From fc9881538714f89c9b795b3713a0ced2275d6cf7 Mon Sep 17 00:00:00 2001 From: Ninad1306 Date: Thu, 27 Feb 2025 18:32:35 +0530 Subject: [PATCH 1/2] fix: allow reclaim of itc through journal entry (cherry picked from commit d28ac00accae7c2f58a2eeae3b12fe6bdeee788d) # Conflicts: # india_compliance/patches.txt --- .../gstr_3b_report/gstr_3b_report.html | 8 +-- .../doctype/gstr_3b_report/gstr_3b_report.py | 53 +++++++++++++------ .../gst_india/setup/property_setters.py | 2 +- india_compliance/patches.txt | 5 ++ 4 files changed, 46 insertions(+), 22 deletions(-) diff --git a/india_compliance/gst_india/doctype/gstr_3b_report/gstr_3b_report.html b/india_compliance/gst_india/doctype/gstr_3b_report/gstr_3b_report.html index 138b58be39..44d467ce8d 100644 --- a/india_compliance/gst_india/doctype/gstr_3b_report/gstr_3b_report.html +++ b/india_compliance/gst_india/doctype/gstr_3b_report/gstr_3b_report.html @@ -256,7 +256,7 @@
4.   {{__("Eligible ITC")}}
-   (1) {{__("As per rules 42 & 43 of CGST Rules and section 17(5)")}} +   (1) {{__("As per rules 38,42 & 43 of CGST Rules and section 17(5)")}} {{ flt(data.itc_elg.itc_rev[0].iamt, 2) }} {{ flt(data.itc_elg.itc_rev[0].camt, 2) }} {{ flt(data.itc_elg.itc_rev[0].samt, 2) }} @@ -270,14 +270,14 @@
4.   {{__("Eligible ITC")}}
{{ flt(data.itc_elg.itc_rev[1].csamt, 2) }} - (C) {{__("Net ITC Available(A) - (B)")}} + (C) {{__("Net ITC Available (A) - (B)")}} {{ flt(data.itc_elg.itc_net.iamt, 2) }} {{ flt(data.itc_elg.itc_net.camt, 2) }} {{ flt(data.itc_elg.itc_net.samt, 2) }} {{ flt(data.itc_elg.itc_net.csamt, 2) }} - (D) {{__("Ineligible ITC")}} + (D) {{__("Other Details")}} @@ -311,7 +311,7 @@
5.    {{__("Values of exempt, nil rated and non-GST inward supplies" - {{__("From a supplier under composition scheme, Exempt and Nil rated")}} + {{__("From a supplier under composition scheme, Exempt and Nil rated supply")}} {{ flt(data.inward_sup.isup_details[0].inter, 2) }} {{ flt(data.inward_sup.isup_details[0].intra, 2) }} diff --git a/india_compliance/gst_india/doctype/gstr_3b_report/gstr_3b_report.py b/india_compliance/gst_india/doctype/gstr_3b_report/gstr_3b_report.py index 3a359f3a22..53b9832b2c 100644 --- a/india_compliance/gst_india/doctype/gstr_3b_report/gstr_3b_report.py +++ b/india_compliance/gst_india/doctype/gstr_3b_report/gstr_3b_report.py @@ -19,6 +19,13 @@ ) VALUES_TO_UPDATE = ["iamt", "camt", "samt", "csamt"] +GST_TAX_TYPE_MAP = { + "sgst": "samt", + "cgst": "camt", + "igst": "iamt", + "cess": "csamt", + "cess_non_advol": "csamt", +} class GSTR3BReport(Document): @@ -55,6 +62,7 @@ def get_data(self): inward_nil_exempt = self.get_inward_nil_exempt( self.gst_details.get("gst_state") ) + self.set_reclaim_of_itc_reversal() self.set_inward_nil_exempt(inward_nil_exempt) self.set_reverse_charge_supply_through_ecomm_operators() @@ -195,13 +203,6 @@ def update_itc_reversal_from_journal_entry(self): ).run(as_dict=True) net_itc = self.report_dict["itc_elg"]["itc_net"] - gst_tax_type_to_key_map = { - "sgst": "samt", - "cgst": "camt", - "igst": "iamt", - "cess": "csamt", - "cess_non_advol": "csamt", - } for entry in reversal_entries: if entry.ineligibility_reason == "As per rules 42 & 43 of CGST Rules": @@ -209,10 +210,11 @@ def update_itc_reversal_from_journal_entry(self): else: index = 1 - tax_amount_key = gst_tax_type_to_key_map.get(entry.gst_tax_type) + tax_amount_key = GST_TAX_TYPE_MAP.get(entry.gst_tax_type) self.report_dict["itc_elg"]["itc_rev"][index][ tax_amount_key ] += entry.amount + net_itc[tax_amount_key] -= entry.amount def get_itc_details(self): @@ -277,6 +279,30 @@ def _get_tax_amount(account_type): itc_details["Import Of Goods"]["iamt"] += igst itc_details["Import Of Goods"]["csamt"] += cess + def set_reclaim_of_itc_reversal(self): + journal_entry = frappe.qb.DocType("Journal Entry") + journal_entry_account = frappe.qb.DocType("Journal Entry Account") + + reclaimed_entries = ( + frappe.qb.from_(journal_entry) + .join(journal_entry_account) + .on(journal_entry_account.parent == journal_entry.name) + .select( + journal_entry_account.gst_tax_type, + Sum(journal_entry_account.debit_in_account_currency).as_("amount"), + ) + .where(journal_entry.voucher_type == "Reclaim of ITC Reversal") + .where(IfNull(journal_entry_account.gst_tax_type, "") != "") + .groupby(journal_entry_account.gst_tax_type) + ) + reclaimed_entries = self.get_query_with_conditions( + journal_entry, reclaimed_entries, party_gstin="" + ).run(as_dict=True) + + for entry in reclaimed_entries: + tax_amount_key = GST_TAX_TYPE_MAP.get(entry.gst_tax_type) + self.report_dict["itc_elg"]["itc_inelg"][0][tax_amount_key] += entry.amount + def get_inward_nil_exempt(self, state): inward_nil_exempt = frappe.db.sql( """ @@ -360,13 +386,6 @@ def get_invoice_item_wise_tax_details(self, doctype): def set_item_wise_tax_details(self, docs): self.invoice_item_wise_tax_details = {} item_wise_details = {} - gst_tax_type_map = { - "cgst": "camt", - "sgst": "samt", - "igst": "iamt", - "cess": "csamt", - "cess_non_advol": "csamt", - } item_defaults = frappe._dict( { @@ -402,7 +421,7 @@ def set_item_wise_tax_details(self, docs): # Process tax details for tax in details["taxes"]: - gst_tax_type = gst_tax_type_map.get(tax.gst_tax_type) + gst_tax_type = GST_TAX_TYPE_MAP.get(tax.gst_tax_type) if not gst_tax_type: continue @@ -525,7 +544,7 @@ def get_outward_tax_details(self, doctype): def get_reverse_charge_invoice_condition(self, doctype): condition = "" if doctype == "Sales Invoice" and self.reverse_charge_invoices: - condition = f""" and parent not in ({', '.join([f'"{invoice}"' for invoice in self.reverse_charge_invoices])})""" + condition = f""" and parent not in ({", ".join([f'"{invoice}"' for invoice in self.reverse_charge_invoices])})""" return condition diff --git a/india_compliance/gst_india/setup/property_setters.py b/india_compliance/gst_india/setup/property_setters.py index b0be7a4f2d..1f65ee0bee 100644 --- a/india_compliance/gst_india/setup/property_setters.py +++ b/india_compliance/gst_india/setup/property_setters.py @@ -6,7 +6,7 @@ def get_property_setters(*, include_defaults=False): get_options_property_setter( "Journal Entry", "voucher_type", - ["Reversal Of ITC"], + ["Reversal Of ITC", "Reclaim of ITC Reversal"], prepend=False, ), get_options_property_setter( diff --git a/india_compliance/patches.txt b/india_compliance/patches.txt index 8de46b916a..4f275cc0e7 100644 --- a/india_compliance/patches.txt +++ b/india_compliance/patches.txt @@ -3,8 +3,13 @@ execute:import frappe; frappe.delete_doc_if_exists("DocType", "GSTIN") [post_model_sync] india_compliance.patches.v14.set_default_for_overridden_accounts_setting +<<<<<<< HEAD execute:from india_compliance.gst_india.setup import create_custom_fields; create_custom_fields() #58 execute:from india_compliance.gst_india.setup import create_property_setters; create_property_setters() #10 +======= +execute:from india_compliance.gst_india.setup import create_custom_fields; create_custom_fields() #62 +execute:from india_compliance.gst_india.setup import create_property_setters; create_property_setters() #11 +>>>>>>> d28ac00a (fix: allow reclaim of itc through journal entry) execute:from india_compliance.income_tax_india.setup import create_custom_fields; create_custom_fields() #2 india_compliance.patches.post_install.remove_old_fields #2 india_compliance.patches.post_install.set_gst_tax_type From 545e7dd0386ae1f8e3ce6401520043b496dad6ee Mon Sep 17 00:00:00 2001 From: Smit Vora Date: Tue, 4 Mar 2025 06:56:26 +0530 Subject: [PATCH 2/2] chore: resolve conflicts --- india_compliance/patches.txt | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/india_compliance/patches.txt b/india_compliance/patches.txt index 4f275cc0e7..cf50e4dc09 100644 --- a/india_compliance/patches.txt +++ b/india_compliance/patches.txt @@ -3,13 +3,8 @@ execute:import frappe; frappe.delete_doc_if_exists("DocType", "GSTIN") [post_model_sync] india_compliance.patches.v14.set_default_for_overridden_accounts_setting -<<<<<<< HEAD execute:from india_compliance.gst_india.setup import create_custom_fields; create_custom_fields() #58 -execute:from india_compliance.gst_india.setup import create_property_setters; create_property_setters() #10 -======= -execute:from india_compliance.gst_india.setup import create_custom_fields; create_custom_fields() #62 execute:from india_compliance.gst_india.setup import create_property_setters; create_property_setters() #11 ->>>>>>> d28ac00a (fix: allow reclaim of itc through journal entry) execute:from india_compliance.income_tax_india.setup import create_custom_fields; create_custom_fields() #2 india_compliance.patches.post_install.remove_old_fields #2 india_compliance.patches.post_install.set_gst_tax_type @@ -64,4 +59,4 @@ india_compliance.patches.v14.update_total_taxes_for_gst_inward_supply india_compliance.patches.v14.enable_sales_through_ecommerce_operator india_compliance.patches.v14.update_gstin_status_refresh_interval india_compliance.patches.v15.migrate_gstr1_log_to_returns_log -india_compliance.patches.v15.update_action_for_gst_inward_supply \ No newline at end of file +india_compliance.patches.v15.update_action_for_gst_inward_supply