From 66544bfa109bd65763cc682211fed2ae00affec3 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Tue, 31 Dec 2024 12:53:30 +0530 Subject: [PATCH 1/6] fix: Added patch and fallback code to prevent future issues similiar to helpdesk ticket 28246 (cherry picked from commit 65dc3505c405b4fe8c237bcb55c38d8cef6bf684) # Conflicts: # erpnext/patches.txt --- .../controllers/subcontracting_controller.py | 10 +++++++ erpnext/patches.txt | 5 ++++ .../patches/set_sc_conversion_factor.py | 26 +++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 erpnext/subcontracting/doctype/subcontracting_order/patches/set_sc_conversion_factor.py diff --git a/erpnext/controllers/subcontracting_controller.py b/erpnext/controllers/subcontracting_controller.py index 75cb5516348..5a8fa03d814 100644 --- a/erpnext/controllers/subcontracting_controller.py +++ b/erpnext/controllers/subcontracting_controller.py @@ -103,6 +103,16 @@ class SubcontractingController(StockController): _("Row {0}: Item {1} must be a subcontracted item.").format(item.idx, item.item_name) ) + if ( + not item.sc_conversion_factor + ): # this condition will only be true if user has recently updated from develop branch + service_item_qty = frappe.get_value( + "Subcontracting Order Service Item", + filters={"purchase_order_item": item.purchase_order_item, "parent": self.name}, + fieldname=["qty"], + ) + item.sc_conversion_factor = service_item_qty / item.qty + if ( self.doctype not in "Subcontracting Receipt" and item.qty diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 7e03ef9394c..075a1f4b8a7 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -386,3 +386,8 @@ erpnext.patches.v14_0.update_stock_uom_in_work_order_item erpnext.patches.v15_0.set_is_exchange_gain_loss_in_payment_entry_deductions erpnext.patches.v15_0.enable_allow_existing_serial_no erpnext.patches.v15_0.update_cc_in_process_statement_of_accounts +<<<<<<< HEAD +======= +erpnext.patches.v15_0.refactor_closing_stock_balance #5 +erpnext.subcontracting.doctype.subcontracting_order.patches.set_sc_conversion_factor +>>>>>>> 65dc3505c4 (fix: Added patch and fallback code to prevent future issues similiar to helpdesk ticket 28246) diff --git a/erpnext/subcontracting/doctype/subcontracting_order/patches/set_sc_conversion_factor.py b/erpnext/subcontracting/doctype/subcontracting_order/patches/set_sc_conversion_factor.py new file mode 100644 index 00000000000..1b23c9565bf --- /dev/null +++ b/erpnext/subcontracting/doctype/subcontracting_order/patches/set_sc_conversion_factor.py @@ -0,0 +1,26 @@ +import frappe + + +def execute(): + # Calculate and set sc_conversion_factor for draft Subcontracting Orders if value is 0 + + subcontracting_order_items = frappe.get_all( + "Subcontracting Order Item", + filters={"docstatus": 0, "sc_conversion_factor": 0}, + fields=["name", "parent", "purchase_order_item", "qty"], + ) + for subcontracting_order_item in subcontracting_order_items: + service_item_qty = frappe.get_value( + "Subcontracting Order Service Item", + filters={ + "purchase_order_item": subcontracting_order_item.purchase_order_item, + "parent": subcontracting_order_item.parent, + }, + fieldname=["qty"], + ) + frappe.set_value( + "Subcontracting Order Item", + subcontracting_order_item.name, + "sc_conversion_factor", + service_item_qty / subcontracting_order_item.qty, + ) From b3b808335f34ee73df494d8ef015001388d0bca1 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Tue, 31 Dec 2024 20:33:05 +0530 Subject: [PATCH 2/6] fix: Fixed logic in if condition causing tests to fail (cherry picked from commit 575fb43f9cd5852b37f1a3fe17db3206df596608) --- erpnext/controllers/subcontracting_controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/controllers/subcontracting_controller.py b/erpnext/controllers/subcontracting_controller.py index 5a8fa03d814..0f9431ab440 100644 --- a/erpnext/controllers/subcontracting_controller.py +++ b/erpnext/controllers/subcontracting_controller.py @@ -104,7 +104,7 @@ class SubcontractingController(StockController): ) if ( - not item.sc_conversion_factor + self.doctype == "Subcontracting Order" and not item.sc_conversion_factor ): # this condition will only be true if user has recently updated from develop branch service_item_qty = frappe.get_value( "Subcontracting Order Service Item", From 163af91c377bfd2398b892e7e3abd9033e401f49 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Wed, 1 Jan 2025 13:49:49 +0530 Subject: [PATCH 3/6] fix: Removed patch as instructed by mentor (cherry picked from commit d1d01482dfb006a956e010f0e27b322632072804) # Conflicts: # erpnext/patches.txt --- erpnext/patches.txt | 4 +++ .../patches/set_sc_conversion_factor.py | 26 ------------------- 2 files changed, 4 insertions(+), 26 deletions(-) delete mode 100644 erpnext/subcontracting/doctype/subcontracting_order/patches/set_sc_conversion_factor.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 075a1f4b8a7..d712933a898 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -387,7 +387,11 @@ erpnext.patches.v15_0.set_is_exchange_gain_loss_in_payment_entry_deductions erpnext.patches.v15_0.enable_allow_existing_serial_no erpnext.patches.v15_0.update_cc_in_process_statement_of_accounts <<<<<<< HEAD +<<<<<<< HEAD ======= erpnext.patches.v15_0.refactor_closing_stock_balance #5 erpnext.subcontracting.doctype.subcontracting_order.patches.set_sc_conversion_factor >>>>>>> 65dc3505c4 (fix: Added patch and fallback code to prevent future issues similiar to helpdesk ticket 28246) +======= +erpnext.patches.v15_0.refactor_closing_stock_balance #5 +>>>>>>> d1d01482df (fix: Removed patch as instructed by mentor) diff --git a/erpnext/subcontracting/doctype/subcontracting_order/patches/set_sc_conversion_factor.py b/erpnext/subcontracting/doctype/subcontracting_order/patches/set_sc_conversion_factor.py deleted file mode 100644 index 1b23c9565bf..00000000000 --- a/erpnext/subcontracting/doctype/subcontracting_order/patches/set_sc_conversion_factor.py +++ /dev/null @@ -1,26 +0,0 @@ -import frappe - - -def execute(): - # Calculate and set sc_conversion_factor for draft Subcontracting Orders if value is 0 - - subcontracting_order_items = frappe.get_all( - "Subcontracting Order Item", - filters={"docstatus": 0, "sc_conversion_factor": 0}, - fields=["name", "parent", "purchase_order_item", "qty"], - ) - for subcontracting_order_item in subcontracting_order_items: - service_item_qty = frappe.get_value( - "Subcontracting Order Service Item", - filters={ - "purchase_order_item": subcontracting_order_item.purchase_order_item, - "parent": subcontracting_order_item.parent, - }, - fieldname=["qty"], - ) - frappe.set_value( - "Subcontracting Order Item", - subcontracting_order_item.name, - "sc_conversion_factor", - service_item_qty / subcontracting_order_item.qty, - ) From ab87265395c99b12ef0a2fd764930fa909ce8ab7 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Tue, 31 Dec 2024 12:53:30 +0530 Subject: [PATCH 4/6] fix: Added patch and fallback code to prevent future issues similiar to helpdesk ticket 28246 --- erpnext/patches.txt | 8 ------ .../patches/set_sc_conversion_factor.py | 26 +++++++++++++++++++ 2 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 erpnext/subcontracting/doctype/subcontracting_order/patches/set_sc_conversion_factor.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index d712933a898..cb240acf4b8 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -386,12 +386,4 @@ erpnext.patches.v14_0.update_stock_uom_in_work_order_item erpnext.patches.v15_0.set_is_exchange_gain_loss_in_payment_entry_deductions erpnext.patches.v15_0.enable_allow_existing_serial_no erpnext.patches.v15_0.update_cc_in_process_statement_of_accounts -<<<<<<< HEAD -<<<<<<< HEAD -======= erpnext.patches.v15_0.refactor_closing_stock_balance #5 -erpnext.subcontracting.doctype.subcontracting_order.patches.set_sc_conversion_factor ->>>>>>> 65dc3505c4 (fix: Added patch and fallback code to prevent future issues similiar to helpdesk ticket 28246) -======= -erpnext.patches.v15_0.refactor_closing_stock_balance #5 ->>>>>>> d1d01482df (fix: Removed patch as instructed by mentor) diff --git a/erpnext/subcontracting/doctype/subcontracting_order/patches/set_sc_conversion_factor.py b/erpnext/subcontracting/doctype/subcontracting_order/patches/set_sc_conversion_factor.py new file mode 100644 index 00000000000..1b23c9565bf --- /dev/null +++ b/erpnext/subcontracting/doctype/subcontracting_order/patches/set_sc_conversion_factor.py @@ -0,0 +1,26 @@ +import frappe + + +def execute(): + # Calculate and set sc_conversion_factor for draft Subcontracting Orders if value is 0 + + subcontracting_order_items = frappe.get_all( + "Subcontracting Order Item", + filters={"docstatus": 0, "sc_conversion_factor": 0}, + fields=["name", "parent", "purchase_order_item", "qty"], + ) + for subcontracting_order_item in subcontracting_order_items: + service_item_qty = frappe.get_value( + "Subcontracting Order Service Item", + filters={ + "purchase_order_item": subcontracting_order_item.purchase_order_item, + "parent": subcontracting_order_item.parent, + }, + fieldname=["qty"], + ) + frappe.set_value( + "Subcontracting Order Item", + subcontracting_order_item.name, + "sc_conversion_factor", + service_item_qty / subcontracting_order_item.qty, + ) From 3049027f437ade49db2fa0cf9fcc1c67c11fb750 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Wed, 1 Jan 2025 13:49:49 +0530 Subject: [PATCH 5/6] fix: Removed patch as instructed by mentor --- .../patches/set_sc_conversion_factor.py | 26 ------------------- 1 file changed, 26 deletions(-) delete mode 100644 erpnext/subcontracting/doctype/subcontracting_order/patches/set_sc_conversion_factor.py diff --git a/erpnext/subcontracting/doctype/subcontracting_order/patches/set_sc_conversion_factor.py b/erpnext/subcontracting/doctype/subcontracting_order/patches/set_sc_conversion_factor.py deleted file mode 100644 index 1b23c9565bf..00000000000 --- a/erpnext/subcontracting/doctype/subcontracting_order/patches/set_sc_conversion_factor.py +++ /dev/null @@ -1,26 +0,0 @@ -import frappe - - -def execute(): - # Calculate and set sc_conversion_factor for draft Subcontracting Orders if value is 0 - - subcontracting_order_items = frappe.get_all( - "Subcontracting Order Item", - filters={"docstatus": 0, "sc_conversion_factor": 0}, - fields=["name", "parent", "purchase_order_item", "qty"], - ) - for subcontracting_order_item in subcontracting_order_items: - service_item_qty = frappe.get_value( - "Subcontracting Order Service Item", - filters={ - "purchase_order_item": subcontracting_order_item.purchase_order_item, - "parent": subcontracting_order_item.parent, - }, - fieldname=["qty"], - ) - frappe.set_value( - "Subcontracting Order Item", - subcontracting_order_item.name, - "sc_conversion_factor", - service_item_qty / subcontracting_order_item.qty, - ) From f9d038ee4a255dc1e1e34b178d119b7e79936b62 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Thu, 2 Jan 2025 10:51:11 +0530 Subject: [PATCH 6/6] fix: removed unknown patch? --- erpnext/patches.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index cb240acf4b8..7e03ef9394c 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -386,4 +386,3 @@ erpnext.patches.v14_0.update_stock_uom_in_work_order_item erpnext.patches.v15_0.set_is_exchange_gain_loss_in_payment_entry_deductions erpnext.patches.v15_0.enable_allow_existing_serial_no erpnext.patches.v15_0.update_cc_in_process_statement_of_accounts -erpnext.patches.v15_0.refactor_closing_stock_balance #5