Merge branch 'develop' into fix-tax-breakup-for-diff-tax-rates
diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
index 0280c35..41e5554 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 @@
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 77006b9..62d4c53 100644
--- a/erpnext/controllers/taxes_and_totals.py
+++ b/erpnext/controllers/taxes_and_totals.py
@@ -954,16 +954,15 @@
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 @@
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_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 fbc80de..89d4373 100644
--- a/erpnext/templates/includes/itemised_tax_breakup.html
+++ b/erpnext/templates/includes/itemised_tax_breakup.html
@@ -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 %}