Merge pull request #28065 from Anuja-pawar/gst-category
fix(minor): check if gst_category exists while validating GSTIN
diff --git a/erpnext/regional/india/utils.py b/erpnext/regional/india/utils.py
index 404ab8f..54d592a 100644
--- a/erpnext/regional/india/utils.py
+++ b/erpnext/regional/india/utils.py
@@ -26,12 +26,13 @@
gst_category = []
- if len(doc.links):
- link_doctype = doc.links[0].get("link_doctype")
- link_name = doc.links[0].get("link_name")
+ if hasattr(doc, 'gst_category'):
+ if len(doc.links):
+ link_doctype = doc.links[0].get("link_doctype")
+ link_name = doc.links[0].get("link_name")
- if link_doctype in ["Customer", "Supplier"]:
- gst_category = frappe.db.get_value(link_doctype, {'name': link_name}, ['gst_category'])
+ if link_doctype in ["Customer", "Supplier"]:
+ gst_category = frappe.db.get_value(link_doctype, {'name': link_name}, ['gst_category'])
doc.gstin = doc.gstin.upper().strip()
if not doc.gstin or doc.gstin == 'NA':
@@ -73,12 +74,11 @@
frappe.throw(_("Intra State tax category for GST State {0} already exists").format(doc.gst_state))
def update_gst_category(doc, method):
- for link in doc.links:
- if link.link_doctype in ['Customer', 'Supplier']:
- if doc.get('gstin'):
- frappe.db.sql("""
- UPDATE `tab{0}` SET gst_category = %s WHERE name = %s AND gst_category = 'Unregistered'
- """.format(link.link_doctype), ("Registered Regular", link.link_name)) #nosec
+ if hasattr(doc, 'gst_category'):
+ for link in doc.links:
+ if link.link_doctype in ['Customer', 'Supplier']:
+ if doc.get('gstin'):
+ frappe.db.set_value(link.link_doctype, {'name': link.link_name, 'gst_category': 'Unregistered'}, 'gst_category', 'Registered Regular')
def set_gst_state_and_state_number(doc):
if not doc.gst_state: