From 8885b071143a64912cd00f2632fe4de0ccd8f8d1 Mon Sep 17 00:00:00 2001 From: ljain112 Date: Tue, 24 Dec 2024 15:15:30 +0530 Subject: [PATCH 1/3] fix: update item_tax_rate in backend (cherry picked from commit de54c0b41f6c3367f39e74a5726d757bcedbc79f) # Conflicts: # erpnext/controllers/taxes_and_totals.py --- .../doctype/sales_invoice/test_sales_invoice.py | 14 ++++++++++++++ erpnext/controllers/taxes_and_totals.py | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 57eb84caaa4..763fea7a260 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -43,6 +43,7 @@ from erpnext.stock.doctype.stock_entry.test_stock_entry import ( from erpnext.stock.doctype.stock_reconciliation.test_stock_reconciliation import ( create_stock_reconciliation, ) +from erpnext.stock.get_item_details import get_item_tax_map from erpnext.stock.utils import get_incoming_rate, get_stock_balance @@ -2873,13 +2874,26 @@ class TestSalesInvoice(FrappeTestCase): item.save() sales_invoice = create_sales_invoice(item="T Shirt", rate=700, do_not_submit=True) + item_tax_map = get_item_tax_map( + doc=sales_invoice, + tax_template=sales_invoice.items[0].item_tax_template, + ) + self.assertEqual(sales_invoice.items[0].item_tax_template, "_Test Account Excise Duty @ 12 - _TC") + self.assertEqual(sales_invoice.items[0].item_tax_rate, item_tax_map) # Apply discount sales_invoice.apply_discount_on = "Net Total" sales_invoice.discount_amount = 300 sales_invoice.save() + + item_tax_map = get_item_tax_map( + doc=sales_invoice, + tax_template=sales_invoice.items[0].item_tax_template, + ) + self.assertEqual(sales_invoice.items[0].item_tax_template, "_Test Account Excise Duty @ 10 - _TC") + self.assertEqual(sales_invoice.items[0].item_tax_rate, item_tax_map) @change_settings("Selling Settings", {"enable_discount_accounting": 1}) def test_sales_invoice_with_discount_accounting_enabled(self): diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index bf5beab1a82..2ebe8270cad 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -18,7 +18,12 @@ from erpnext.controllers.accounts_controller import ( validate_inclusive_tax, validate_taxes_and_charges, ) +<<<<<<< HEAD from erpnext.stock.get_item_details import _get_item_tax_template +======= +from erpnext.deprecation_dumpster import deprecated +from erpnext.stock.get_item_details import ItemDetailsCtx, _get_item_tax_template, get_item_tax_map +>>>>>>> de54c0b41f (fix: update item_tax_rate in backend) from erpnext.utilities.regional import temporary_flag @@ -70,6 +75,7 @@ class calculate_taxes_and_totals: self.validate_conversion_rate() self.calculate_item_values() self.validate_item_tax_template() + self.update_item_tax_map() self.initialize_taxes() self.determine_exclusive_rate() self.calculate_net_total() @@ -134,6 +140,14 @@ class calculate_taxes_and_totals: ) ) + def update_item_tax_map(self): + for item in self.doc.items: + item.item_tax_rate = get_item_tax_map( + doc=self.doc, + tax_template=item.item_tax_template, + as_json=True, + ) + def validate_conversion_rate(self): # validate conversion rate company_currency = erpnext.get_company_currency(self.doc.company) From 885dd31c5c2f1d70812c16ac52c1d18ae32009db Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Tue, 31 Dec 2024 15:54:06 +0530 Subject: [PATCH 2/3] chore: resolve conflict --- erpnext/controllers/taxes_and_totals.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 2ebe8270cad..53d0ce0ee2f 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -18,12 +18,7 @@ from erpnext.controllers.accounts_controller import ( validate_inclusive_tax, validate_taxes_and_charges, ) -<<<<<<< HEAD -from erpnext.stock.get_item_details import _get_item_tax_template -======= -from erpnext.deprecation_dumpster import deprecated -from erpnext.stock.get_item_details import ItemDetailsCtx, _get_item_tax_template, get_item_tax_map ->>>>>>> de54c0b41f (fix: update item_tax_rate in backend) +from erpnext.stock.get_item_details import _get_item_tax_template, get_item_tax_map from erpnext.utilities.regional import temporary_flag From e09fb8759751942e2eb2b1c927f2a18cb8bea566 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Tue, 31 Dec 2024 16:57:16 +0530 Subject: [PATCH 3/3] refactor: use existing method parameters --- .../accounts/doctype/sales_invoice/test_sales_invoice.py | 8 ++++---- erpnext/controllers/taxes_and_totals.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 763fea7a260..439fc5639e5 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -2875,8 +2875,8 @@ class TestSalesInvoice(FrappeTestCase): sales_invoice = create_sales_invoice(item="T Shirt", rate=700, do_not_submit=True) item_tax_map = get_item_tax_map( - doc=sales_invoice, - tax_template=sales_invoice.items[0].item_tax_template, + company=sales_invoice.company, + item_tax_template=sales_invoice.items[0].item_tax_template, ) self.assertEqual(sales_invoice.items[0].item_tax_template, "_Test Account Excise Duty @ 12 - _TC") @@ -2888,8 +2888,8 @@ class TestSalesInvoice(FrappeTestCase): sales_invoice.save() item_tax_map = get_item_tax_map( - doc=sales_invoice, - tax_template=sales_invoice.items[0].item_tax_template, + company=sales_invoice.company, + item_tax_template=sales_invoice.items[0].item_tax_template, ) self.assertEqual(sales_invoice.items[0].item_tax_template, "_Test Account Excise Duty @ 10 - _TC") diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 53d0ce0ee2f..8fecb177295 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -138,8 +138,8 @@ class calculate_taxes_and_totals: def update_item_tax_map(self): for item in self.doc.items: item.item_tax_rate = get_item_tax_map( - doc=self.doc, - tax_template=item.item_tax_template, + company=self.doc.get("company"), + item_tax_template=item.item_tax_template, as_json=True, )