Skip to content

Commit

Permalink
fix: ITC Classification Refactor for GST Purchase Register Report (#2557
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninad1306 authored and mergify[bot] committed Aug 29, 2024
1 parent e325d23 commit 6eb2fc4
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 18 deletions.
20 changes: 20 additions & 0 deletions india_compliance/gst_india/client_scripts/purchase_invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ frappe.ui.form.on(DOCTYPE, {
});
},

onload: toggle_reverse_charge,

gst_category: toggle_reverse_charge,

after_save(frm) {
if (
frm.doc.supplier_address ||
Expand Down Expand Up @@ -84,3 +88,19 @@ frappe.ui.form.on(DOCTYPE, {
}, 2000);
},
});

frappe.ui.form.on("Purchase Invoice Item", {
item_code: toggle_reverse_charge,

items_remove: toggle_reverse_charge,
});

function toggle_reverse_charge(frm) {
let is_read_only = 0;
if (frm.doc.gst_category !== "Overseas") is_read_only = 0;
// has_goods_item
else if (frm.doc.items.some(item => !item.gst_hsn_code.startsWith("99")))
is_read_only = 1;

frm.set_df_property("is_reverse_charge", "read_only", is_read_only);
}
1 change: 1 addition & 0 deletions india_compliance/gst_india/constants/custom_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,7 @@
),
"default": "All Other ITC",
"translatable": 0,
"read_only": 1,
},
{
"fieldname": "ineligibility_reason",
Expand Down
31 changes: 21 additions & 10 deletions india_compliance/gst_india/overrides/purchase_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def is_b2b_invoice(doc):
def update_itc_totals(doc, method=None):
# Set default value
set_itc_classification(doc)
validate_reverse_charge(doc)

# Initialize values
doc.itc_integrated_tax = 0
Expand All @@ -111,19 +112,22 @@ def update_itc_totals(doc, method=None):


def set_itc_classification(doc):
default_classification = "All Other ITC"
reverse_charge_classification = "ITC on Reverse Charge"
if doc.gst_category == "Overseas":
for item in doc.items:
if not item.gst_hsn_code.startswith("99"):
doc.itc_classification = "Import Of Goods"
break
else:
doc.itc_classification = "Import Of Service"

if doc.is_reverse_charge:
doc.itc_classification = reverse_charge_classification
return
elif doc.is_reverse_charge:
doc.itc_classification = "ITC on Reverse Charge"

elif doc.itc_classification == reverse_charge_classification:
doc.itc_classification = default_classification
return
elif doc.gst_category == "Input Service Distributor" and doc.is_internal_transfer():
doc.itc_classification = "Input Service Distributor"

if not doc.itc_classification:
doc.itc_classification = default_classification
else:
doc.itc_classification = "All Other ITC"


def validate_supplier_invoice_number(doc):
Expand Down Expand Up @@ -252,3 +256,10 @@ def set_ineligibility_reason(doc, show_alert=True):
alert=True,
indicator="orange",
)


def validate_reverse_charge(doc):
if doc.itc_classification != "Import Of Goods" or not doc.is_reverse_charge:
return

frappe.throw(_("Reverse Charge is not applicable on Import of Goods"))
60 changes: 60 additions & 0 deletions india_compliance/gst_india/overrides/test_purchase_invoice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import frappe
from frappe.tests.utils import FrappeTestCase, change_settings
from erpnext.accounts.doctype.account.test_account import create_account

from india_compliance.gst_india.utils.tests import append_item, create_purchase_invoice


class TestPurchaseInvoice(FrappeTestCase):
@change_settings("GST Settings", {"enable_overseas_transactions": 1})
def test_itc_classification(self):
pinv = create_purchase_invoice(
supplier="_Test Foreign Supplier",
do_not_submit=1,
item_code="_Test Service Item",
)
self.assertEqual(pinv.itc_classification, "Import Of Service")

append_item(pinv)
pinv.save()
self.assertEqual(pinv.itc_classification, "Import Of Goods")

pinv = create_purchase_invoice(
supplier="_Test Registered Supplier",
is_reverse_charge=1,
do_not_submit=1,
)
self.assertEqual(pinv.itc_classification, "ITC on Reverse Charge")

pinv.is_reverse_charge = 0
pinv.save()
self.assertEqual(pinv.itc_classification, "All Other ITC")

company = "_Test Indian Registered Company"
account = create_account(
account_name="Unrealized Profit",
parent_account="Current Assets - _TIRC",
company=company,
)

frappe.db.set_value(
"Company", company, "unrealized_profit_loss_account", account
)
pinv = create_purchase_invoice(
supplier="Test Internal with ISD Supplier",
qty=-1,
is_return=1,
)
self.assertEqual(pinv.itc_classification, "Input Service Distributor")

pinv = create_purchase_invoice(
supplier="_Test Foreign Supplier",
do_not_save=1,
is_reverse_charge=1,
)

self.assertRaisesRegex(
frappe.exceptions.ValidationError,
"Reverse Charge is not applicable on Import of Goods",
pinv.save,
)
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def get_itc_from_boe(self):
).as_("csamt"),
LiteralValue(0).as_("camt"),
LiteralValue(0).as_("samt"),
ConstantColumn("Import of Goods").as_("itc_classification"),
ConstantColumn("Import Of Goods").as_("itc_classification"),
)
.where(
(boe.docstatus == 1)
Expand Down
6 changes: 0 additions & 6 deletions india_compliance/gst_india/utils/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ def create_transaction(**data):
if not transaction.supplier:
transaction.supplier = "_Test Registered Supplier"

if (
transaction.doctype == "Purchase Invoice"
and not transaction.itc_classification
):
transaction.itc_classification = "All Other ITC"

if transaction.doctype == "POS Invoice":
transaction.append(
"payments",
Expand Down
2 changes: 1 addition & 1 deletion india_compliance/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,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() #56
execute:from india_compliance.gst_india.setup import create_custom_fields; create_custom_fields() #57
execute:from india_compliance.gst_india.setup import create_property_setters; create_property_setters() #8
execute:from india_compliance.income_tax_india.setup import create_custom_fields; create_custom_fields() #1
india_compliance.patches.post_install.remove_old_fields #2
Expand Down
14 changes: 14 additions & 0 deletions india_compliance/tests/test_records.json
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,20 @@
"gstin": "05AAACG2140A1ZL",
"gst_category": "Registered Regular",
"is_transporter": 1
},
{
"supplier_name": "Test Internal with ISD Supplier",
"name": "Test Internal with ISD Supplier",
"supplier_type": "Company",
"gstin": "24AABCR6898M1ZN",
"gst_category": "Input Service Distributor",
"is_internal_supplier": 1,
"represents_company": "_Test Indian Registered Company",
"companies": [
{
"company": "_Test Indian Registered Company"
}
]
}
],
"Address": [
Expand Down

0 comments on commit 6eb2fc4

Please sign in to comment.