Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Correct Tax Breakup for different tax rates for same hsn code #36235

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 16 additions & 8 deletions erpnext/controllers/taxes_and_totals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
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