blob: 62de7a9897e339a14fbb3fa9e10b253d7587555c [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:
Nabin Haitf3f0dfe2017-07-06 14:49:34 +053010 doc.gstin = doc.gstin.upper()
Aditya Duggalf1bd39c2017-06-29 14:25:19 +053011 if doc.gstin != "NA":
12 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}")
13 if not p.match(doc.gstin):
14 frappe.throw(_("Invalid GSTIN or Enter NA for Unregistered"))
Rushabh Mehtab3c8f442017-06-21 17:22:38 +053015
16 if not doc.gst_state:
17 if doc.state in states:
18 doc.gst_state = doc.state
19
Nabin Hait852cb642017-07-05 12:58:19 +053020 if doc.gst_state:
Nabin Haitf3f0dfe2017-07-06 14:49:34 +053021 doc.gst_state_number = state_numbers[doc.gst_state]
22 if doc.gst_state_number != doc.gstin[:2]:
23 frappe.throw(_("First 2 digits of GSTIN should match with State number {0}")
24 .format(doc.gst_state_number))