blob: 26c579448dccc9950ef67cf9e172e10746946573 [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:
10 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}")
11 if not p.match(doc.gstin):
12 frappe.throw(_("Invalid GSTIN"))
13
14 if not doc.gst_state:
15 if doc.state in states:
16 doc.gst_state = doc.state
17
18 if doc.gst_state:
19 state_number = state_numbers[doc.gst_state]
20 if state_number != doc.gstin[:2]:
21 frappe.throw(_("First 2 digits of GSTIN should match with State number {0}").format(state_number))