Skip to content

Commit

Permalink
Merge pull request #488 from resilient-tech/mergify/bp/version-14-hot…
Browse files Browse the repository at this point in the history
…fix/pr-487

fix: rounding and other issues in GSTR-1 related reports (backport #487)
  • Loading branch information
sagarvora authored Mar 4, 2023
2 parents dac17b5 + 230eb3e commit 098b906
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 39 deletions.
14 changes: 7 additions & 7 deletions india_compliance/gst_india/report/gstr_1/gstr_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -1090,20 +1090,20 @@ def get_advances_json(data, gstin):
for item in items:
itms = {
"rt": item["rate"],
"ad_amount": flt(item.get("taxable_value")),
"csamt": flt(item.get("cess_amount")),
"ad_amount": flt(item.get("taxable_value"), 2),
"csamt": flt(item.get("cess_amount"), 2),
}

if supply_type == "INTRA":
itms.update(
{
"samt": flt((itms["ad_amount"] * itms["rt"]) / 100),
"camt": flt((itms["ad_amount"] * itms["rt"]) / 100),
"samt": flt((itms["ad_amount"] * itms["rt"]) / 100, 2),
"camt": flt((itms["ad_amount"] * itms["rt"]) / 100, 2),
"rt": itms["rt"] * 2,
}
)
else:
itms.update({"iamt": flt((itms["ad_amount"] * itms["rt"]) / 100)})
itms["iamt"] = flt((itms["ad_amount"] * itms["rt"]) / 100, 2)

row["itms"].append(itms)
out.append(row)
Expand Down Expand Up @@ -1193,7 +1193,7 @@ def get_cdnr_reg_json(res, gstin):
inv_item = {
"nt_num": invoice[0]["invoice_number"],
"nt_dt": getdate(invoice[0]["posting_date"]).strftime("%d-%m-%Y"),
"val": abs(flt(invoice[0]["invoice_value"])),
"val": abs(flt(invoice[0]["invoice_value"], 2)),
"ntty": invoice[0]["document_type"],
"pos": "%02d" % int(invoice[0]["place_of_supply"].split("-")[0]),
"rchrg": invoice[0]["is_reverse_charge"],
Expand Down Expand Up @@ -1221,7 +1221,7 @@ def get_cdnr_unreg_json(res, gstin):
inv_item = {
"nt_num": items[0]["invoice_number"],
"nt_dt": getdate(items[0]["posting_date"]).strftime("%d-%m-%Y"),
"val": abs(flt(items[0]["invoice_value"])),
"val": abs(flt(items[0]["invoice_value"], 2)),
"ntty": items[0]["document_type"],
"pos": "%02d" % int(items[0]["place_of_supply"].split("-")[0]),
"typ": get_invoice_type(items[0]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@


def execute(filters=None):
return _execute(filters)


def _execute(filters=None):
if not filters:
filters = {}

columns = get_columns()

output_gst_accounts = [
Expand All @@ -40,25 +37,39 @@ def _execute(filters=None):
data = []
added_item = []
for d in item_list:
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
for tax in tax_columns:
item_tax = itemised_tax.get((d.parent, d.item_code), {}).get(tax, {})
tax_rate += flt(item_tax.get("tax_rate", 0))
total_tax += flt(item_tax.get("tax_amount", 0))

row += [tax_rate, d.taxable_value + total_tax, d.taxable_value]

for tax in tax_columns:
item_tax = itemised_tax.get((d.parent, d.item_code), {}).get(tax, {})
row += [item_tax.get("tax_amount", 0)]

data.append(row)
added_item.append((d.parent, d.gst_hsn_code, d.item_code))
if (d.parent, d.gst_hsn_code, d.item_code) in added_item:
continue

if d.gst_hsn_code.startswith("99"):
# service item doesnt have qty / uom
d.stock_qty = 0
d.uqc = "NA"

else:
d.uqc = d.get("uqc", "").upper()
if d.uqc not in UOMS:
d.uqc = "OTH"

row = [d.gst_hsn_code, d.description, d.uqc, d.stock_qty]
total_tax = 0
tax_rate = 0
for tax in tax_columns:
item_tax = itemised_tax.get((d.parent, d.item_code), {}).get(tax, {})
tax_rate += flt(item_tax.get("tax_rate", 0))
total_tax += flt(item_tax.get("tax_amount", 0))

row += [tax_rate, d.taxable_value + total_tax, d.taxable_value]

for tax in tax_columns:
item_tax = itemised_tax.get((d.parent, d.item_code), {}).get(tax, {})
row += [item_tax.get("tax_amount", 0)]

data.append(row)
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 All @@ -78,8 +89,8 @@ def get_columns():
"width": 300,
},
{
"fieldname": "stock_uom",
"label": _("Stock UOM"),
"fieldname": "uqc",
"label": _("UQC"),
"fieldtype": "Data",
"width": 100,
},
Expand Down Expand Up @@ -138,7 +149,7 @@ def get_items(filters):
f"""
SELECT
`tabSales Invoice Item`.gst_hsn_code,
`tabSales Invoice Item`.stock_uom,
`tabSales Invoice Item`.stock_uom as uqc,
sum(`tabSales Invoice Item`.stock_qty) AS stock_qty,
sum(`tabSales Invoice Item`.taxable_value) AS taxable_value,
sum(`tabSales Invoice Item`.base_price_list_rate) AS base_price_list_rate,
Expand Down Expand Up @@ -308,31 +319,28 @@ def download_json_file():


def get_hsn_wise_json_data(filters, report_data):

filters = frappe._dict(filters)
gst_accounts = get_gst_accounts_by_type(filters.company, "Output")
data = []
count = 1

for hsn in report_data:
uom = hsn.get("stock_uom", "").upper()
if uom not in UOMS:
uom = "OTH"

row = {
"num": count,
"hsn_sc": hsn.get("gst_hsn_code"),
"desc": hsn.get("description")[:30],
"uqc": uom,
"uqc": hsn.get("uqc"),
"qty": hsn.get("stock_qty"),
"rt": flt(hsn.get("tax_rate"), 2),
"txval": flt(hsn.get("taxable_amount", 2)),
"txval": flt(hsn.get("taxable_amount"), 2),
"iamt": 0.0,
"camt": 0.0,
"samt": 0.0,
"csamt": 0.0,
}

if hsn_description := hsn.get("description"):
row["desc"] = hsn_description[:30]

row["iamt"] += flt(
hsn.get(frappe.scrub(cstr(gst_accounts.get("igst_account"))), 0.0), 2
)
Expand Down

0 comments on commit 098b906

Please sign in to comment.