From 230eb3ea1f72e4eacb99ca76bfca0c3f7e4c1d17 Mon Sep 17 00:00:00 2001 From: Sagar Vora Date: Sat, 4 Mar 2023 18:43:36 +0530 Subject: [PATCH] fix: rounding and other issues in GSTR-1 related reports (cherry picked from commit 9ffc1072223f47bc899fd5b35a7f3dbfb689271f) --- .../gst_india/report/gstr_1/gstr_1.py | 14 ++-- .../hsn_wise_summary_of_outward_supplies.py | 72 ++++++++++--------- 2 files changed, 47 insertions(+), 39 deletions(-) diff --git a/india_compliance/gst_india/report/gstr_1/gstr_1.py b/india_compliance/gst_india/report/gstr_1/gstr_1.py index 4459ddc87..46199eb3c 100644 --- a/india_compliance/gst_india/report/gstr_1/gstr_1.py +++ b/india_compliance/gst_india/report/gstr_1/gstr_1.py @@ -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) @@ -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"], @@ -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]), diff --git a/india_compliance/gst_india/report/hsn_wise_summary_of_outward_supplies/hsn_wise_summary_of_outward_supplies.py b/india_compliance/gst_india/report/hsn_wise_summary_of_outward_supplies/hsn_wise_summary_of_outward_supplies.py index 63a7186e6..20028bac9 100644 --- a/india_compliance/gst_india/report/hsn_wise_summary_of_outward_supplies/hsn_wise_summary_of_outward_supplies.py +++ b/india_compliance/gst_india/report/hsn_wise_summary_of_outward_supplies/hsn_wise_summary_of_outward_supplies.py @@ -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 = [ @@ -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 @@ -78,8 +89,8 @@ def get_columns(): "width": 300, }, { - "fieldname": "stock_uom", - "label": _("Stock UOM"), + "fieldname": "uqc", + "label": _("UQC"), "fieldtype": "Data", "width": 100, }, @@ -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, @@ -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 )