Skip to content

Commit

Permalink
fix: Correct Tax Breakup for different tax rates for same hsn code
Browse files Browse the repository at this point in the history
  • Loading branch information
DaizyModi committed Jul 21, 2023
1 parent cc36af5 commit 99474c0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
36 changes: 25 additions & 11 deletions erpnext/controllers/taxes_and_totals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
),
Expand Down Expand Up @@ -1000,12 +999,26 @@ 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):
Expand Down Expand Up @@ -1048,11 +1061,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):
Expand Down
8 changes: 4 additions & 4 deletions erpnext/templates/includes/itemised_tax_breakup.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
</tr>
</thead>
<tbody>
{% for item, taxes in itemised_tax.items() %}
{% for taxes in itemised_tax_data %}
<tr>
<td>{{ item }}</td>
<td>{{ taxes.item }}</td>
<td class="text-right">
{% 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 %}
</td>
{% for tax_account in tax_accounts %}
Expand Down

0 comments on commit 99474c0

Please sign in to comment.