diff --git a/india_compliance/gst_india/api_classes/returns.py b/india_compliance/gst_india/api_classes/returns.py index 3a6f511c5..f84eb7480 100644 --- a/india_compliance/gst_india/api_classes/returns.py +++ b/india_compliance/gst_india/api_classes/returns.py @@ -337,6 +337,9 @@ def get_auth_token(self): if not self.auth_token: return None + if not self.session_expiry: + return None + if self.session_expiry <= now_datetime(): return None diff --git a/india_compliance/gst_india/doctype/purchase_reconciliation_tool/__init__.py b/india_compliance/gst_india/doctype/purchase_reconciliation_tool/__init__.py index e60ae2d7a..23da2e3d2 100644 --- a/india_compliance/gst_india/doctype/purchase_reconciliation_tool/__init__.py +++ b/india_compliance/gst_india/doctype/purchase_reconciliation_tool/__init__.py @@ -32,6 +32,7 @@ class Fields(Enum): SGST = "sgst" IGST = "igst" CESS = "cess" + TOTAL_GST = "total_gst" class Rule(Enum): @@ -188,9 +189,7 @@ class MatchStatus(Enum): Fields.PLACE_OF_SUPPLY: Rule.EXACT_MATCH, Fields.REVERSE_CHARGE: Rule.EXACT_MATCH, Fields.TAXABLE_VALUE: Rule.ROUNDING_DIFFERENCE, - Fields.CGST: Rule.ROUNDING_DIFFERENCE, - Fields.SGST: Rule.ROUNDING_DIFFERENCE, - Fields.IGST: Rule.ROUNDING_DIFFERENCE, + Fields.TOTAL_GST: Rule.ROUNDING_DIFFERENCE, Fields.CESS: Rule.ROUNDING_DIFFERENCE, }, }, @@ -203,9 +202,7 @@ class MatchStatus(Enum): Fields.PLACE_OF_SUPPLY: Rule.EXACT_MATCH, Fields.REVERSE_CHARGE: Rule.EXACT_MATCH, Fields.TAXABLE_VALUE: Rule.ROUNDING_DIFFERENCE, - Fields.CGST: Rule.ROUNDING_DIFFERENCE, - Fields.SGST: Rule.ROUNDING_DIFFERENCE, - Fields.IGST: Rule.ROUNDING_DIFFERENCE, + Fields.TOTAL_GST: Rule.ROUNDING_DIFFERENCE, Fields.CESS: Rule.ROUNDING_DIFFERENCE, }, }, @@ -233,9 +230,7 @@ class MatchStatus(Enum): Fields.PLACE_OF_SUPPLY: Rule.EXACT_MATCH, Fields.REVERSE_CHARGE: Rule.EXACT_MATCH, Fields.TAXABLE_VALUE: Rule.ROUNDING_DIFFERENCE, - Fields.CGST: Rule.ROUNDING_DIFFERENCE, - Fields.SGST: Rule.ROUNDING_DIFFERENCE, - Fields.IGST: Rule.ROUNDING_DIFFERENCE, + Fields.TOTAL_GST: Rule.ROUNDING_DIFFERENCE, Fields.CESS: Rule.ROUNDING_DIFFERENCE, }, }, @@ -748,7 +743,7 @@ def reconcile(self, category, amended_category): # GSTIN Level matching purchases = self.get_unmatched_purchase_or_bill_of_entry(category) inward_supplies = self.get_unmatched_inward_supply(category, amended_category) - self.reconcile_for_rules(GSTIN_RULES, purchases, inward_supplies, category) + self.reconcile_for_rules(GSTIN_RULES, purchases, inward_supplies) # In case of IMPG GST in not available in 2A. So skip PAN level matching. if category == "IMPG": @@ -757,9 +752,9 @@ def reconcile(self, category, amended_category): # PAN Level matching purchases = self.get_pan_level_data(purchases) inward_supplies = self.get_pan_level_data(inward_supplies) - self.reconcile_for_rules(PAN_RULES, purchases, inward_supplies, category) + self.reconcile_for_rules(PAN_RULES, purchases, inward_supplies) - def reconcile_for_rules(self, rules, purchases, inward_supplies, category): + def reconcile_for_rules(self, rules, purchases, inward_supplies): if not (purchases and inward_supplies): return @@ -769,12 +764,9 @@ def reconcile_for_rules(self, rules, purchases, inward_supplies, category): inward_supplies, rule.get("match_status").value, rule.get("rule"), - category, ) - def reconcile_for_rule( - self, purchases, inward_supplies, match_status, rules, category - ): + def reconcile_for_rule(self, purchases, inward_supplies, match_status, rules): """ Sequentially reconcile invoices as per rules list. - Reconciliation only done between invoices of same GSTIN. @@ -785,28 +777,18 @@ def reconcile_for_rule( if not inward_supplies.get(supplier_gstin): continue - summary_diff = {} - if match_status == "Residual Match" and category != "CDNR": - summary_diff = self.get_summary_difference( - purchases[supplier_gstin], inward_supplies[supplier_gstin] - ) - for purchase_invoice_name, purchase in ( purchases[supplier_gstin].copy().items() ): - if summary_diff and not ( - abs(summary_diff[purchase.bill_date.month]) < 2 - ): - continue - for inward_supply_name, inward_supply in ( inward_supplies[supplier_gstin].copy().items() ): - if ( - summary_diff - and purchase.bill_date.month != inward_supply.bill_date.month - ): - continue + if match_status == "Residual Match": + if ( + abs((purchase.bill_date - inward_supply.bill_date).days) + > 10 + ): + continue if not self.is_doc_matching(purchase, inward_supply, rules): continue @@ -823,26 +805,6 @@ def reconcile_for_rule( inward_supplies[supplier_gstin].pop(inward_supply_name) break - def get_summary_difference(self, data1, data2): - """ - Returns dict with difference of monthly purchase for given supplier data. - Calculated only for Residual Match. - - Objective: Residual match is to match Invoices where bill no is completely different. - It should be matched for invoices of a given month only if difference in total invoice - value is negligible for purchase and inward supply. - """ - summary = {} - for doc in data1.values(): - summary.setdefault(doc.bill_date.month, 0) - summary[doc.bill_date.month] += BaseUtil.get_total_tax(doc) - - for doc in data2.values(): - summary.setdefault(doc.bill_date.month, 0) - summary[doc.bill_date.month] -= BaseUtil.get_total_tax(doc) - - return summary - def is_doc_matching(self, purchase, inward_supply, rules): """ Returns true if all fields match from purchase and inward supply as per rules. @@ -911,6 +873,10 @@ def get_amount_difference(self, purchase, inward_supply, field): if field == "cess": BaseUtil.update_cess_amount(purchase) + if field == "total_gst": + BaseUtil.update_total_gst_amount(purchase) + BaseUtil.update_total_gst_amount(inward_supply) + return abs(purchase.get(field, 0) - inward_supply.get(field, 0)) def update_matching_doc( @@ -1308,7 +1274,14 @@ def get_total_tax(doc): @staticmethod def update_cess_amount(doc): - doc.cess = doc.get("cess", 0) + doc.get("cess_non_advol", 0) + if doc.get("cess_non_advol"): + doc.cess = doc.get("cess", 0) + doc.get("cess_non_advol", 0) + doc.cess_non_advol = 0 + + @staticmethod + def update_total_gst_amount(doc): + if not doc.get("total_gst"): + doc.total_gst = doc.cgst + doc.sgst + doc.igst @staticmethod def get_periods(date_range, return_type: ReturnType, reversed_order=False): 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 ae89bd516..ddb357a0d 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 @@ -317,7 +317,7 @@ def get_json(filters, report_name, data): gst_json = {"version": "GST3.1.2", "hash": "hash", "gstin": gstin, "fp": fp} - gst_json["hsn"] = {"data": get_hsn_wise_json_data(filters, report_data)} + gst_json["hsn"] = get_hsn_wise_json_data(filters, report_data) return {"report_name": report_name, "data": gst_json} @@ -378,4 +378,4 @@ def get_hsn_wise_json_data(filters, report_data): data.append(row) count += 1 - return data + return {"data": data} diff --git a/india_compliance/install.py b/india_compliance/install.py index d379f32e7..8f6a44f32 100644 --- a/india_compliance/install.py +++ b/india_compliance/install.py @@ -39,6 +39,7 @@ "update_company_gstin", "update_payment_entry_fields", "update_itc_classification_field", + "update_reconciliation_status", "update_default_gstr3b_status", "improve_item_tax_template", "update_vehicle_no_field_in_purchase_receipt", diff --git a/india_compliance/patches/check_version_compatibility.py b/india_compliance/patches/check_version_compatibility.py index db05911a9..9893d0167 100644 --- a/india_compliance/patches/check_version_compatibility.py +++ b/india_compliance/patches/check_version_compatibility.py @@ -35,6 +35,9 @@ def execute(): " Compliance.\n" ) + if IC_VERSION.major == 16: + continue + app_branch = get_app_branch(app_name.lower()) required_versions = app["required_versions"] diff --git a/india_compliance/patches/post_install/update_gst_treatment_for_taxable_nil_transaction_item.py b/india_compliance/patches/post_install/update_gst_treatment_for_taxable_nil_transaction_item.py index 6b9258729..f9a76fc1d 100644 --- a/india_compliance/patches/post_install/update_gst_treatment_for_taxable_nil_transaction_item.py +++ b/india_compliance/patches/post_install/update_gst_treatment_for_taxable_nil_transaction_item.py @@ -37,6 +37,10 @@ def update_nil_rated_items(): nil_rated_templates = frappe.get_all( "Item Tax Template", filters={"gst_treatment": "Nil-Rated"}, pluck="name" ) + + if not nil_rated_templates: + return + for dt in DOCTYPES: doctype = frappe.qb.DocType(dt)