From aa026239d2c11bda03d955631692471fda53a6ec Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Fri, 27 Dec 2024 11:24:20 +0530 Subject: [PATCH] refactor: reduce nested if and simplify return message --- .../doctype/gst_return_log/generate_gstr_1.py | 4 +--- .../doctype/gstr_1_beta/gstr_1_beta.js | 22 ++++++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/india_compliance/gst_india/doctype/gst_return_log/generate_gstr_1.py b/india_compliance/gst_india/doctype/gst_return_log/generate_gstr_1.py index 53062baad..147c4af50 100644 --- a/india_compliance/gst_india/doctype/gst_return_log/generate_gstr_1.py +++ b/india_compliance/gst_india/doctype/gst_return_log/generate_gstr_1.py @@ -762,9 +762,7 @@ def upload_gstr1(self, json_data, is_nil_return, force): ), indicator="red", ) - return - - return "upload nil return gstr1" + return "nil_return_for_gstr1" # upload data after proceed to file self.db_set({"filing_status": "Not Filed"}) diff --git a/india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.js b/india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.js index 64eac03f5..e2c34d160 100644 --- a/india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.js +++ b/india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.js @@ -170,6 +170,7 @@ frappe.ui.form.on(DOCTYPE, { frm.taxpayer_api_call("generate_gstr1").then(r => { frm.doc.__gst_data = r.message; frm.trigger("load_gstr1_data"); + frm.gstr1.gstr1_action?.check_for_nil_return(); }); }); }, @@ -2564,19 +2565,20 @@ class GSTR1Action extends FileGSTR1Dialog { if (!r.message) return; this.frm.doc.__gst_data = r.message; this.frm.trigger("load_gstr1_data"); + this.check_for_nil_return(); if (!r.message.pending_actions) return; r.message.pending_actions.forEach(request_type => this.check_action_status_with_retry(request_type, 0, true) ); - - this.check_for_nil_return(); }); } check_for_nil_return() { const data = this.frm.doc.__gst_data; + if(!data || !is_gstr1_api_enabled()) return; + if (Object.keys(data.unfiled).length == 1 && data.status == "Not Filed") { this.frm.set_df_property("file_nil_gstr1", "hidden", 0) } @@ -2588,20 +2590,20 @@ class GSTR1Action extends FileGSTR1Dialog { const upload = () => { this.perform_gstr1_action(action, response => { + if(response.message != "nil_return_for_gstr1"){ + frappe.show_alert(__("Uploading data to GSTN")); + this.check_action_status_with_retry(action); + return; + } + // No data to upload if(response._server_messages){ this.frm.scroll_to_field("file_nil_gstr1"); this.toggle_actions(true); return; } - if (response.message == "upload nil reated gstr1"){ - frappe.show_alert(__("Proceeding to file Nil Rated GSTR-1")); - this.proceed_to_file(); - return; - } - - frappe.show_alert(__("Uploading data to GSTN")); - this.check_action_status_with_retry(action); + frappe.show_alert(__("Proceeding to file Nil Rated GSTR-1")); + this.proceed_to_file(); }, { is_nil_return : this.frm.doc.file_nil_gstr1 }); };