[Regional BUG India] Error for Company without GST registration

My company is not registered with GST (as turnover is less than 40 Lakh). Till version 12.1 of erpnext, it worked well as I had put ‘NA’ in GSTIN field of my company address. Now after updating to v12.5, it is throwing below error (as copied from browser console) while creating a new invoice.

Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/app.py”, line 60, in application
response = frappe.api.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/api.py”, line 55, in handle
return frappe.handler.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 22, in handle
data = execute_cmd(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 61, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 1051, in call
return fn(*args, **newargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/save.py”, line 22, in savedocs
doc.save()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 273, in save
return self._save(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 296, in _save
self.insert()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 230, in insert
self.run_before_save_methods()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 895, in run_before_save_methods
self.run_method(“validate”)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 794, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1065, in composer
return composed(self, method, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1048, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 788, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.py”, line 74, in validate
super(SalesInvoice, self).validate()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/selling_controller.py”, line 39, in validate
super(SellingController, self).validate()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/stock_controller.py”, line 21, in validate
super(StockController, self).validate()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/accounts_controller.py”, line 68, in validate
self.set_missing_values(for_validate=True)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.py”, line 340, in set_missing_values
super(SalesInvoice, self).set_missing_values(for_validate)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/selling_controller.py”, line 55, in set_missing_values
self.set_missing_lead_customer_details()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/selling_controller.py”, line 84, in set_missing_lead_customer_details
party_address=self.customer_address, shipping_address=self.shipping_address_name)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/party.py”, line 49, in _get_party_details
party_address, shipping_address = set_address_details(party_details, party, party_type, doctype, company, party_address, company_address, shipping_address)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/party.py”, line 104, in set_address_details
get_regional_address_details(party_details, doctype, company)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/init.py”, line 129, in caller
return frappe.get_attr(regional_overrides[region][fn_name])(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/regional/india/utils.py”, line 187, in get_regional_address_details
default_tax = get_tax_template(master_doctype, company, 1, party_details.company_gstin[:2])
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/regional/india/utils.py”, line 217, in get_tax_template
if tax_category.gst_state == number_state_mapping[state_code] or
KeyError: u’NA’

Were you able to resolve this issue, if so please share how were you able to resolve this issue as even I am getting this error even on ERPNext: v12.13.0 (version-12)

There seems to be an error in the code in regional settings:

	for tax_category in tax_categories:
		if tax_category.gst_state == number_state_mapping[state_code] or \
	 		(not default_tax and not tax_category.gst_state):

Basically we are looking for gst_state number from the company address and if the gstin is “NA” in case of unregistered person then this Key ERROR is coming.

Traceback (most recent call last):
  File "/data/v12-bench/apps/frappe/frappe/desk/form/save.py", line 21, in savedocs
    doc.save()
  File "/data/v12-bench/apps/frappe/frappe/model/document.py", line 273, in save
    return self._save(*args, **kwargs)
  File "/data/v12-bench/apps/frappe/frappe/model/document.py", line 296, in _save
    self.insert()
  File "/data/v12-bench/apps/frappe/frappe/model/document.py", line 230, in insert
    self.run_before_save_methods()
  File "/data/v12-bench/apps/frappe/frappe/model/document.py", line 896, in run_before_save_methods
    self.run_method("validate")
  File "/data/v12-bench/apps/frappe/frappe/model/document.py", line 797, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "/data/v12-bench/apps/frappe/frappe/model/document.py", line 1073, in composer
    return composed(self, method, *args, **kwargs)
  File "/data/v12-bench/apps/frappe/frappe/model/document.py", line 1056, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/data/v12-bench/apps/frappe/frappe/model/document.py", line 791, in <lambda>
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
  File "/data/v12-bench/apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.py", line 74, in validate
    super(SalesInvoice, self).validate()
  File "/data/v12-bench/apps/erpnext/erpnext/controllers/selling_controller.py", line 40, in validate
    super(SellingController, self).validate()
  File "/data/v12-bench/apps/erpnext/erpnext/controllers/stock_controller.py", line 21, in validate
    super(StockController, self).validate()
  File "/data/v12-bench/apps/erpnext/erpnext/controllers/accounts_controller.py", line 71, in validate
    self.set_missing_values(for_validate=True)
  File "/data/v12-bench/apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.py", line 340, in set_missing_values
    super(SalesInvoice, self).set_missing_values(for_validate)
  File "/data/v12-bench/apps/erpnext/erpnext/controllers/selling_controller.py", line 57, in set_missing_values
    self.set_missing_lead_customer_details(for_validate=for_validate)
  File "/data/v12-bench/apps/erpnext/erpnext/controllers/selling_controller.py", line 82, in set_missing_lead_customer_details
    party_details = _get_party_details(customer,
  File "/data/v12-bench/apps/erpnext/erpnext/accounts/party.py", line 49, in _get_party_details
    party_address, shipping_address = set_address_details(party_details, party, party_type, doctype, company, party_address, company_address, shipping_address)
  File "/data/v12-bench/apps/erpnext/erpnext/accounts/party.py", line 104, in set_address_details
    get_regional_address_details(party_details, doctype, company)
  File "/data/v12-bench/apps/erpnext/erpnext/__init__.py", line 129, in caller
    return frappe.get_attr(regional_overrides[region][fn_name])(*args, **kwargs)
  File "/data/v12-bench/apps/erpnext/erpnext/regional/india/utils.py", line 190, in get_regional_address_details
    default_tax = get_tax_template(master_doctype, company, 1, party_details.company_gstin[:2])
  File "/data/v12-bench/apps/erpnext/erpnext/regional/india/utils.py", line 221, in get_tax_template
    if tax_category.gst_state == number_state_mapping[state_code] or \
KeyError: 'NA'

request.js:355 Traceback (most recent call last):
  File "/data/v12-bench/apps/frappe/frappe/app.py", line 64, in application
    response = frappe.api.handle()
  File "/data/v12-bench/apps/frappe/frappe/api.py", line 59, in handle
    return frappe.handler.handle()
  File "/data/v12-bench/apps/frappe/frappe/handler.py", line 24, in handle
    data = execute_cmd(cmd)
  File "/data/v12-bench/apps/frappe/frappe/handler.py", line 64, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/data/v12-bench/apps/frappe/frappe/__init__.py", line 1064, in call
    return fn(*args, **newargs)
  File "/data/v12-bench/apps/frappe/frappe/desk/form/save.py", line 21, in savedocs
    doc.save()
  File "/data/v12-bench/apps/frappe/frappe/model/document.py", line 273, in save
    return self._save(*args, **kwargs)
  File "/data/v12-bench/apps/frappe/frappe/model/document.py", line 296, in _save
    self.insert()
  File "/data/v12-bench/apps/frappe/frappe/model/document.py", line 230, in insert
    self.run_before_save_methods()
  File "/data/v12-bench/apps/frappe/frappe/model/document.py", line 896, in run_before_save_methods
    self.run_method("validate")
  File "/data/v12-bench/apps/frappe/frappe/model/document.py", line 797, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "/data/v12-bench/apps/frappe/frappe/model/document.py", line 1073, in composer
    return composed(self, method, *args, **kwargs)
  File "/data/v12-bench/apps/frappe/frappe/model/document.py", line 1056, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/data/v12-bench/apps/frappe/frappe/model/document.py", line 791, in <lambda>
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
  File "/data/v12-bench/apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.py", line 74, in validate
    super(SalesInvoice, self).validate()
  File "/data/v12-bench/apps/erpnext/erpnext/controllers/selling_controller.py", line 40, in validate
    super(SellingController, self).validate()
  File "/data/v12-bench/apps/erpnext/erpnext/controllers/stock_controller.py", line 21, in validate
    super(StockController, self).validate()
  File "/data/v12-bench/apps/erpnext/erpnext/controllers/accounts_controller.py", line 71, in validate
    self.set_missing_values(for_validate=True)
  File "/data/v12-bench/apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.py", line 340, in set_missing_values
    super(SalesInvoice, self).set_missing_values(for_validate)
  File "/data/v12-bench/apps/erpnext/erpnext/controllers/selling_controller.py", line 57, in set_missing_values
    self.set_missing_lead_customer_details(for_validate=for_validate)
  File "/data/v12-bench/apps/erpnext/erpnext/controllers/selling_controller.py", line 82, in set_missing_lead_customer_details
    party_details = _get_party_details(customer,
  File "/data/v12-bench/apps/erpnext/erpnext/accounts/party.py", line 49, in _get_party_details
    party_address, shipping_address = set_address_details(party_details, party, party_type, doctype, company, party_address, company_address, shipping_address)
  File "/data/v12-bench/apps/erpnext/erpnext/accounts/party.py", line 104, in set_address_details
    get_regional_address_details(party_details, doctype, company)
  File "/data/v12-bench/apps/erpnext/erpnext/__init__.py", line 129, in caller
    return frappe.get_attr(regional_overrides[region][fn_name])(*args, **kwargs)
  File "/data/v12-bench/apps/erpnext/erpnext/regional/india/utils.py", line 190, in get_regional_address_details
    default_tax = get_tax_template(master_doctype, company, 1, party_details.company_gstin[:2])
  File "/data/v12-bench/apps/erpnext/erpnext/regional/india/utils.py", line 221, in get_tax_template
    if tax_category.gst_state == number_state_mapping[state_code] or \
KeyError: 'NA'