From 6bee70596bc2776dc6a0c799edb60f86c10344ac Mon Sep 17 00:00:00 2001 From: ljain112 Date: Mon, 6 Jul 2026 17:37:09 +0530 Subject: [PATCH 1/3] refactor: move functionality in postprocess for mapped doc (cherry picked from commit 0691c7c7bc6c23bb05ed764d01192ff733da72fb) # Conflicts: # erpnext/subcontracting/doctype/subcontracting_inward_order/subcontracting_inward_order.py --- .../subcontracting_inward_order.py | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+) diff --git a/erpnext/subcontracting/doctype/subcontracting_inward_order/subcontracting_inward_order.py b/erpnext/subcontracting/doctype/subcontracting_inward_order/subcontracting_inward_order.py index 9687a070bda..1b225db401c 100644 --- a/erpnext/subcontracting/doctype/subcontracting_inward_order/subcontracting_inward_order.py +++ b/erpnext/subcontracting/doctype/subcontracting_inward_order/subcontracting_inward_order.py @@ -345,6 +345,26 @@ class SubcontractingInwardOrder(SubcontractingController): if target_doc and target_doc.get("items"): target_doc.items = [] + def postprocess(source, target): + target.purpose = "Receive from Customer" + target.subcontracting_inward_order = source.name + target.set_stock_entry_type() + + for rm_item in source.received_items: + if not rm_item.required_qty or not rm_item.is_customer_provided_item: + continue + + target.append( + "items", + { + "scio_detail": rm_item.get("name"), + "item_code": rm_item.get("rm_item_code"), + "qty": calculate_qty_as_per_bom(rm_item), + "t_warehouse": rm_item.get("warehouse"), + "stock_uom": rm_item.get("stock_uom"), + }, + ) + stock_entry = get_mapped_doc( "Subcontracting Inward Order", self.name, @@ -357,9 +377,11 @@ class SubcontractingInwardOrder(SubcontractingController): }, }, target_doc, + postprocess=postprocess, ignore_child_tables=True, ) +<<<<<<< HEAD stock_entry.purpose = "Receive from Customer" stock_entry.subcontracting_inward_order = self.name @@ -380,6 +402,8 @@ class SubcontractingInwardOrder(SubcontractingController): stock_entry.add_to_stock_entry_detail(items_dict) +======= +>>>>>>> 0691c7c7bc (refactor: move functionality in postprocess for mapped doc) if target_doc: return stock_entry else: @@ -390,6 +414,27 @@ class SubcontractingInwardOrder(SubcontractingController): if target_doc and target_doc.get("items"): target_doc.items = [] + def postprocess(source, target): + target.purpose = "Return Raw Material to Customer" + target.subcontracting_inward_order = source.name + target.set_stock_entry_type() + + for rm_item in source.received_items: + qty = rm_item.received_qty - rm_item.work_order_qty - rm_item.returned_qty + if not qty: + continue + + target.append( + "items", + { + "scio_detail": rm_item.get("name"), + "item_code": rm_item.get("rm_item_code"), + "qty": qty, + "s_warehouse": rm_item.get("warehouse"), + "stock_uom": rm_item.get("stock_uom"), + }, + ) + stock_entry = get_mapped_doc( "Subcontracting Inward Order", self.name, @@ -402,9 +447,11 @@ class SubcontractingInwardOrder(SubcontractingController): }, }, target_doc, + postprocess=postprocess, ignore_child_tables=True, ) +<<<<<<< HEAD stock_entry.purpose = "Return Raw Material to Customer" stock_entry.set_stock_entry_type() stock_entry.subcontracting_inward_order = self.name @@ -421,6 +468,8 @@ class SubcontractingInwardOrder(SubcontractingController): stock_entry.add_to_stock_entry_detail(items_dict) +======= +>>>>>>> 0691c7c7bc (refactor: move functionality in postprocess for mapped doc) if target_doc: return stock_entry else: @@ -431,6 +480,58 @@ class SubcontractingInwardOrder(SubcontractingController): if target_doc and target_doc.get("items"): target_doc.items = [] + def postprocess(source, target): + target.purpose = "Subcontracting Delivery" + target.subcontracting_inward_order = source.name + target.set_stock_entry_type() + + scio_details = [] + allow_over = frappe.get_single_value("Selling Settings", "allow_delivery_of_overproduced_qty") + for fg_item in source.items: + qty = ( + fg_item.produced_qty + if allow_over + else min(fg_item.qty, fg_item.produced_qty) - fg_item.delivered_qty + ) + if qty < 0: + continue + + scio_details.append(fg_item.name) + target.append( + "items", + { + "qty": qty, + "item_code": fg_item.item_code, + "s_warehouse": fg_item.delivery_warehouse, + "stock_uom": fg_item.stock_uom, + "scio_detail": fg_item.name, + "is_finished_item": 1, + }, + ) + + if ( + frappe.get_single_value("Selling Settings", "deliver_secondary_items") + and source.secondary_items + and scio_details + ): + for secondary_item in source.secondary_items: + if secondary_item.reference_name not in scio_details: + continue + + qty = secondary_item.produced_qty - secondary_item.delivered_qty + if qty > 0: + target.append( + "items", + { + "qty": qty, + "item_code": secondary_item.item_code, + "s_warehouse": secondary_item.warehouse, + "stock_uom": secondary_item.stock_uom, + "scio_detail": secondary_item.name, + "secondary_item_type": secondary_item.secondary_item_type, + }, + ) + stock_entry = get_mapped_doc( "Subcontracting Inward Order", self.name, @@ -443,9 +544,11 @@ class SubcontractingInwardOrder(SubcontractingController): }, }, target_doc, + postprocess=postprocess, ignore_child_tables=True, ) +<<<<<<< HEAD stock_entry.purpose = "Subcontracting Delivery" stock_entry.set_stock_entry_type() stock_entry.subcontracting_inward_order = self.name @@ -499,6 +602,8 @@ class SubcontractingInwardOrder(SubcontractingController): stock_entry.add_to_stock_entry_detail(items_dict) +======= +>>>>>>> 0691c7c7bc (refactor: move functionality in postprocess for mapped doc) if target_doc: return stock_entry else: @@ -509,6 +614,26 @@ class SubcontractingInwardOrder(SubcontractingController): if target_doc and target_doc.get("items"): target_doc.items = [] + def postprocess(source, target): + target.purpose = "Subcontracting Return" + target.set_stock_entry_type() + + for fg_item in source.items: + qty = fg_item.delivered_qty - fg_item.returned_qty + if qty < 0: + continue + + target.append( + "items", + { + "qty": qty, + "item_code": fg_item.item_code, + "stock_uom": fg_item.stock_uom, + "scio_detail": fg_item.name, + "is_finished_item": 1, + }, + ) + stock_entry = get_mapped_doc( "Subcontracting Inward Order", self.name, @@ -522,9 +647,11 @@ class SubcontractingInwardOrder(SubcontractingController): }, }, target_doc, + postprocess=postprocess, ignore_child_tables=True, ) +<<<<<<< HEAD stock_entry.purpose = "Subcontracting Return" stock_entry.set_stock_entry_type() @@ -544,6 +671,8 @@ class SubcontractingInwardOrder(SubcontractingController): stock_entry.add_to_stock_entry_detail(items_dict) +======= +>>>>>>> 0691c7c7bc (refactor: move functionality in postprocess for mapped doc) if target_doc: return stock_entry else: From 3141387949201dcb9593ec6ee92f0413ac445b73 Mon Sep 17 00:00:00 2001 From: ljain112 Date: Wed, 5 Aug 2026 12:33:01 +0530 Subject: [PATCH 2/3] chore: resolve conflicts --- .../subcontracting_inward_order.py | 120 ------------------ 1 file changed, 120 deletions(-) diff --git a/erpnext/subcontracting/doctype/subcontracting_inward_order/subcontracting_inward_order.py b/erpnext/subcontracting/doctype/subcontracting_inward_order/subcontracting_inward_order.py index 1b225db401c..d6ec3219684 100644 --- a/erpnext/subcontracting/doctype/subcontracting_inward_order/subcontracting_inward_order.py +++ b/erpnext/subcontracting/doctype/subcontracting_inward_order/subcontracting_inward_order.py @@ -381,29 +381,6 @@ class SubcontractingInwardOrder(SubcontractingController): ignore_child_tables=True, ) -<<<<<<< HEAD - stock_entry.purpose = "Receive from Customer" - stock_entry.subcontracting_inward_order = self.name - - stock_entry.set_stock_entry_type() - - for rm_item in self.received_items: - if not rm_item.required_qty or not rm_item.is_customer_provided_item: - continue - - items_dict = { - rm_item.get("rm_item_code"): { - "scio_detail": rm_item.get("name"), - "qty": calculate_qty_as_per_bom(rm_item), - "to_warehouse": rm_item.get("warehouse"), - "stock_uom": rm_item.get("stock_uom"), - } - } - - stock_entry.add_to_stock_entry_detail(items_dict) - -======= ->>>>>>> 0691c7c7bc (refactor: move functionality in postprocess for mapped doc) if target_doc: return stock_entry else: @@ -451,25 +428,6 @@ class SubcontractingInwardOrder(SubcontractingController): ignore_child_tables=True, ) -<<<<<<< HEAD - stock_entry.purpose = "Return Raw Material to Customer" - stock_entry.set_stock_entry_type() - stock_entry.subcontracting_inward_order = self.name - - for rm_item in self.received_items: - items_dict = { - rm_item.get("rm_item_code"): { - "scio_detail": rm_item.get("name"), - "qty": rm_item.received_qty - rm_item.work_order_qty - rm_item.returned_qty, - "from_warehouse": rm_item.get("warehouse"), - "stock_uom": rm_item.get("stock_uom"), - } - } - - stock_entry.add_to_stock_entry_detail(items_dict) - -======= ->>>>>>> 0691c7c7bc (refactor: move functionality in postprocess for mapped doc) if target_doc: return stock_entry else: @@ -548,62 +506,6 @@ class SubcontractingInwardOrder(SubcontractingController): ignore_child_tables=True, ) -<<<<<<< HEAD - stock_entry.purpose = "Subcontracting Delivery" - stock_entry.set_stock_entry_type() - stock_entry.subcontracting_inward_order = self.name - scio_details = [] - - allow_over = frappe.get_single_value("Selling Settings", "allow_delivery_of_overproduced_qty") - for fg_item in self.items: - qty = ( - fg_item.produced_qty - if allow_over - else min(fg_item.qty, fg_item.produced_qty) - fg_item.delivered_qty - ) - if qty < 0: - continue - - scio_details.append(fg_item.name) - items_dict = { - fg_item.item_code: { - "qty": qty, - "from_warehouse": fg_item.delivery_warehouse, - "stock_uom": fg_item.stock_uom, - "scio_detail": fg_item.name, - "is_finished_item": 1, - } - } - - stock_entry.add_to_stock_entry_detail(items_dict) - - if ( - frappe.get_single_value("Selling Settings", "deliver_secondary_items") - and self.secondary_items - and scio_details - ): - secondary_items = [ - secondary_item - for secondary_item in self.secondary_items - if secondary_item.reference_name in scio_details - ] - for secondary_item in secondary_items: - qty = secondary_item.produced_qty - secondary_item.delivered_qty - if qty > 0: - items_dict = { - secondary_item.item_code: { - "qty": secondary_item.produced_qty - secondary_item.delivered_qty, - "from_warehouse": secondary_item.warehouse, - "stock_uom": secondary_item.stock_uom, - "scio_detail": secondary_item.name, - "type": secondary_item.type, - } - } - - stock_entry.add_to_stock_entry_detail(items_dict) - -======= ->>>>>>> 0691c7c7bc (refactor: move functionality in postprocess for mapped doc) if target_doc: return stock_entry else: @@ -651,28 +553,6 @@ class SubcontractingInwardOrder(SubcontractingController): ignore_child_tables=True, ) -<<<<<<< HEAD - stock_entry.purpose = "Subcontracting Return" - stock_entry.set_stock_entry_type() - - for fg_item in self.items: - qty = fg_item.delivered_qty - fg_item.returned_qty - if qty < 0: - continue - - items_dict = { - fg_item.item_code: { - "qty": qty, - "stock_uom": fg_item.stock_uom, - "scio_detail": fg_item.name, - "is_finished_item": 1, - } - } - - stock_entry.add_to_stock_entry_detail(items_dict) - -======= ->>>>>>> 0691c7c7bc (refactor: move functionality in postprocess for mapped doc) if target_doc: return stock_entry else: From b412266e182e0c53c8700828a4bed7dc375c6d5f Mon Sep 17 00:00:00 2001 From: ljain112 Date: Wed, 5 Aug 2026 17:01:39 +0530 Subject: [PATCH 3/3] chore: resolve conflicts --- .../subcontracting_inward_order/subcontracting_inward_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/subcontracting/doctype/subcontracting_inward_order/subcontracting_inward_order.py b/erpnext/subcontracting/doctype/subcontracting_inward_order/subcontracting_inward_order.py index d6ec3219684..69539f7b091 100644 --- a/erpnext/subcontracting/doctype/subcontracting_inward_order/subcontracting_inward_order.py +++ b/erpnext/subcontracting/doctype/subcontracting_inward_order/subcontracting_inward_order.py @@ -486,7 +486,7 @@ class SubcontractingInwardOrder(SubcontractingController): "s_warehouse": secondary_item.warehouse, "stock_uom": secondary_item.stock_uom, "scio_detail": secondary_item.name, - "secondary_item_type": secondary_item.secondary_item_type, + "type": secondary_item.type, }, )