Skip to content

Commit

Permalink
fix: use existing utility
Browse files Browse the repository at this point in the history
(cherry picked from commit 94434a4)
  • Loading branch information
Ninad1306 authored and mergify[bot] committed Sep 12, 2024
1 parent cd4bef5 commit 8bbabee
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions india_compliance/gst_india/client_scripts/purchase_invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ frappe.ui.form.on(DOCTYPE, {
onload: toggle_reverse_charge,

gst_category(frm) {
toggle_reverse_charge(frm);
validate_gst_hsn_code(frm);
toggle_reverse_charge(frm);
},

after_save(frm) {
Expand Down Expand Up @@ -94,8 +94,8 @@ frappe.ui.form.on(DOCTYPE, {

frappe.ui.form.on("Purchase Invoice Item", {
item_code(frm) {
toggle_reverse_charge(frm);
validate_gst_hsn_code(frm);
toggle_reverse_charge(frm);
},

items_remove: toggle_reverse_charge,
Expand Down
15 changes: 10 additions & 5 deletions india_compliance/gst_india/overrides/purchase_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from india_compliance.gst_india.overrides.sales_invoice import (
update_dashboard_with_gst_logs,
)
from india_compliance.gst_india.overrides.transaction import (
validate_hsn_codes as _validate_hsn_codes,
)
from india_compliance.gst_india.overrides.transaction import validate_transaction
from india_compliance.gst_india.utils import is_api_enabled
from india_compliance.gst_india.utils.e_waybill import get_e_waybill_info
Expand Down Expand Up @@ -43,7 +46,7 @@ def validate(doc, method=None):
if validate_transaction(doc) is False:
return

validate_gst_hsn_code(doc)
validate_hsn_codes(doc)
set_ineligibility_reason(doc)
update_itc_totals(doc)
validate_supplier_invoice_number(doc)
Expand Down Expand Up @@ -265,10 +268,12 @@ def validate_reverse_charge(doc):
frappe.throw(_("Reverse Charge is not applicable on Import of Goods"))


def validate_gst_hsn_code(doc):
def validate_hsn_codes(doc):
if doc.gst_category != "Overseas":
return

for item in doc.items:
if not item.get("gst_hsn_code"):
frappe.throw(_("GST HSN Code is mandatory for Overseas Purchase Invoice"))
_validate_hsn_codes(
doc,
throw=True,
message="GST HSN Code is mandatory for Overseas Purchase Invoice.<br>",
)
8 changes: 5 additions & 3 deletions india_compliance/gst_india/overrides/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,13 +721,13 @@ def validate_backdated_transaction(doc, gst_settings=None, action="create"):
)


def validate_hsn_codes(doc):
def validate_hsn_codes(doc, throw=False, message=None):
validate_hsn_code, valid_hsn_length = get_hsn_settings()

if not validate_hsn_code:
return

return _validate_hsn_codes(doc, valid_hsn_length, message=None)
return _validate_hsn_codes(doc, valid_hsn_length, throw, message)


def validate_sales_reverse_charge(doc):
Expand All @@ -740,7 +740,7 @@ def validate_sales_reverse_charge(doc):
)


def _validate_hsn_codes(doc, valid_hsn_length, message=None):
def _validate_hsn_codes(doc, valid_hsn_length, throw=False, message=None):
rows_with_missing_hsn = []
rows_with_invalid_hsn = []

Expand Down Expand Up @@ -773,6 +773,7 @@ def _validate_hsn_codes(doc, valid_hsn_length, message=None):
"{0}" "Please enter HSN/SAC code for the following row numbers: <br>{1}"
).format(message or "", frappe.bold(", ".join(rows_with_missing_hsn))),
title=_("Invalid HSN/SAC"),
raise_exception=throw,
)

if rows_with_invalid_hsn:
Expand All @@ -787,6 +788,7 @@ def _validate_hsn_codes(doc, valid_hsn_length, message=None):
frappe.bold(", ".join(rows_with_invalid_hsn)),
),
title=_("Invalid HSN/SAC"),
raise_exception=throw,
)


Expand Down

0 comments on commit 8bbabee

Please sign in to comment.