Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow Reclaim of ITC Reversal (backport #3115) #3119

Merged
merged 2 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ <h5>4. &nbsp {{__("Eligible ITC")}}</h5>
<td></td>
</tr>
<tr>
<td>&nbsp (1) {{__("As per rules 42 & 43 of CGST Rules and section 17(5)")}}</td>
<td>&nbsp (1) {{__("As per rules 38,42 & 43 of CGST Rules and section 17(5)")}}</td>
<td class="right">{{ flt(data.itc_elg.itc_rev[0].iamt, 2) }}</td>
<td class="right">{{ flt(data.itc_elg.itc_rev[0].camt, 2) }}</td>
<td class="right">{{ flt(data.itc_elg.itc_rev[0].samt, 2) }}</td>
Expand All @@ -270,14 +270,14 @@ <h5>4. &nbsp {{__("Eligible ITC")}}</h5>
<td class="right">{{ flt(data.itc_elg.itc_rev[1].csamt, 2) }}</td>
</tr>
<tr>
<td><b>(C) {{__("Net ITC Available(A) - (B)")}}</b></td>
<td><b>(C) {{__("Net ITC Available (A) - (B)")}}</b></td>
<td class="right">{{ flt(data.itc_elg.itc_net.iamt, 2) }}</td>
<td class="right">{{ flt(data.itc_elg.itc_net.camt, 2) }}</td>
<td class="right">{{ flt(data.itc_elg.itc_net.samt, 2) }}</td>
<td class="right">{{ flt(data.itc_elg.itc_net.csamt, 2) }}</td>
</tr>
<tr>
<td><b>(D) {{__("Ineligible ITC")}}</b></td>
<td><b>(D) {{__("Other Details")}}</b></td>
<td></td>
<td></td>
<td></td>
Expand Down Expand Up @@ -311,7 +311,7 @@ <h5>5. &nbsp&nbsp {{__("Values of exempt, nil rated and non-GST inward supplies"
</thead>
<tbody>
<tr>
<td>{{__("From a supplier under composition scheme, Exempt and Nil rated")}}</td>
<td>{{__("From a supplier under composition scheme, Exempt and Nil rated supply")}}</td>
<td class="right">{{ flt(data.inward_sup.isup_details[0].inter, 2) }}</td>
<td class="right">{{ flt(data.inward_sup.isup_details[0].intra, 2) }}</td>
</tr>
Expand Down
53 changes: 36 additions & 17 deletions india_compliance/gst_india/doctype/gstr_3b_report/gstr_3b_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -195,24 +203,18 @@ 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":
index = 0
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):
Expand Down Expand Up @@ -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(
"""
Expand Down Expand Up @@ -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(
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion india_compliance/gst_india/setup/property_setters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions india_compliance/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ execute:import frappe; frappe.delete_doc_if_exists("DocType", "GSTIN")
[post_model_sync]
india_compliance.patches.v14.set_default_for_overridden_accounts_setting
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_property_setters; create_property_setters() #11
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
Expand Down Expand Up @@ -59,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
india_compliance.patches.v15.update_action_for_gst_inward_supply