Skip to content

Commit

Permalink
Merge pull request #333 from rtdany10/hsn-summary-fix
Browse files Browse the repository at this point in the history
fix: hsn summary calculation
  • Loading branch information
vorasmit authored Nov 14, 2022
2 parents 827209e + ec1a34a commit d51c329
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _execute(filters=None):
data = []
added_item = []
for d in item_list:
if (d.parent, d.item_code) not in added_item:
if (d.parent, d.gst_hsn_code, d.item_code) not in added_item:
row = [d.gst_hsn_code, d.description, d.stock_uom, d.stock_qty]
total_tax = 0
tax_rate = 0
Expand All @@ -56,7 +56,7 @@ def _execute(filters=None):
row += [item_tax.get("tax_amount", 0)]

data.append(row)
added_item.append((d.parent, d.item_code))
added_item.append((d.parent, d.gst_hsn_code, d.item_code))
if data:
data = get_merged_data(columns, data) # merge same hsn code data
return columns, data
Expand Down Expand Up @@ -155,11 +155,9 @@ def get_items(filters):
GROUP BY
`tabSales Invoice Item`.parent,
`tabSales Invoice Item`.item_code,
`tabSales Invoice Item`.gst_hsn_code,
`tabSales Invoice Item`.uom
`tabSales Invoice Item`.gst_hsn_code
ORDER BY
`tabSales Invoice Item`.gst_hsn_code,
`tabSales Invoice Item`.uom
`tabSales Invoice Item`.gst_hsn_code
""",
filters,
as_dict=1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,24 @@ def tearDownClass(cls):
frappe.db.rollback()

def test_hsn_summary_for_invoice_with_duplicate_items(self):
si = create_sales_invoice(do_not_save=1, is_in_state=True)
append_item(si)
si_one = create_sales_invoice(do_not_save=1, is_in_state=True)
append_item(si_one, frappe._dict(gst_hsn_code="61149090", uom="Box"))
append_item(si_one, frappe._dict(gst_hsn_code="61149090", uom="Litre"))
si_one.submit()

si.submit()
si_two = create_sales_invoice(do_not_save=1, is_in_state=True)
append_item(si_two, frappe._dict(gst_hsn_code="61149090", uom="Box"))
append_item(si_two, frappe._dict(gst_hsn_code="61149090", uom="Litre"))

si_two.submit()

columns, data = run_report(
filters=frappe._dict(
{
"company": "_Test Indian Registered Company",
"company_gstin": si.company_gstin,
"from_date": si.posting_date,
"to_date": si.posting_date,
"company_gstin": si_one.company_gstin,
"from_date": si_one.posting_date,
"to_date": si_one.posting_date,
}
)
)
Expand All @@ -44,5 +50,6 @@ def test_hsn_summary_for_invoice_with_duplicate_items(self):
self.assertTrue(filtered_rows)

hsn_row = filtered_rows[0]
self.assertEquals(hsn_row["stock_qty"], 2.0)
self.assertEquals(hsn_row["total_amount"], 236) # 2 * 100 * 1.18
self.assertEquals(hsn_row["stock_qty"], 6.0)
self.assertEquals(hsn_row["taxable_amount"], 600)
self.assertEquals(hsn_row["total_amount"], 708) # 6 * 100 * 1.18
1 change: 1 addition & 0 deletions india_compliance/gst_india/utils/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def append_item(transaction, data=None, company_abbr="_TIRC"):
{
"item_code": data.item_code or "_Test Trading Goods 1",
"qty": data.qty or 1,
"uom": data.uom,
"rate": data.rate or 100,
"cost_center": f"Main - {company_abbr}",
"is_nil_exempt": data.is_nil_exempt,
Expand Down

0 comments on commit d51c329

Please sign in to comment.