From 6f2e6391822564f771a92a01435ec4923c59a05f Mon Sep 17 00:00:00 2001 From: DaizyModi Date: Tue, 25 Jul 2023 11:25:53 +0530 Subject: [PATCH] fix: itemised tax breakup --- .../sales_invoice/test_sales_invoice.py | 22 ++++++++++------- erpnext/controllers/taxes_and_totals.py | 24 ++++++++++++------- .../includes/itemised_tax_breakup.html | 8 +++---- 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index f9fb6232ac96..856631ee6576 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -1900,16 +1900,22 @@ def test_item_wise_tax_breakup(self): si = self.create_si_to_test_tax_breakup() - itemised_tax, itemised_taxable_amount = get_itemised_tax_breakup_data(si) + itemised_tax_data = get_itemised_tax_breakup_data(si) - expected_itemised_tax = { - "_Test Item": {"Service Tax": {"tax_rate": 10.0, "tax_amount": 1000.0}}, - "_Test Item 2": {"Service Tax": {"tax_rate": 10.0, "tax_amount": 500.0}}, - } - expected_itemised_taxable_amount = {"_Test Item": 10000.0, "_Test Item 2": 5000.0} + expected_itemised_tax = [ + { + "item": "_Test Item", + "taxable_amount": 10000.0, + "Service Tax": {"tax_rate": 10.0, "tax_amount": 1000.0}, + }, + { + "item": "_Test Item 2", + "taxable_amount": 5000.0, + "Service Tax": {"tax_rate": 10.0, "tax_amount": 500.0}, + }, + ] - self.assertEqual(itemised_tax, expected_itemised_tax) - self.assertEqual(itemised_taxable_amount, expected_itemised_taxable_amount) + self.assertEqual(itemised_tax_data, expected_itemised_tax) frappe.flags.country = None diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 77006b905cb7..62d4c5386828 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -954,16 +954,15 @@ def get_itemised_tax_breakup_html(doc): with temporary_flag("company", doc.company): headers = get_itemised_tax_breakup_header(doc.doctype + " Item", tax_accounts) - itemised_tax, itemised_taxable_amount = get_itemised_tax_breakup_data(doc) - get_rounded_tax_amount(itemised_tax, doc.precision("tax_amount", "taxes")) + itemised_tax_data = get_itemised_tax_breakup_data(doc) + get_rounded_tax_amount(itemised_tax_data, doc.precision("tax_amount", "taxes")) update_itemised_tax_data(doc) return frappe.render_template( "templates/includes/itemised_tax_breakup.html", dict( headers=headers, - itemised_tax=itemised_tax, - itemised_taxable_amount=itemised_taxable_amount, + itemised_tax_data=itemised_tax_data, tax_accounts=tax_accounts, doc=doc, ), @@ -999,7 +998,15 @@ def get_itemised_tax_breakup_data(doc): itemised_taxable_amount = get_itemised_taxable_amount(doc.items) - return itemised_tax, itemised_taxable_amount + itemised_tax_data = [] + for item_code, taxes in itemised_tax.items(): + itemised_tax_data.append( + frappe._dict( + {"item": item_code, "taxable_amount": itemised_taxable_amount.get(item_code), **taxes} + ) + ) + + return itemised_tax_data def get_itemised_tax(taxes, with_tax_account=False): @@ -1044,9 +1051,10 @@ def get_itemised_taxable_amount(items): def get_rounded_tax_amount(itemised_tax, precision): # Rounding based on tax_amount precision - for taxes in itemised_tax.values(): - for tax_account in taxes: - taxes[tax_account]["tax_amount"] = flt(taxes[tax_account]["tax_amount"], precision) + for taxes in itemised_tax: + for row in taxes.values(): + if isinstance(row, dict) and isinstance(row["tax_amount"], float): + row["tax_amount"] = flt(row["tax_amount"], precision) class init_landed_taxes_and_totals(object): diff --git a/erpnext/templates/includes/itemised_tax_breakup.html b/erpnext/templates/includes/itemised_tax_breakup.html index fbc80de7d0db..7b507bd1fdbd 100644 --- a/erpnext/templates/includes/itemised_tax_breakup.html +++ b/erpnext/templates/includes/itemised_tax_breakup.html @@ -12,14 +12,14 @@ - {% for item, taxes in itemised_tax.items() %} + {% for taxes in itemised_tax_data %} - {{ item }} + {{ taxes.item }} {% if doc.get('is_return') %} - {{ frappe.utils.fmt_money((itemised_taxable_amount.get(item, 0))|abs, None, doc.currency) }} + {{ frappe.utils.fmt_money(taxes.taxable_amount|abs, None, doc.currency) }} {% else %} - {{ frappe.utils.fmt_money(itemised_taxable_amount.get(item, 0), None, doc.currency) }} + {{ frappe.utils.fmt_money(taxes.taxable_amount, None, doc.currency) }} {% endif %} {% for tax_account in tax_accounts %}