Skip to content

Commit

Permalink
fix: otp handeling for gstr-1 with newer method
Browse files Browse the repository at this point in the history
(cherry picked from commit 3dd82ba)
  • Loading branch information
vorasmit authored and mergify[bot] committed Sep 11, 2024
1 parent 271ea9b commit c000cc8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 42 deletions.
2 changes: 1 addition & 1 deletion india_compliance/gst_india/api_classes/taxpayer_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class TaxpayerAuthenticate(BaseAPI):
IGNORED_ERROR_CODES = {
"RETOTPREQUEST": "otp_requested",
"EVCREQUEST": "otp_requested",
"AUTH158": "invalid_otp", # Invalid OTP
"AUTH158": "authorization_failed", # GSTR1
"AUTH4033": "invalid_otp", # Invalid Session
# "AUTH4034": "invalid_otp", # Invalid OTP
"AUTH4038": "authorization_failed", # Session Expired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
GSTR1BooksData,
summarize_retsum_data,
)
from india_compliance.gst_india.utils.gstr_utils import request_otp


class SummarizeGSTR1:
Expand Down Expand Up @@ -513,15 +512,6 @@ def generate_gstr1_data(self, filters, callback=None):
# Get Data
gov_data, is_enqueued = self.get_gov_gstr1_data()

if error_type := gov_data.get("error_type"):
# otp_requested, invalid_otp

if error_type == "invalid_otp":
request_otp(filters.company_gstin)

data = "otp_requested"
return callback and callback(data, filters)

books_data = self.get_books_gstr1_data(filters)

if is_enqueued:
Expand Down
20 changes: 4 additions & 16 deletions india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ frappe.ui.form.on(DOCTYPE, {
// Primary Action
frm.disable_save();
frm.page.set_primary_action(__("Generate"), () =>
frm.call("generate_gstr1")
frm.taxpayer_api_call("generate_gstr1")
);

// After indicator set in frappe refresh
Expand All @@ -205,18 +205,6 @@ frappe.ui.form.on(DOCTYPE, {

load_gstr1_data(frm) {
const data = frm.doc.__gst_data;
if (!frm._otp_requested && data == "otp_requested") {
frm._otp_requested = true;

india_compliance
.authenticate_otp(frm.doc.company_gstin)
.then(() => frm.call("generate_gstr1"));

return;
}

frm._otp_requested = false;

if (!data?.status) return;

// Toggle HTML fields
Expand Down Expand Up @@ -1522,7 +1510,7 @@ class BooksTab extends GSTR1_TabManager {

recompute_books() {
render_empty_state(this.instance.frm);
this.instance.frm.call("recompute_books");
this.instance.frm.taxpayer_api_call("recompute_books");
}

// COLUMNS
Expand Down Expand Up @@ -1733,7 +1721,7 @@ class FiledTab extends GSTR1_TabManager {

sync_with_gstn(sync_for) {
render_empty_state(this.instance.frm);
this.instance.frm.call("sync_with_gstn", { sync_for });
this.instance.frm.taxpayer_api_call("sync_with_gstn", { sync_for });
}

download_filed_json() {
Expand Down Expand Up @@ -1809,7 +1797,7 @@ class FiledTab extends GSTR1_TabManager {
mark_as_filed() {
render_empty_state(this.instance.frm);
this.instance.frm
.call("mark_as_filed")
.taxpayer_api_call("mark_as_filed")
.then(() => this.instance.frm.trigger("load_gstr1_data"));
}

Expand Down
23 changes: 11 additions & 12 deletions india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,23 @@
from frappe.query_builder.functions import Date, Sum
from frappe.utils import get_last_day, getdate

from india_compliance.gst_india.api_classes.taxpayer_base import (
TaxpayerBaseAPI,
otp_handler,
)
from india_compliance.gst_india.utils import get_gst_accounts_by_type
from india_compliance.gst_india.utils.gstin_info import get_gstr_1_return_status
from india_compliance.gst_india.utils.gstr_utils import request_otp


class GSTR1Beta(Document):

@frappe.whitelist()
def recompute_books(self):
self.generate_gstr1(recompute_books=True)
return self.generate_gstr1(recompute_books=True)

@frappe.whitelist()
def sync_with_gstn(self, sync_for):
self.generate_gstr1(sync_for=sync_for, recompute_books=True)
return self.generate_gstr1(sync_for=sync_for, recompute_books=True)

@frappe.whitelist()
def mark_as_filed(self):
Expand All @@ -44,9 +47,10 @@ def mark_as_filed(self):
return_status,
)

self.generate_gstr1()
return self.generate_gstr1()

@frappe.whitelist()
@otp_handler
def generate_gstr1(self, sync_for=None, recompute_books=False):
period = get_period(self.month_or_quarter, self.year)

Expand Down Expand Up @@ -100,14 +104,9 @@ def generate_gstr1(self, sync_for=None, recompute_books=False):
self.on_generate(data)
return

# request OTP
if gstr1_log.is_sek_needed(settings) and not settings.is_sek_valid(
self.company_gstin
):
request_otp(self.company_gstin)
data = "otp_requested"
self.on_generate(data)
return
# validate auth token
if gstr1_log.is_sek_needed(settings):
TaxpayerBaseAPI(self.company_gstin).validate_auth_token()

self.gstr1_log = gstr1_log

Expand Down
3 changes: 0 additions & 3 deletions india_compliance/gst_india/utils/gstr_1/gstr_1_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ def download_gstr1_json_data(gstr1_log):
for action in actions:
response = api.get_gstr_1_data(action, return_period)

if response.error_type in ["otp_requested", "invalid_otp"]:
return response, None

if response.error_type == "no_docs_found":
continue

Expand Down

0 comments on commit c000cc8

Please sign in to comment.