From c022b80e05ac738f1552ae61d8f8afa786dffa53 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Fri, 18 Jul 2025 15:13:59 +0530 Subject: [PATCH 1/3] fix: missing account in GL entries (subcontracting) --- erpnext/patches.txt | 3 ++- ..._entries_with_no_account_subcontracting.py | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 erpnext/patches/v15_0/erpnext.patches.v15_0.repost_gl_entries_with_no_account_subcontracting.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 2eab5d3fa65..64b5085cf34 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -425,4 +425,5 @@ erpnext.patches.v15_0.rename_pos_closing_entry_fields #2025-06-13 erpnext.patches.v15_0.update_pegged_currencies erpnext.patches.v15_0.set_status_cancelled_on_cancelled_pos_opening_entry_and_pos_closing_entry erpnext.patches.v15_0.set_company_on_pos_inv_merge_log -erpnext.patches.v15_0.rename_price_list_to_buying_price_list \ No newline at end of file +erpnext.patches.v15_0.rename_price_list_to_buying_price_list +erpnext.patches.v15_0.repost_gl_entries_with_no_account_subcontracting \ No newline at end of file diff --git a/erpnext/patches/v15_0/erpnext.patches.v15_0.repost_gl_entries_with_no_account_subcontracting.py b/erpnext/patches/v15_0/erpnext.patches.v15_0.repost_gl_entries_with_no_account_subcontracting.py new file mode 100644 index 00000000000..867702ae546 --- /dev/null +++ b/erpnext/patches/v15_0/erpnext.patches.v15_0.repost_gl_entries_with_no_account_subcontracting.py @@ -0,0 +1,24 @@ +import frappe + + +def execute(): + docs = frappe.get_all( + "GL Entry", + filters={"voucher_type": "Subcontracting Receipt", "account": ["is", "not set"], "is_cancelled": 0}, + pluck="voucher_no", + ) + for doc in docs: + doc = frappe.get_doc("Subcontracting Receipt", doc) + for item in doc.supplied_items: + if not item.expense_account: + account = frappe.get_value( + "Subcontracting Receipt Item", item.reference_name, "expense_account" + ) + item.db_set("expense_account", account) + repost_doc = frappe.new_doc("Repost Item Valuation") + repost_doc.voucher_type = "Subcontracting Receipt" + repost_doc.voucher_no = doc.name + repost_doc.based_on = "Transaction" + repost_doc.company = doc.company + repost_doc.save() + repost_doc.submit() From b53723acad0f2c24ba272023849194194661f775 Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Fri, 18 Jul 2025 15:33:31 +0530 Subject: [PATCH 2/3] fix: include cost center in patch --- ..._entries_with_no_account_subcontracting.py | 24 ----------------- ..._entries_with_no_account_subcontracting.py | 26 +++++++++++++++++++ 2 files changed, 26 insertions(+), 24 deletions(-) delete mode 100644 erpnext/patches/v15_0/erpnext.patches.v15_0.repost_gl_entries_with_no_account_subcontracting.py create mode 100644 erpnext/patches/v15_0/repost_gl_entries_with_no_account_subcontracting.py diff --git a/erpnext/patches/v15_0/erpnext.patches.v15_0.repost_gl_entries_with_no_account_subcontracting.py b/erpnext/patches/v15_0/erpnext.patches.v15_0.repost_gl_entries_with_no_account_subcontracting.py deleted file mode 100644 index 867702ae546..00000000000 --- a/erpnext/patches/v15_0/erpnext.patches.v15_0.repost_gl_entries_with_no_account_subcontracting.py +++ /dev/null @@ -1,24 +0,0 @@ -import frappe - - -def execute(): - docs = frappe.get_all( - "GL Entry", - filters={"voucher_type": "Subcontracting Receipt", "account": ["is", "not set"], "is_cancelled": 0}, - pluck="voucher_no", - ) - for doc in docs: - doc = frappe.get_doc("Subcontracting Receipt", doc) - for item in doc.supplied_items: - if not item.expense_account: - account = frappe.get_value( - "Subcontracting Receipt Item", item.reference_name, "expense_account" - ) - item.db_set("expense_account", account) - repost_doc = frappe.new_doc("Repost Item Valuation") - repost_doc.voucher_type = "Subcontracting Receipt" - repost_doc.voucher_no = doc.name - repost_doc.based_on = "Transaction" - repost_doc.company = doc.company - repost_doc.save() - repost_doc.submit() diff --git a/erpnext/patches/v15_0/repost_gl_entries_with_no_account_subcontracting.py b/erpnext/patches/v15_0/repost_gl_entries_with_no_account_subcontracting.py new file mode 100644 index 00000000000..7e06a4050d5 --- /dev/null +++ b/erpnext/patches/v15_0/repost_gl_entries_with_no_account_subcontracting.py @@ -0,0 +1,26 @@ +import frappe + + +def execute(): + docs = frappe.get_all( + "GL Entry", + filters={"voucher_type": "Subcontracting Receipt", "account": ["is", "not set"], "is_cancelled": 0}, + pluck="voucher_no", + ) + for doc in docs: + doc = frappe.get_doc("Subcontracting Receipt", doc) + for item in doc.supplied_items: + account, cost_center = frappe.db.get_values( + "Subcontracting Receipt Item", item.reference_name, ["expense_account", "cost_center"] + )[0] + if not item.expense_account: + item.db_set("expense_account", account) + if not item.cost_center: + item.db_set("cost_center", cost_center) + repost_doc = frappe.new_doc("Repost Item Valuation") + repost_doc.voucher_type = "Subcontracting Receipt" + repost_doc.voucher_no = doc.name + repost_doc.based_on = "Transaction" + repost_doc.company = doc.company + repost_doc.save() + repost_doc.submit() From cb02391f379f49bf953fab34e8ba14685c77bccb Mon Sep 17 00:00:00 2001 From: Mihir Kandoi Date: Fri, 18 Jul 2025 16:26:57 +0530 Subject: [PATCH 3/3] fix: recreate GL entry instead of repost --- ...ost_gl_entries_with_no_account_subcontracting.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/erpnext/patches/v15_0/repost_gl_entries_with_no_account_subcontracting.py b/erpnext/patches/v15_0/repost_gl_entries_with_no_account_subcontracting.py index 7e06a4050d5..b2208667ea6 100644 --- a/erpnext/patches/v15_0/repost_gl_entries_with_no_account_subcontracting.py +++ b/erpnext/patches/v15_0/repost_gl_entries_with_no_account_subcontracting.py @@ -13,14 +13,13 @@ def execute(): account, cost_center = frappe.db.get_values( "Subcontracting Receipt Item", item.reference_name, ["expense_account", "cost_center"] )[0] + if not item.expense_account: item.db_set("expense_account", account) if not item.cost_center: item.db_set("cost_center", cost_center) - repost_doc = frappe.new_doc("Repost Item Valuation") - repost_doc.voucher_type = "Subcontracting Receipt" - repost_doc.voucher_no = doc.name - repost_doc.based_on = "Transaction" - repost_doc.company = doc.company - repost_doc.save() - repost_doc.submit() + + doc.docstatus = 2 + doc.make_gl_entries_on_cancel() + doc.docstatus = 1 + doc.make_gl_entries()