From b84deec601b79679137377c6500d7ca3af9202ac Mon Sep 17 00:00:00 2001 From: DaizyModi Date: Fri, 21 Jul 2023 17:26:35 +0530 Subject: [PATCH] fix: Correct Tax Breakup for different tax rates for same hsn code --- erpnext/controllers/taxes_and_totals.py | 34 +++++++++++++------ .../includes/itemised_tax_breakup.html | 8 ++--- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 4661c5ca7e..d9b8acb8ed 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -955,9 +955,9 @@ def get_itemised_tax_breakup_html(doc): headers = get_itemised_tax_breakup_header(doc.doctype + " Item", tax_accounts) # get tax breakup data - itemised_tax, itemised_taxable_amount = get_itemised_tax_breakup_data(doc) + itemised_tax_data = get_itemised_tax_breakup_data(doc) - get_rounded_tax_amount(itemised_tax, doc.precision("tax_amount", "taxes")) + get_rounded_tax_amount(itemised_tax_data, doc.precision("tax_amount", "taxes"), tax_accounts) update_itemised_tax_data(doc) frappe.flags.company = None @@ -966,8 +966,7 @@ def get_itemised_tax_breakup_html(doc): "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, ), @@ -1000,12 +999,24 @@ def get_itemised_tax_breakup_header(item_doctype, tax_accounts): @erpnext.allow_regional -def get_itemised_tax_breakup_data(doc): - itemised_tax = get_itemised_tax(doc.taxes) +def get_itemised_tax_breakup_data(doc, with_tax_account=False): + return _get_itemised_tax_breakup_data(doc, with_tax_account=False) + + +def _get_itemised_tax_breakup_data(doc, with_tax_account=False): + itemised_tax = get_itemised_tax(doc.taxes, with_tax_account=with_tax_account) 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(): + for _item_code, taxable_amount in itemised_taxable_amount.items(): + if item_code == _item_code: + itemised_tax_data.append( + frappe._dict({"item": item_code, "taxable_amount": taxable_amount, **taxes}) + ) + + return itemised_tax_data def get_itemised_tax(taxes, with_tax_account=False): @@ -1048,11 +1059,12 @@ def get_itemised_taxable_amount(items): return itemised_taxable_amount -def get_rounded_tax_amount(itemised_tax, precision): +def get_rounded_tax_amount(itemised_tax, precision, tax_accounts): # 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 _itemised_tax in itemised_tax: + for key, value in _itemised_tax.items(): + if key in tax_accounts: + value["tax_amount"] = flt(value["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 fbc80de7d0..89d4373036 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 %}