Skip to content

Commit

Permalink
fix: tax breakup test fix, eway bill hsn fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesis189 committed Sep 16, 2021
1 parent c2e5d8f commit d1a4c73
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
13 changes: 10 additions & 3 deletions erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -1420,15 +1420,22 @@ def test_item_wise_tax_breakup_india(self):
itemised_tax, itemised_taxable_amount = get_itemised_tax_breakup_data(si)

expected_itemised_tax = {
"999800": {
"_Test Item": {
"Service Tax": {
"tax_rate": 10.0,
"tax_amount": 1000.0
}
},
"_Test Item 2": {
"Service Tax": {
"tax_rate": 10.0,
"tax_amount": 1500.0
"tax_amount": 500.0
}
}
}
expected_itemised_taxable_amount = {
"999800": 15000.0
"_Test Item": 10000.0,
"_Test Item 2": 5000.0
}

self.assertEqual(itemised_tax, expected_itemised_tax)
Expand Down
27 changes: 17 additions & 10 deletions erpnext/regional/india/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,30 +117,37 @@ def get_itemised_tax_breakup_header(item_doctype, tax_accounts):
else:
return [_("Item"), _("Taxable Amount")] + tax_accounts

def get_itemised_tax_breakup_data(doc, account_wise=False):
def get_itemised_tax_breakup_data(doc, account_wise=False, hsn_wise=False):
itemised_tax = get_itemised_tax(doc.taxes, with_tax_account=account_wise)

itemised_taxable_amount = get_itemised_taxable_amount(doc.items)

if not frappe.get_meta(doc.doctype + " Item").has_field('gst_hsn_code'):
return itemised_tax, itemised_taxable_amount

if hsn_wise:
item_hsn_map = frappe._dict()
for d in doc.items:
item_hsn_map.setdefault(d.item_code or d.item_name, d.get("gst_hsn_code"))

hsn_tax = {}
for item, taxes in itemised_tax.items():
hsn_tax.setdefault(item, frappe._dict())
item_or_hsn = item if not hsn_wise else item_hsn_map.get(item)
hsn_tax.setdefault(item_or_hsn, frappe._dict())
for tax_desc, tax_detail in taxes.items():
key = tax_desc
if account_wise:
key = tax_detail.get('tax_account')
hsn_tax[item].setdefault(key, {"tax_rate": 0, "tax_amount": 0})
hsn_tax[item][key]["tax_rate"] = tax_detail.get("tax_rate")
hsn_tax[item][key]["tax_amount"] += tax_detail.get("tax_amount")
hsn_tax[item_or_hsn].setdefault(key, {"tax_rate": 0, "tax_amount": 0})
hsn_tax[item_or_hsn][key]["tax_rate"] = tax_detail.get("tax_rate")
hsn_tax[item_or_hsn][key]["tax_amount"] += tax_detail.get("tax_amount")

# set taxable amount
hsn_taxable_amount = frappe._dict()
for item in itemised_taxable_amount:
hsn_taxable_amount.setdefault(item, 0)
hsn_taxable_amount[item] += itemised_taxable_amount.get(item)
item_or_hsn = item if not hsn_wise else item_hsn_map.get(item)
hsn_taxable_amount.setdefault(item_or_hsn, 0)
hsn_taxable_amount[item_or_hsn] += itemised_taxable_amount.get(item)

return hsn_tax, hsn_taxable_amount

Expand Down Expand Up @@ -434,7 +441,7 @@ def get_ewb_data(dt, dn):
data.itemList = []
data.totalValue = doc.total

data = get_item_list(data, doc)
data = get_item_list(data, doc, hsn_wise=True)

disable_rounded = frappe.db.get_single_value('Global Defaults', 'disable_rounded_total')
data.totInvValue = doc.grand_total if disable_rounded else doc.rounded_total
Expand Down Expand Up @@ -545,7 +552,7 @@ def get_address_details(data, doc, company_address, billing_address, dispatch_ad

return data

def get_item_list(data, doc):
def get_item_list(data, doc, hsn_wise=False):
for attr in ['cgstValue', 'sgstValue', 'igstValue', 'cessValue', 'OthValue']:
data[attr] = 0

Expand All @@ -557,7 +564,7 @@ def get_item_list(data, doc):
'cess_account': ['cessRate', 'cessValue']
}
item_data_attrs = ['sgstRate', 'cgstRate', 'igstRate', 'cessRate', 'cessNonAdvol']
hsn_wise_charges, hsn_taxable_amount = get_itemised_tax_breakup_data(doc, account_wise=True)
hsn_wise_charges, hsn_taxable_amount = get_itemised_tax_breakup_data(doc, account_wise=True, hsn_wise=hsn_wise)
for hsn_code, taxable_amount in hsn_taxable_amount.items():
item_data = frappe._dict()
if not hsn_code:
Expand Down

0 comments on commit d1a4c73

Please sign in to comment.