blob: c4acafc944fc74053d3c61adab4e7ce7d9406344 [file] [log] [blame]
Rushabh Mehtab3c8f442017-06-21 17:22:38 +05301import frappe, re
2from frappe import _
3from erpnext.regional.india import states, state_numbers
4
5def validate_gstin_for_india(doc, method):
6 if not hasattr(doc, 'gstin'):
7 return
8
9 if doc.gstin:
Aditya Duggalf1bd39c2017-06-29 14:25:19 +053010 if doc.gstin != "NA":
11 p = re.compile("[0-9]{2}[a-zA-Z]{5}[0-9]{4}[a-zA-Z]{1}[1-9A-Za-z]{1}[Z]{1}[0-9a-zA-Z]{1}")
12 if not p.match(doc.gstin):
13 frappe.throw(_("Invalid GSTIN or Enter NA for Unregistered"))
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053014
15 if not doc.gst_state:
16 if doc.state in states:
17 doc.gst_state = doc.state
18
Nabin Hait852cb642017-07-05 12:58:19 +053019 if doc.gst_state:
20 state_number = state_numbers[doc.gst_state]
21 if state_number != doc.gstin[:2]:
22 frappe.throw(_("First 2 digits of GSTIN should match with State number {0}").format(state_number))