Skip to content

Commit

Permalink
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 3 deletions.
1 change: 1 addition & 0 deletions india_compliance/gst_india/api_classes/e_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class EInvoiceAPI(BaseAPI):
# Invalid GSTIN error
"3028": "GSTIN is invalid",
"3029": "GSTIN is not active",
"3001": "Requested data is not available",
}

def setup(self, doc=None, *, company_gstin=None):
Expand Down
11 changes: 11 additions & 0 deletions india_compliance/gst_india/api_classes/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def setup(self):
self.default_headers.update({"requestid": self.generate_request_id()})

def get_gstin_info(self, gstin):
self.gstin = gstin
response = self.get("search", params={"action": "TP", "gstin": gstin})
if self.sandbox_mode:
response.update(
Expand All @@ -33,3 +34,13 @@ def get_returns_info(self, gstin, fy):
return self.get(
"returns", params={"action": "RETTRACK", "gstin": gstin, "fy": fy}
)

def is_ignored_error(self, response_json):
if response_json.get("errorCode") == "FO8000":
response_json.update(
{
"sts": "Invalid",
"gstin": self.gstin,
}
)
return True
2 changes: 1 addition & 1 deletion india_compliance/gst_india/utils/e_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def generate_e_invoice(docname, throw=True, force=False):
)

# Handle Invalid GSTIN Error
if result.error_code in ("3028", "3029"):
if result.error_code in ("3028", "3029", "3001"):
gstin = data.get("BuyerDtls").get("Gstin")
response = api.sync_gstin_info(gstin)

Expand Down
3 changes: 2 additions & 1 deletion india_compliance/gst_india/utils/gstin_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def _get_gstin_info(gstin, *, throw_error=True):
queue="long",
response=get_formatted_response_for_status(response),
)

except Exception as exc:
if isinstance(exc, GSPServerError):
frappe.cache.set_value("gst_server_error", True, expires_in_sec=60)
Expand All @@ -75,7 +76,7 @@ def _get_gstin_info(gstin, *, throw_error=True):

gstin_info = frappe._dict(
gstin=response.gstin,
business_name=titlecase(business_name),
business_name=titlecase(business_name or ""),
gst_category=GST_CATEGORIES.get(response.dty, ""),
status=response.sts,
)
Expand Down
30 changes: 29 additions & 1 deletion india_compliance/gst_india/utils/test_gstin_info.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from unittest.mock import Mock, patch

import responses
from responses import matchers

import frappe
from frappe.tests import IntegrationTestCase
from frappe.tests import IntegrationTestCase, change_settings

from india_compliance.gst_india.utils.gstin_info import get_gstin_info

Expand Down Expand Up @@ -189,3 +192,28 @@ def test_tcs_gstin_info(self):
},
},
)


class TestGstinInvalidInfo(IntegrationTestCase):
@responses.activate
@change_settings("GST Settings", {"validate_gstin_status": 1, "sandbox_mode": 0})
def test_invalid_gstin(self):
gstin = "24AQTPC8950E1ZO"
url = "https://asp.resilient.tech/commonapi/search"

responses.add(
responses.GET,
url,
json={
"errorCode": "FO8000",
"gstin": "24AQTPC8950E1ZO",
"message": "No records found",
"sts": "Invalid",
"success": False,
},
match=[matchers.query_param_matcher({"action": "TP", "gstin": gstin})],
)

gstin_info = get_gstin_info(gstin)
self.assertEqual(gstin_info.status, "Invalid")
self.assertEqual(gstin_info.business_name, "")

0 comments on commit 61e10af

Please sign in to comment.