Skip to content

Commit

Permalink
fix: allow reclaim of itc through journal entry
Browse files Browse the repository at this point in the history
(cherry picked from commit d28ac00)
  • Loading branch information
Ninad1306 authored and mergify[bot] committed Mar 3, 2025
1 parent 4c69937 commit 468bb11
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 23 deletions.
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 @@ -20,6 +20,13 @@
from india_compliance.gst_india.utils import get_period

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 @@ -58,6 +65,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 @@ -207,24 +215,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 @@ -304,6 +306,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 @@ -393,13 +419,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 @@ -435,7 +454,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 @@ -562,7 +581,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
2 changes: 1 addition & 1 deletion india_compliance/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ india_compliance.patches.v15.remove_duplicate_web_template
[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() #62
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

0 comments on commit 468bb11

Please sign in to comment.