From 58ca4a2b99a694ea891e1b3cfd949f799edacafb Mon Sep 17 00:00:00 2001 From: ljain112 Date: Wed, 18 Sep 2024 19:38:14 +0530 Subject: [PATCH 1/4] fix: improved the conditions for determining voucher subtypes (cherry picked from commit 00eee161904b5deb01ba80b6a3629bd7e2dd613f) --- erpnext/controllers/accounts_controller.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index e47e9917149..b14cf428c53 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1096,9 +1096,11 @@ class AccountsController(TransactionBase): return "Purchase Return" elif self.doctype == "Delivery Note" and self.is_return: return "Sales Return" - elif (self.doctype == "Sales Invoice" and self.is_return) or self.doctype == "Purchase Invoice": + elif self.doctype == "Sales Invoice" and self.is_return: return "Credit Note" - elif (self.doctype == "Purchase Invoice" and self.is_return) or self.doctype == "Sales Invoice": + elif self.doctype == "Sales Invoice" and self.is_debit_note: + return "Debit Note" + elif self.doctype == "Purchase Invoice" and self.is_return: return "Debit Note" return self.doctype From 107d53b3582ccdac3f237745efba4eca5a14a328 Mon Sep 17 00:00:00 2001 From: ljain112 Date: Mon, 30 Sep 2024 20:10:36 +0530 Subject: [PATCH 2/4] fix: patch (cherry picked from commit d76cc210860651377262371359b65e4f7ea9abb7) # Conflicts: # erpnext/patches.txt --- erpnext/patches.txt | 5 ++ .../update_sub_voucher_type_in_gl_entries.py | 57 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 erpnext/patches/v15_0/update_sub_voucher_type_in_gl_entries.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 64c74f9d645..01dc68d1d3a 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -379,5 +379,10 @@ erpnext.patches.v15_0.drop_index_posting_datetime_from_sle erpnext.patches.v15_0.add_disassembly_order_stock_entry_type #1 erpnext.patches.v15_0.set_standard_stock_entry_type erpnext.patches.v15_0.link_purchase_item_to_asset_doc +<<<<<<< HEAD erpnext.patches.v14_0.update_currency_exchange_settings_for_frankfurter erpnext.patches.v15_0.update_task_assignee_email_field_in_asset_maintenance_log +======= +erpnext.patches.v15_0.migrate_to_utm_analytics +erpnext.patches.v15_0.update_sub_voucher_type_in_gl_entries +>>>>>>> d76cc21086 (fix: patch) diff --git a/erpnext/patches/v15_0/update_sub_voucher_type_in_gl_entries.py b/erpnext/patches/v15_0/update_sub_voucher_type_in_gl_entries.py new file mode 100644 index 00000000000..7160a6ba87d --- /dev/null +++ b/erpnext/patches/v15_0/update_sub_voucher_type_in_gl_entries.py @@ -0,0 +1,57 @@ +import frappe + + +def execute(): + update_purchase_invoices() + update_sales_invoices() + update_sales_debit_notes() + + +def update_purchase_invoices(): + invoices = frappe.get_all( + "Purchase Invoice", + filters={"docstatus": 1, "is_return": 0}, + pluck="name", + ) + + if not invoices: + return + + update_gl_entry(doctype="Purchase Invoice", invoices=invoices, value="Purchase Invoice") + + +def update_sales_invoices(): + invoices = frappe.get_all( + "Sales Invoice", + filters={"docstatus": 1, "is_return": 0, "is_debit_note": 0}, + pluck="name", + ) + if not invoices: + return + + update_gl_entry(doctype="Sales Invoice", invoices=invoices, value="Sales Invoice") + + +def update_sales_debit_notes(): + invoices = frappe.get_all( + "Sales Invoice", + filters={"docstatus": 1, "is_debit_note": 1}, + pluck="name", + ) + + if not invoices: + return + + update_gl_entry(doctype="Sales Invoice", invoices=invoices, value="Debit Note") + + +def update_gl_entry(doctype, invoices, value): + gl_entry = frappe.qb.DocType("GL Entry") + ( + frappe.qb.update(gl_entry) + .set("voucher_subtype", value) + .where(gl_entry.voucher_subtype.isnotnull()) + .where(gl_entry.voucher_no.isin(invoices)) + .where(gl_entry.voucher_type == doctype) + .run() + ) From d7f91824c0e7b5a36ac5aa28f9d6d23580ed192e Mon Sep 17 00:00:00 2001 From: Smit Vora Date: Thu, 7 Nov 2024 13:35:54 +0530 Subject: [PATCH 3/4] test: test voucher subtype for sales invoice (cherry picked from commit ad6cc352f189449484e8560dc4a4c87ff8c0f894) --- .../sales_invoice/test_sales_invoice.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index d05da0dbf19..db6fd41e439 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -4005,6 +4005,25 @@ class TestSalesInvoice(FrappeTestCase): si.submit() self.assertEqual(si.remarks, f"Against Customer Order Test PO dated {format_date(nowdate())}") + def test_gl_voucher_subtype(self): + si = create_sales_invoice() + gl_entries = frappe.get_all( + "GL Entry", + filters={"voucher_type": "Sales Invoice", "voucher_no": si.name}, + pluck="voucher_subtype", + ) + + self.assertTrue(all([x == "Sales Invoice" for x in gl_entries])) + + si = create_sales_invoice(is_return=1, qty=-1) + gl_entries = frappe.get_all( + "GL Entry", + filters={"voucher_type": "Sales Invoice", "voucher_no": si.name}, + pluck="voucher_subtype", + ) + + self.assertTrue(all([x == "Credit Note" for x in gl_entries])) + def set_advance_flag(company, flag, default_account): frappe.db.set_value( From 6649d17b068fcacf7c8b24b1b1cdc5891c4735dd Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 8 Nov 2024 10:33:56 +0530 Subject: [PATCH 4/4] chore: resolve conflict --- erpnext/patches.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 01dc68d1d3a..1f1c2edc917 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -379,10 +379,6 @@ erpnext.patches.v15_0.drop_index_posting_datetime_from_sle erpnext.patches.v15_0.add_disassembly_order_stock_entry_type #1 erpnext.patches.v15_0.set_standard_stock_entry_type erpnext.patches.v15_0.link_purchase_item_to_asset_doc -<<<<<<< HEAD erpnext.patches.v14_0.update_currency_exchange_settings_for_frankfurter erpnext.patches.v15_0.update_task_assignee_email_field_in_asset_maintenance_log -======= -erpnext.patches.v15_0.migrate_to_utm_analytics erpnext.patches.v15_0.update_sub_voucher_type_in_gl_entries ->>>>>>> d76cc21086 (fix: patch)