Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert: GST Transporter ID API validation (refactor and fixes required) #2080

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1162,9 +1162,11 @@ async function update_gst_tranporter_id(dialog) {
}

function set_gst_transporter_id_status(dialog) {
const gst_transporter_id_field = dialog.get_field("gst_transporter_id");
return;
// TODO: Refactor
// const gst_transporter_id_field = dialog.get_field("gst_transporter_id");

india_compliance.set_gstin_status(gst_transporter_id_field);
// india_compliance.set_gstin_status(gst_transporter_id_field);
}

function update_generation_dialog(dialog, doc) {
Expand Down
19 changes: 10 additions & 9 deletions india_compliance/gst_india/client_scripts/supplier.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ frappe.ui.form.on(DOCTYPE, {
frm.set_value("gst_transporter_id", frm.doc.gstin);
},

gst_transporter_id(frm) {
if (
!frm.doc.gst_transporter_id ||
frm.doc.gst_transporter_id.length < 15
)
return;
// TODO: Refactor
// gst_transporter_id(frm) {
// if (
// !frm.doc.gst_transporter_id ||
// frm.doc.gst_transporter_id.length < 15
// )
// return;

gst_transporter_id_field = frm.get_field("gst_transporter_id");
india_compliance.set_gstin_status(gst_transporter_id_field);
},
// gst_transporter_id_field = frm.get_field("gst_transporter_id");
// india_compliance.set_gstin_status(gst_transporter_id_field);
// },
});
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@
},
{
"default": "1",
"description": "Ensures valid GSTIN and GST Transporter ID in transactions by refreshing status periodically from government database",
"description": "Ensures valid GSTIN in transactions by refreshing status periodically from government database",
"fieldname": "validate_gstin_status",
"fieldtype": "Check",
"label": "Refresh and Validate GSTIN Status in Transactions"
Expand Down
80 changes: 40 additions & 40 deletions india_compliance/gst_india/doctype/gstin/test_gstin.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
# Copyright (c) 2023, Resilient Tech and Contributors
# See license.txt
import re
# import re

import frappe
from frappe.tests.utils import FrappeTestCase, change_settings
from frappe.utils import now
# import frappe
# from frappe.tests.utils import FrappeTestCase, change_settings
# from frappe.utils import now

from india_compliance.gst_india.utils.tests import create_transaction
# from india_compliance.gst_india.utils.tests import create_transaction

# TODO: Uncomment after GST Transporter ID validation is fixed
# class TestGSTIN(FrappeTestCase):
# @change_settings("GST Settings", {"validate_gstin_status": 1, "sandbox_mode": 0})
# def test_validate_gst_transporter_id_info(self):
# # customer gstin
# frappe.get_doc(
# {
# "doctype": "GSTIN",
# "gstin": "24AANFA2641L1ZF",
# "registration_date": "2021-01-01",
# "status": "Active",
# "last_updated_on": now(),
# }
# ).insert(ignore_if_duplicate=True)

class TestGSTIN(FrappeTestCase):
@change_settings("GST Settings", {"validate_gstin_status": 1, "sandbox_mode": 0})
def test_validate_gst_transporter_id_info(self):
# customer gstin
frappe.get_doc(
{
"doctype": "GSTIN",
"gstin": "24AANFA2641L1ZF",
"registration_date": "2021-01-01",
"status": "Active",
"last_updated_on": now(),
}
).insert(ignore_if_duplicate=True)
# # gst transporter id
# frappe.get_doc(
# {
# "doctype": "GSTIN",
# "gstin": "88AABCM9407D1ZS",
# "status": "Invalid",
# "last_updated_on": now(),
# }
# ).insert(ignore_if_duplicate=True)

# gst transporter id
frappe.get_doc(
{
"doctype": "GSTIN",
"gstin": "88AABCM9407D1ZS",
"status": "Invalid",
"last_updated_on": now(),
}
).insert(ignore_if_duplicate=True)
# si = create_transaction(
# doctype="Sales Invoice",
# gst_transporter_id="88AABCM9407D1ZS",
# do_not_save=True,
# )

si = create_transaction(
doctype="Sales Invoice",
gst_transporter_id="88AABCM9407D1ZS",
do_not_save=True,
)

self.assertRaisesRegex(
frappe.ValidationError,
re.compile(
r"^(.*is not Active. Please make sure that transporter ID is valid.*)$"
),
si.save,
)
# self.assertRaisesRegex(
# frappe.ValidationError,
# re.compile(
# r"^(.*is not Active. Please make sure that transporter ID is valid.*)$"
# ),
# si.save,
# )
18 changes: 9 additions & 9 deletions india_compliance/gst_india/overrides/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
STATE_NUMBERS,
)
from india_compliance.gst_india.constants.custom_fields import E_WAYBILL_INV_FIELDS
from india_compliance.gst_india.doctype.gstin.gstin import (
_validate_gst_transporter_id_info,
from india_compliance.gst_india.doctype.gstin.gstin import ( # _validate_gst_transporter_id_info,
_validate_gstin_info,
get_gstin_status,
)
Expand Down Expand Up @@ -1289,23 +1288,24 @@ def validate_gstin_status(gstin, transaction_date):


def validate_gst_transporter_id(doc):
# TODO: Refactor
if not doc.get("gst_transporter_id"):
return

settings = frappe.get_cached_doc("GST Settings")
if not settings.validate_gstin_status:
return
# settings = frappe.get_cached_doc("GST Settings")
# if not settings.validate_gstin_status:
# return

doc.gst_transporter_id = validate_gstin(
doc.gst_transporter_id, label="GST Transporter ID", is_transporter_id=True
)

gstin_doc = get_gstin_status(doc.gst_transporter_id)
# gstin_doc = get_gstin_status(doc.gst_transporter_id)

if not gstin_doc:
return
# if not gstin_doc:
# return

_validate_gst_transporter_id_info(gstin_doc, throw=True)
# _validate_gst_transporter_id_info(gstin_doc, throw=True)


def validate_company_address_field(doc):
Expand Down
2 changes: 1 addition & 1 deletion india_compliance/gst_india/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def validate_gstin(
title=_("Invalid {0}").format(label),
)

if not (is_transporter_id and gstin.startswith("88")):
if not is_transporter_id:
validate_gstin_check_digit(gstin, label)

if is_tcs_gstin and not TCS.match(gstin):
Expand Down
8 changes: 4 additions & 4 deletions india_compliance/public/js/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ function set_and_validate_gstin_status(doctype) {
[gstin_field_name](frm) {
_set_and_validate_gstin_status(frm, gstin_field_name);
},

gst_transporter_id(frm) {
_set_and_validate_gstin_status(frm, "gst_transporter_id");
},
// TODO: Refactor
// gst_transporter_id(frm) {
// _set_and_validate_gstin_status(frm, "gst_transporter_id");
// },

posting_date(frm) {
if (frm.get_field("posting_date"))
Expand Down