Skip to content

Commit

Permalink
fix: use base_tax_amount_after_discount_amount instead of tax_amount
Browse files Browse the repository at this point in the history
  • Loading branch information
ljain112 committed May 24, 2024
1 parent 9c3341c commit 7ed762c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 15 deletions.
13 changes: 7 additions & 6 deletions india_compliance/gst_india/overrides/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,14 @@ def update_taxable_values(doc, valid_accounts):
if any(
row
for row in doc.taxes
if row.tax_amount and row.account_head in valid_accounts
if row.base_tax_amount_after_discount_amount
and row.account_head in valid_accounts
):
reference_row_index = next(
(
cint(row.row_id) - 1
for row in doc.taxes
if row.tax_amount
if row.base_tax_amount_after_discount_amount
and row.charge_type == "On Previous Row Total"
and row.account_head in valid_accounts
),
Expand Down Expand Up @@ -184,10 +185,10 @@ def get_tds_amount(doc):
continue

if row.get("add_deduct_tax") and row.add_deduct_tax == "Deduct":
tds_amount -= row.tax_amount
tds_amount -= row.base_tax_amount_after_discount_amount

Check warning on line 188 in india_compliance/gst_india/overrides/transaction.py

View check run for this annotation

Codecov / codecov/patch

india_compliance/gst_india/overrides/transaction.py#L188

Added line #L188 was not covered by tests

else:
tds_amount += row.tax_amount
tds_amount += row.base_tax_amount_after_discount_amount

Check warning on line 191 in india_compliance/gst_india/overrides/transaction.py

View check run for this annotation

Codecov / codecov/patch

india_compliance/gst_india/overrides/transaction.py#L191

Added line #L191 was not covered by tests

return tds_amount

Expand Down Expand Up @@ -1028,7 +1029,7 @@ def set_item_wise_tax_details(self):

for row in self.doc.taxes:
if (
not row.tax_amount
not row.base_tax_amount_after_discount_amount
or not row.item_wise_tax_detail
or row.account_head not in self.gst_account_map
):
Expand All @@ -1041,7 +1042,7 @@ def set_item_wise_tax_details(self):

old = json.loads(row.item_wise_tax_detail)

tax_difference = row.tax_amount
tax_difference = row.base_tax_amount_after_discount_amount

# update item taxes
for item_name in old:
Expand Down
4 changes: 2 additions & 2 deletions india_compliance/gst_india/utils/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ def get(self):
tax_type,
{
"tax_rate": flt(item.get(f"{_tax_type}_rate", 0)),
"tax_amount": 0,
"base_tax_amount_after_discount_amount": 0,
},
)

tax_details["tax_amount"] += flt(
tax_details["base_tax_amount_after_discount_amount"] += flt(
item.get(f"{_tax_type}_amount", 0), self.precision
)

Expand Down
2 changes: 1 addition & 1 deletion india_compliance/gst_india/utils/test_e_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def test_progressive_item_tax_amount(self):

total_item_wise_cgst = sum(row["CgstAmt"] for row in e_invoice_data.item_list)
self.assertEqual(
si.taxes[0].tax_amount,
si.taxes[0].base_tax_amount_after_discount_amount,
total_item_wise_cgst,
)

Expand Down
10 changes: 8 additions & 2 deletions india_compliance/gst_india/utils/transaction_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ def update_transaction_tax_details(self):
self.transaction_details[key] = 0

for row in self.doc.taxes:
if not row.tax_amount or row.account_head not in self.gst_accounts:
if (
not row.base_tax_amount_after_discount_amount
or row.account_head not in self.gst_accounts
):
continue

tax = self.gst_accounts[row.account_head][:-8]
Expand Down Expand Up @@ -326,7 +329,10 @@ def update_item_tax_details(self, item_details, item):
item_details.update({f"{tax}_amount": 0, f"{tax}_rate": 0})

for row in self.doc.taxes:
if not row.tax_amount or row.account_head not in self.gst_accounts:
if (
not row.base_tax_amount_after_discount_amount
or row.account_head not in self.gst_accounts
):
continue

# Remove '_account' from 'cgst_account'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def get_taxes_for_docs(docs, doctype, is_sales_doctype):
return (
frappe.qb.from_(taxes)
.select(
taxes.tax_amount,
taxes.base_tax_amount_after_discount_amount,
taxes.account_head,
taxes.parent,
taxes.item_wise_tax_detail,
Expand Down
6 changes: 3 additions & 3 deletions india_compliance/templates/gst_breakup.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
</td>
{% else %}
<td class="text-right">
{% if value.tax_rate or not value.tax_amount %}
{% if value.tax_rate or not value.base_tax_amount_after_discount_amount %}
({{ value.tax_rate }}%)&nbsp;
{% endif %}

{% if doc.get('is_return') %}
{{ frappe.utils.fmt_money(value.tax_amount |abs, None, "INR") }}
{{ frappe.utils.fmt_money(value.base_tax_amount_after_discount_amount |abs, None, "INR") }}
{% else %}
{{ frappe.utils.fmt_money(value.tax_amount, None, "INR") }}
{{ frappe.utils.fmt_money(value.base_tax_amount_after_discount_amount, None, "INR") }}
{% endif %}
</td>
{% endif %}
Expand Down

0 comments on commit 7ed762c

Please sign in to comment.