From 90dea426d8adc86a56a37666e1f3f7b274b0df2f Mon Sep 17 00:00:00 2001 From: Ninad1306 Date: Tue, 18 Feb 2025 12:52:33 +0530 Subject: [PATCH 1/3] fix: set taxes before calculating taxes and totals (cherry picked from commit 0fd0695bbbaec834bd120b4fdc93bc7142f60532) --- erpnext/controllers/accounts_controller.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index bb0a4070981..884ce4de71b 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -194,6 +194,14 @@ class AccountsController(TransactionBase): self.set_incoming_rate() self.init_internal_values() + # Need to set taxes based on taxes_and_charges template + # before calculating taxes and totals + if self.meta.get_field("taxes_and_charges"): + self.validate_enabled_taxes_and_charges() + self.validate_tax_account_company() + + self.set_taxes_and_charges() + if self.meta.get_field("currency"): self.calculate_taxes_and_totals() @@ -204,10 +212,6 @@ class AccountsController(TransactionBase): self.validate_all_documents_schedule() - if self.meta.get_field("taxes_and_charges"): - self.validate_enabled_taxes_and_charges() - self.validate_tax_account_company() - self.validate_party() self.validate_currency() self.validate_party_account_currency() @@ -252,8 +256,6 @@ class AccountsController(TransactionBase): self.validate_deferred_income_expense_account() self.set_inter_company_account() - self.set_taxes_and_charges() - if self.doctype == "Purchase Invoice": self.calculate_paid_amount() # apply tax withholding only if checked and applicable From 41e9a10ab413fd4d2c279aedb0fe08ff05426f2b Mon Sep 17 00:00:00 2001 From: Ninad1306 Date: Tue, 18 Feb 2025 14:03:35 +0530 Subject: [PATCH 2/3] test: validate fetching of taxes based on taxes and charges template (cherry picked from commit 196ef7ac4e496785ac7fb5dbff2e13c9317071bc) --- .../tests/test_accounts_controller.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/erpnext/controllers/tests/test_accounts_controller.py b/erpnext/controllers/tests/test_accounts_controller.py index 2c46f04af71..ccabb361b32 100644 --- a/erpnext/controllers/tests/test_accounts_controller.py +++ b/erpnext/controllers/tests/test_accounts_controller.py @@ -931,6 +931,35 @@ class TestAccountsController(FrappeTestCase): self.assertEqual(exc_je_for_si, []) self.assertEqual(exc_je_for_pe, []) + @IntegrationTestCase.change_settings("Accounts Settings", {"add_taxes_from_item_tax_template": 1}) + def test_18_fetch_taxes_based_on_taxes_and_charges_template(self): + # Create a Sales Taxes and Charges Template + if not frappe.db.exists("Sales Taxes and Charges Template", "_Test Tax - _TC"): + doc = frappe.new_doc("Sales Taxes and Charges Template") + doc.company = self.company + doc.title = "_Test Tax" + doc.append( + "taxes", + { + "charge_type": "On Net Total", + "account_head": "Sales Expenses - _TC", + "description": "Test taxes", + "rate": 9, + }, + ) + doc.insert() + + # Create a Sales Invoice + sinv = frappe.new_doc("Sales Invoice") + sinv.customer = self.customer + sinv.company = self.company + sinv.currency = "INR" + sinv.taxes_and_charges = "_Test Tax - _TC" + sinv.append("items", {"item_code": "_Test Item", "qty": 1, "rate": 50}) + sinv.insert() + + self.assertEqual(sinv.total_taxes_and_charges, 4.5) + def test_20_journal_against_sales_invoice(self): # Invoice in Foreign Currency si = self.create_sales_invoice(qty=1, conversion_rate=80, rate=1) From 35df539da3d059c82f798541a80ab2e5ccc555c7 Mon Sep 17 00:00:00 2001 From: Smit Vora Date: Mon, 3 Mar 2025 17:02:15 +0530 Subject: [PATCH 3/3] chore: fix linters --- erpnext/controllers/tests/test_accounts_controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/controllers/tests/test_accounts_controller.py b/erpnext/controllers/tests/test_accounts_controller.py index ccabb361b32..f959cbd0488 100644 --- a/erpnext/controllers/tests/test_accounts_controller.py +++ b/erpnext/controllers/tests/test_accounts_controller.py @@ -931,7 +931,7 @@ class TestAccountsController(FrappeTestCase): self.assertEqual(exc_je_for_si, []) self.assertEqual(exc_je_for_pe, []) - @IntegrationTestCase.change_settings("Accounts Settings", {"add_taxes_from_item_tax_template": 1}) + @change_settings("Accounts Settings", {"add_taxes_from_item_tax_template": 1}) def test_18_fetch_taxes_based_on_taxes_and_charges_template(self): # Create a Sales Taxes and Charges Template if not frappe.db.exists("Sales Taxes and Charges Template", "_Test Tax - _TC"):