From 08c7591c4f89d92abc92b018756b56f64bed1786 Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Thu, 26 Dec 2024 15:44:17 +0530 Subject: [PATCH 01/12] feat: allow filing of Nil return for GSTR-1 --- .../gst_india/api_classes/taxpayer_returns.py | 5 +-- .../doctype/gst_return_log/generate_gstr_1.py | 24 ++++++++++---- .../doctype/gstr_1_beta/gstr_1_beta.js | 33 ++++++++++++++++--- .../doctype/gstr_1_beta/gstr_1_beta.json | 10 +++++- 4 files changed, 57 insertions(+), 15 deletions(-) diff --git a/india_compliance/gst_india/api_classes/taxpayer_returns.py b/india_compliance/gst_india/api_classes/taxpayer_returns.py index fb0df061bb..064414e351 100644 --- a/india_compliance/gst_india/api_classes/taxpayer_returns.py +++ b/india_compliance/gst_india/api_classes/taxpayer_returns.py @@ -37,7 +37,7 @@ def get_return_status(self, return_period, reference_id, otp=None): otp=otp, ) - def proceed_to_file(self, return_type, return_period, otp=None): + def proceed_to_file(self, return_type, return_period, is_nil_rated, otp=None): return self.post( return_type=return_type, return_period=return_period, @@ -46,7 +46,8 @@ def proceed_to_file(self, return_type, return_period, otp=None): "data": { "gstin": self.company_gstin, "ret_period": return_period, - }, # "isnil": "N" / "Y" + "isnil": "Y" if is_nil_rated else "N", + }, }, endpoint="returns/gstrptf", otp=otp, 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 e62a22490c..fd98d09852 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 @@ -4,7 +4,7 @@ import frappe from frappe import _, unscrub -from frappe.utils import flt +from frappe.utils import cint, flt from india_compliance.gst_india.api_classes.taxpayer_returns import GSTR1API from india_compliance.gst_india.utils.gstr_1 import GovJsonKey, GSTR1_SubCategory @@ -747,7 +747,7 @@ def process_reset_gstr1(self): return response - def upload_gstr1(self, json_data, force): + def upload_gstr1(self, json_data, is_nil_rated, force): if not json_data: return @@ -755,8 +755,14 @@ def upload_gstr1(self, json_data, force): keys = {category.value for category in GovJsonKey} if all(key not in json_data for key in keys): - frappe.msgprint(_("No data to upload"), indicator="red") - return + if not cint(is_nil_rated): + frappe.msgprint( + _("No data to upload. To file Nil Return, mark the checkbox."), + indicator="red", + ) + return + + return "upload nil return gstr1" # upload data after proceed to file self.db_set({"filing_status": "Not Filed"}) @@ -812,11 +818,11 @@ def process_upload_gstr1(self): return response - def proceed_to_file_gstr1(self, force): + def proceed_to_file_gstr1(self, is_nil_rated, force): verify_request_in_progress(self, force) api = GSTR1API(self) - response = api.proceed_to_file("GSTR1", self.return_period) + response = api.proceed_to_file("GSTR1", self.return_period, is_nil_rated) # Return Form already ready to be filed if response.error and response.error.error_cd == "RET00003": @@ -843,6 +849,10 @@ def process_proceed_to_file_gstr1(self): if response.get("status_cd") == "IP": return response + if response.error and response.error.error_cd == "RET13510": + # here it is giving status code as 0 + response.status_cd = "P" + doc.db_set({"status": status_code_map.get(response.get("status_cd"))}) return self.fetch_and_compare_summary(api, response) @@ -858,7 +868,7 @@ def fetch_and_compare_summary(self, api, response=None): self.update_json_for("authenticated_summary", summary) mapped_summary = self.get_json_for("books_summary") - gov_summary = convert_to_internal_data_format(summary).get("summary") + gov_summary = convert_to_internal_data_format(summary).get("summary", {}) gov_summary = summarize_retsum_data(gov_summary.values()) differing_categories = get_differing_categories(mapped_summary, gov_summary) 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 272e0ddc00..6e5be4335a 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 @@ -2570,24 +2570,39 @@ class GSTR1Action extends FileGSTR1Dialog { r.message.pending_actions.forEach(request_type => this.check_action_status_with_retry(request_type, 0, true) ); + + this.check_for_nil_rated(); }); } + check_for_nil_rated() { + const data = this.frm.doc.__gst_data; + if (Object.keys(data.unfiled).length == 1 && data.status == "Not Filed") { + this.frm.set_df_property("file_nil_gstr1", "hidden", 0) + } + } + async upload_gstr1_data() { const action = "upload"; if (await this.is_request_in_progress(action)) return; const upload = () => { - frappe.show_alert(__("Uploading data to GSTN")); this.perform_gstr1_action(action, response => { // No data to upload - if (response._server_messages && response._server_messages.length) { + if(response._server_messages){ + 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); - }); + }, + { is_nil_rated : this.frm.doc.file_nil_gstr1 }); }; // has draft invoices @@ -2625,9 +2640,15 @@ class GSTR1Action extends FileGSTR1Dialog { const action = "proceed_to_file"; this.perform_gstr1_action(action, r => { // already proceed to file - if (r.message) this.handle_proceed_to_file_response(r.message); + if (r.message){ + this.toggle_actions(true); + this.handle_proceed_to_file_response(r.message); + this.check_for_nil_rated(); + } else this.check_action_status_with_retry(action); - }); + // TODO: this.check_for_nil_rated should also go after else condition + }, + { is_nil_rated : this.frm.doc.file_nil_gstr1 }); } async mark_as_unfiled() { @@ -2646,8 +2667,10 @@ class GSTR1Action extends FileGSTR1Dialog { args: { filters: filters, force: this.frm.__action_performed == undefined }, callback: () => { this.frm.gstr1.status = "Not Filed"; + this.frm.doc.__gst_data.status = "Not Filed"; this.frm.refresh(); this.frm.gstr1.refresh_data(); + this.check_for_nil_rated(); }, }); } diff --git a/india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.json b/india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.json index ee26f09558..3aec4f6c73 100644 --- a/india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.json +++ b/india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.json @@ -7,6 +7,7 @@ "field_order": [ "form", "company", + "file_nil_gstr1", "column_break_ejve", "company_gstin", "column_break_ldkv", @@ -81,13 +82,20 @@ "fieldtype": "Select", "label": "Month/Quarter", "reqd": 1 + }, + { + "default": "0", + "fieldname": "file_nil_gstr1", + "fieldtype": "Check", + "hidden": 1, + "label": "File Nil GSTR-1" } ], "hide_toolbar": 1, "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2024-05-27 19:30:01.074149", + "modified": "2024-12-26 12:43:21.979607", "modified_by": "Administrator", "module": "GST India", "name": "GSTR-1 Beta", From ad6f235bf7301bad308c3b619c5a3e8bdd873688 Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Thu, 26 Dec 2024 17:16:19 +0530 Subject: [PATCH 02/12] fix: scroll to field and modify error message --- .../gst_india/doctype/gst_return_log/generate_gstr_1.py | 4 +++- india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.js | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) 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 fd98d09852..d34df0eaf6 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 @@ -757,7 +757,9 @@ def upload_gstr1(self, json_data, is_nil_rated, force): if all(key not in json_data for key in keys): if not cint(is_nil_rated): frappe.msgprint( - _("No data to upload. To file Nil Return, mark the checkbox."), + _( + 'No data to upload.To file Nil Return Select "File Nil GSTR-1" checkbox.' + ), indicator="red", ) return 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 6e5be4335a..4ee82f68f3 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 @@ -2590,6 +2590,7 @@ class GSTR1Action extends FileGSTR1Dialog { this.perform_gstr1_action(action, response => { // No data to upload if(response._server_messages){ + this.frm.scroll_to_field("file_nil_gstr1"); this.toggle_actions(true); return; } From e5c919d3afb08eaf32af6158b25be1a5323a6a82 Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Thu, 26 Dec 2024 23:10:22 +0530 Subject: [PATCH 03/12] fix: rename field --- .../gst_india/api_classes/taxpayer_returns.py | 4 ++-- .../doctype/gst_return_log/generate_gstr_1.py | 8 ++++---- .../gst_india/doctype/gstr_1_beta/gstr_1_beta.js | 14 +++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/india_compliance/gst_india/api_classes/taxpayer_returns.py b/india_compliance/gst_india/api_classes/taxpayer_returns.py index 064414e351..d50cc3a526 100644 --- a/india_compliance/gst_india/api_classes/taxpayer_returns.py +++ b/india_compliance/gst_india/api_classes/taxpayer_returns.py @@ -37,7 +37,7 @@ def get_return_status(self, return_period, reference_id, otp=None): otp=otp, ) - def proceed_to_file(self, return_type, return_period, is_nil_rated, otp=None): + def proceed_to_file(self, return_type, return_period, is_nil_return, otp=None): return self.post( return_type=return_type, return_period=return_period, @@ -46,7 +46,7 @@ def proceed_to_file(self, return_type, return_period, is_nil_rated, otp=None): "data": { "gstin": self.company_gstin, "ret_period": return_period, - "isnil": "Y" if is_nil_rated else "N", + "isnil": "Y" if is_nil_return else "N", }, }, endpoint="returns/gstrptf", 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 d34df0eaf6..53062baad2 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 @@ -747,7 +747,7 @@ def process_reset_gstr1(self): return response - def upload_gstr1(self, json_data, is_nil_rated, force): + def upload_gstr1(self, json_data, is_nil_return, force): if not json_data: return @@ -755,7 +755,7 @@ def upload_gstr1(self, json_data, is_nil_rated, force): keys = {category.value for category in GovJsonKey} if all(key not in json_data for key in keys): - if not cint(is_nil_rated): + if not cint(is_nil_return): frappe.msgprint( _( 'No data to upload.To file Nil Return Select "File Nil GSTR-1" checkbox.' @@ -820,11 +820,11 @@ def process_upload_gstr1(self): return response - def proceed_to_file_gstr1(self, is_nil_rated, force): + def proceed_to_file_gstr1(self, is_nil_return, force): verify_request_in_progress(self, force) api = GSTR1API(self) - response = api.proceed_to_file("GSTR1", self.return_period, is_nil_rated) + response = api.proceed_to_file("GSTR1", self.return_period, is_nil_return) # Return Form already ready to be filed if response.error and response.error.error_cd == "RET00003": 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 4ee82f68f3..64eac03f54 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 @@ -2571,11 +2571,11 @@ class GSTR1Action extends FileGSTR1Dialog { this.check_action_status_with_retry(request_type, 0, true) ); - this.check_for_nil_rated(); + this.check_for_nil_return(); }); } - check_for_nil_rated() { + check_for_nil_return() { const data = this.frm.doc.__gst_data; if (Object.keys(data.unfiled).length == 1 && data.status == "Not Filed") { this.frm.set_df_property("file_nil_gstr1", "hidden", 0) @@ -2603,7 +2603,7 @@ class GSTR1Action extends FileGSTR1Dialog { frappe.show_alert(__("Uploading data to GSTN")); this.check_action_status_with_retry(action); }, - { is_nil_rated : this.frm.doc.file_nil_gstr1 }); + { is_nil_return : this.frm.doc.file_nil_gstr1 }); }; // has draft invoices @@ -2644,12 +2644,12 @@ class GSTR1Action extends FileGSTR1Dialog { if (r.message){ this.toggle_actions(true); this.handle_proceed_to_file_response(r.message); - this.check_for_nil_rated(); + this.check_for_nil_return(); } else this.check_action_status_with_retry(action); - // TODO: this.check_for_nil_rated should also go after else condition + // TODO: this.check_for_nil_return should also go after else condition }, - { is_nil_rated : this.frm.doc.file_nil_gstr1 }); + { is_nil_return : this.frm.doc.file_nil_gstr1 }); } async mark_as_unfiled() { @@ -2671,7 +2671,7 @@ class GSTR1Action extends FileGSTR1Dialog { this.frm.doc.__gst_data.status = "Not Filed"; this.frm.refresh(); this.frm.gstr1.refresh_data(); - this.check_for_nil_rated(); + this.check_for_nil_return(); }, }); } From b572da3203586247648b1639eb88daa10f3029a4 Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Fri, 27 Dec 2024 11:28:23 +0530 Subject: [PATCH 04/12] 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 | 24 ++++++++++--------- 2 files changed, 14 insertions(+), 14 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 53062baad2..147c4af50c 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 64eac03f54..e915a676f3 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,20 +2565,21 @@ 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 (Object.keys(data.unfiled).length == 1 && data.status == "Not Filed") { + 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 }); }; From 267bba37126d33fbcff0fba425a883cab84124de Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Tue, 31 Dec 2024 18:57:13 +0530 Subject: [PATCH 05/12] fix: check for unfiled data --- india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e915a676f3..a1008ac568 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 @@ -2577,7 +2577,7 @@ class GSTR1Action extends FileGSTR1Dialog { check_for_nil_return() { const data = this.frm.doc.__gst_data; - if(!data || !is_gstr1_api_enabled()) return; + if(!data || !data.unfiled || !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) From 5a9de958eb9163d42ec5fa49ad9e631ad65df49b Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Thu, 9 Jan 2025 22:39:03 +0530 Subject: [PATCH 06/12] fix: show proceed_to_file button when nil return --- .../doctype/gst_return_log/generate_gstr_1.py | 19 +++++------ .../doctype/gstr_1_beta/gstr_1_beta.js | 33 +++++++++---------- 2 files changed, 25 insertions(+), 27 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 147c4af50c..8c1dc4aab8 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 @@ -4,7 +4,7 @@ import frappe from frappe import _, unscrub -from frappe.utils import cint, flt +from frappe.utils import flt from india_compliance.gst_india.api_classes.taxpayer_returns import GSTR1API from india_compliance.gst_india.utils.gstr_1 import GovJsonKey, GSTR1_SubCategory @@ -747,7 +747,7 @@ def process_reset_gstr1(self): return response - def upload_gstr1(self, json_data, is_nil_return, force): + def upload_gstr1(self, json_data, force): if not json_data: return @@ -755,14 +755,13 @@ def upload_gstr1(self, json_data, is_nil_return, force): keys = {category.value for category in GovJsonKey} if all(key not in json_data for key in keys): - if not cint(is_nil_return): - frappe.msgprint( - _( - 'No data to upload.To file Nil Return Select "File Nil GSTR-1" checkbox.' - ), - indicator="red", - ) - return "nil_return_for_gstr1" + frappe.msgprint( + _( + 'No data to upload.To file Nil Return Select "File Nil GSTR-1" checkbox.' + ), + indicator="red", + ) + return # 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 a1008ac568..44882ea767 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 @@ -481,6 +481,11 @@ class GSTR1 { }); } + const data = this.frm.doc.__gst_data; + if(data && Object.keys(data.books.aggregate_data).length == 0){ + primary_button_label = "Proceed to File" + } + this.frm.page.set_primary_action(__(primary_button_label), () => actions[primary_button_label].call(this.gstr1_action) ); @@ -2577,10 +2582,12 @@ class GSTR1Action extends FileGSTR1Dialog { check_for_nil_return() { const data = this.frm.doc.__gst_data; - if(!data || !data.unfiled || !is_gstr1_api_enabled()) return; + // check this that books data is present or not + 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) + if (Object.keys(data.books.aggregate_data).length === 0 && data.status == "Not Filed") { + this.frm.set_df_property("file_nil_gstr1", "hidden", 0); + this.frm.remove_custom_button('Upload'); } } @@ -2589,23 +2596,16 @@ class GSTR1Action extends FileGSTR1Dialog { if (await this.is_request_in_progress(action)) return; const upload = () => { + frappe.show_alert(__("Uploading data to GSTN")); 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); + if (response._server_messages && response._server_messages.length) { + this.proceed_to_file(); return; } - frappe.show_alert(__("Proceeding to file Nil Rated GSTR-1")); - this.proceed_to_file(); - }, - { is_nil_return : this.frm.doc.file_nil_gstr1 }); + + this.check_action_status_with_retry(action); + }); }; // has draft invoices @@ -2649,7 +2649,6 @@ class GSTR1Action extends FileGSTR1Dialog { this.check_for_nil_return(); } else this.check_action_status_with_retry(action); - // TODO: this.check_for_nil_return should also go after else condition }, { is_nil_return : this.frm.doc.file_nil_gstr1 }); } From 2c872e87c02be71c5af0dd613a2797dd9bd61d85 Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Fri, 10 Jan 2025 17:33:35 +0530 Subject: [PATCH 07/12] fix: show proceed to file button on check of checkbox --- .../doctype/gst_return_log/generate_gstr_1.py | 7 +------ .../doctype/gstr_1_beta/gstr_1_beta.js | 20 +++++++++++++------ 2 files changed, 15 insertions(+), 12 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 8c1dc4aab8..5f789e90af 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 @@ -755,12 +755,7 @@ def upload_gstr1(self, json_data, force): keys = {category.value for category in GovJsonKey} if all(key not in json_data for key in keys): - frappe.msgprint( - _( - 'No data to upload.To file Nil Return Select "File Nil GSTR-1" checkbox.' - ), - indicator="red", - ) + frappe.msgprint(_("No data to upload"), indicator="red") return # upload data after proceed to file 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 44882ea767..fc600026ce 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 @@ -186,6 +186,8 @@ frappe.ui.form.on(DOCTYPE, { company_gstin: render_empty_state, + file_nil_gstr1: file_nil_return, + month_or_quarter(frm) { render_empty_state(frm); }, @@ -481,11 +483,6 @@ class GSTR1 { }); } - const data = this.frm.doc.__gst_data; - if(data && Object.keys(data.books.aggregate_data).length == 0){ - primary_button_label = "Proceed to File" - } - this.frm.page.set_primary_action(__(primary_button_label), () => actions[primary_button_label].call(this.gstr1_action) ); @@ -2583,7 +2580,7 @@ class GSTR1Action extends FileGSTR1Dialog { check_for_nil_return() { const data = this.frm.doc.__gst_data; // check this that books data is present or not - if(!data || !is_gstr1_api_enabled()) return; + if (!data || !is_gstr1_api_enabled()) return; if (Object.keys(data.books.aggregate_data).length === 0 && data.status == "Not Filed") { this.frm.set_df_property("file_nil_gstr1", "hidden", 0); @@ -2967,6 +2964,17 @@ function set_options_for_month_or_quarter(frm) { else frm.set_value("month_or_quarter", options[options.length - 1]); } +function file_nil_return(frm){ + if(frm.doc.file_nil_gstr1){ + frm.page.set_primary_action(__("Proceed to File"), () => + frm.gstr1.gstr1_action.proceed_to_file() + ); + }else{ + frm.doc.__gst_data.status = "Not Filed"; + frm.gstr1?.render_form_actions(); + } +} + function render_empty_state(frm) { if ($(".gst-ledger-difference").length) { $(".gst-ledger-difference").remove(); From 6cd13b5d4f6d2e51346613f7855de40a3292444e Mon Sep 17 00:00:00 2001 From: Smit Vora Date: Sat, 11 Jan 2025 13:02:46 +0530 Subject: [PATCH 08/12] refactor: changes as per review --- .../doctype/gst_return_log/generate_gstr_1.py | 8 +-- .../doctype/gstr_1_beta/gstr_1_beta.js | 60 +++++++++++-------- 2 files changed, 36 insertions(+), 32 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 f724cb6307..15a21d4ccf 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 @@ -839,7 +839,7 @@ def proceed_to_file_gstr1(self, is_nil_return, force): response = api.proceed_to_file("GSTR1", self.return_period, is_nil_return) # Return Form already ready to be filed - if response.error and response.error.error_cd == "RET00003": + if response.error and response.error.error_cd == "RET00003" or is_nil_return: return self.fetch_and_compare_summary(api) set_gstr1_actions( @@ -863,10 +863,6 @@ def process_proceed_to_file_gstr1(self): if response.get("status_cd") == "IP": return response - if response.error and response.error.error_cd == "RET13510": - # here it is giving status code as 0 - response.status_cd = "P" - doc.db_set({"status": status_code_map.get(response.get("status_cd"))}) return self.fetch_and_compare_summary(api, response) @@ -944,7 +940,7 @@ def file_gstr1(self, pan, otp, force): def get_amendment_data(self): authenticated_summary = convert_to_internal_data_format( self.get_json_for("authenticated_summary") - ).get("summary") + ).get("summary", {}) authenticated_summary = summarize_retsum_data(authenticated_summary.values()) non_amended_entries = { 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 0cbcad0f3d..a0edaff8c4 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 @@ -196,7 +196,9 @@ frappe.ui.form.on(DOCTYPE, { company_gstin: render_empty_state, - file_nil_gstr1: file_nil_return, + file_nil_gstr1(frm) { + frm.gstr1.render_form_actions(); + }, month_or_quarter(frm) { render_empty_state(frm); @@ -303,6 +305,7 @@ class GSTR1 { } this.set_output_gst_balances(); + this.toggle_file_nil_gstr1(); // refresh tabs this.TABS.forEach(_tab => { @@ -480,14 +483,16 @@ class GSTR1 { File: this.gstr1_action.file_gstr1_data, }; + const status = this.frm.doc.file_nil_gstr1 && this.status == "Not Filed" ? "Uploaded" : this.status; + let primary_button_label = { "Not Filed": "Upload", Uploaded: "Proceed to File", "Ready to File": "File", - }[this.status] || "Generate"; + }[status] || "Generate"; - if (this.status === "Ready to File") { + if (status === "Ready to File") { this.frm.add_custom_button(__("Mark as Unfiled"), () => { this.gstr1_action.mark_as_unfiled(); }); @@ -690,6 +695,16 @@ class GSTR1 { else this.$wrapper.find(".filter-selector").hide(); } + toggle_file_nil_gstr1() { + if (!this.data || !is_gstr1_api_enabled()) return; + + const has_records = this.data.books_summary?.some(row => row.no_of_records > 0); + + if (!has_records && this.data.status != "Filed") + this.frm.set_df_property("file_nil_gstr1", "hidden", 0); + else this.frm.set_df_property("file_nil_gstr1", "hidden", 1); + } + async set_output_gst_balances() { //Checks if gst-ledger-difference element is there and removes if already present const gst_liability = await get_net_gst_liability(this.frm); @@ -2604,9 +2619,12 @@ class GSTR1Action extends FileGSTR1Dialog { // check this that books data is present or not if (!data || !is_gstr1_api_enabled()) return; - if (Object.keys(data.books.aggregate_data).length === 0 && data.status == "Not Filed") { + if ( + Object.keys(data.books.aggregate_data).length === 0 && + data.status == "Not Filed" + ) { this.frm.set_df_property("file_nil_gstr1", "hidden", 0); - this.frm.remove_custom_button('Upload'); + this.frm.remove_custom_button("Upload"); } } @@ -2660,16 +2678,17 @@ class GSTR1Action extends FileGSTR1Dialog { proceed_to_file() { const action = "proceed_to_file"; - this.perform_gstr1_action(action, r => { - // already proceed to file - if (r.message){ - this.toggle_actions(true); - this.handle_proceed_to_file_response(r.message); - this.check_for_nil_return(); - } - else this.check_action_status_with_retry(action); - }, - { is_nil_return : this.frm.doc.file_nil_gstr1 }); + this.perform_gstr1_action( + action, + r => { + // already proceed to file + if (r.message) { + this.toggle_actions(true); + this.handle_proceed_to_file_response(r.message); + } else this.check_action_status_with_retry(action); + }, + { is_nil_return: this.frm.doc.file_nil_gstr1 }, + ); } async mark_as_unfiled() { @@ -2993,17 +3012,6 @@ function set_options_for_month_or_quarter(frm) { else frm.set_value("month_or_quarter", options[options.length - 1]); } -function file_nil_return(frm){ - if(frm.doc.file_nil_gstr1){ - frm.page.set_primary_action(__("Proceed to File"), () => - frm.gstr1.gstr1_action.proceed_to_file() - ); - }else{ - frm.doc.__gst_data.status = "Not Filed"; - frm.gstr1?.render_form_actions(); - } -} - function render_empty_state(frm) { if ($(".gst-ledger-difference").length) { $(".gst-ledger-difference").remove(); From 6725770c71fa5ffe77edc217ab2f6e7daef9c606 Mon Sep 17 00:00:00 2001 From: Smit Vora Date: Sat, 11 Jan 2025 13:10:33 +0530 Subject: [PATCH 09/12] revert: original JS implementation --- .../doctype/gstr_1_beta/gstr_1_beta.js | 39 +++++++------------ 1 file changed, 13 insertions(+), 26 deletions(-) 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 a0edaff8c4..67ca7ef671 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,8 +170,12 @@ frappe.ui.form.on(DOCTYPE, { const only_books_data = error_log != undefined; if (error_log) { frappe.msgprint({ - message: __("Error while preparing GSTR-1 data, please check {0} for more deatils.", - [`error log`]), + message: __( + "Error while preparing GSTR-1 data, please check {0} for more deatils.", + [ + `error log`, + ] + ), title: "GSTR-1 Download Failed", indicator: "red", }); @@ -180,7 +184,6 @@ frappe.ui.form.on(DOCTYPE, { frm.taxpayer_api_call("generate_gstr1", { only_books_data }).then(r => { frm.doc.__gst_data = r.message; frm.trigger("load_gstr1_data"); - frm.gstr1.gstr1_action?.check_for_nil_return(); }); }); }, @@ -483,7 +486,10 @@ class GSTR1 { File: this.gstr1_action.file_gstr1_data, }; - const status = this.frm.doc.file_nil_gstr1 && this.status == "Not Filed" ? "Uploaded" : this.status; + const status = + this.frm.doc.file_nil_gstr1 && this.status == "Not Filed" + ? "Uploaded" + : this.status; let primary_button_label = { @@ -2604,7 +2610,6 @@ 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; @@ -2614,20 +2619,6 @@ class GSTR1Action extends FileGSTR1Dialog { }); } - check_for_nil_return() { - const data = this.frm.doc.__gst_data; - // check this that books data is present or not - if (!data || !is_gstr1_api_enabled()) return; - - if ( - Object.keys(data.books.aggregate_data).length === 0 && - data.status == "Not Filed" - ) { - this.frm.set_df_property("file_nil_gstr1", "hidden", 0); - this.frm.remove_custom_button("Upload"); - } - } - async upload_gstr1_data() { const action = "upload"; if (await this.is_request_in_progress(action)) return; @@ -2682,12 +2673,10 @@ class GSTR1Action extends FileGSTR1Dialog { action, r => { // already proceed to file - if (r.message) { - this.toggle_actions(true); - this.handle_proceed_to_file_response(r.message); - } else this.check_action_status_with_retry(action); + if (r.message) this.handle_proceed_to_file_response(r.message); + else this.check_action_status_with_retry(action); }, - { is_nil_return: this.frm.doc.file_nil_gstr1 }, + { is_nil_return: this.frm.doc.file_nil_gstr1 } ); } @@ -2707,10 +2696,8 @@ class GSTR1Action extends FileGSTR1Dialog { args: { filters: filters, force: this.frm.__action_performed == undefined }, callback: () => { this.frm.gstr1.status = "Not Filed"; - this.frm.doc.__gst_data.status = "Not Filed"; this.frm.refresh(); this.frm.gstr1.refresh_data(); - this.check_for_nil_return(); }, }); } From c4890d2a2140abdba54a032c2a71501a3dae54d2 Mon Sep 17 00:00:00 2001 From: Smit Vora Date: Sat, 11 Jan 2025 14:02:29 +0530 Subject: [PATCH 10/12] fix: sbool for string, ensure valid data is sent for filing of return --- .../gst_india/api_classes/taxpayer_returns.py | 17 +++++++++-------- .../doctype/gst_return_log/generate_gstr_1.py | 11 ++++++++++- .../doctype/gstr_1_beta/gstr_1_beta.js | 3 ++- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/india_compliance/gst_india/api_classes/taxpayer_returns.py b/india_compliance/gst_india/api_classes/taxpayer_returns.py index d50cc3a526..26807a075e 100644 --- a/india_compliance/gst_india/api_classes/taxpayer_returns.py +++ b/india_compliance/gst_india/api_classes/taxpayer_returns.py @@ -38,17 +38,18 @@ def get_return_status(self, return_period, reference_id, otp=None): ) def proceed_to_file(self, return_type, return_period, is_nil_return, otp=None): + data = { + "gstin": self.company_gstin, + "ret_period": return_period, + } + + if is_nil_return: + data["isnil"] = "Y" + return self.post( return_type=return_type, return_period=return_period, - json={ - "action": "RETNEWPTF", - "data": { - "gstin": self.company_gstin, - "ret_period": return_period, - "isnil": "Y" if is_nil_return else "N", - }, - }, + json={"action": "RETNEWPTF", "data": data}, endpoint="returns/gstrptf", otp=otp, ) 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 15a21d4ccf..6ea266a37a 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 @@ -4,7 +4,7 @@ import frappe from frappe import _, unscrub -from frappe.utils import flt +from frappe.utils import flt, sbool from india_compliance.gst_india.api_classes.taxpayer_returns import GSTR1API from india_compliance.gst_india.utils.gstr_1 import GovJsonKey, GSTR1_SubCategory @@ -835,11 +835,20 @@ def process_upload_gstr1(self): def proceed_to_file_gstr1(self, is_nil_return, force): verify_request_in_progress(self, force) + is_nil_return = sbool(is_nil_return) + api = GSTR1API(self) response = api.proceed_to_file("GSTR1", self.return_period, is_nil_return) # Return Form already ready to be filed if response.error and response.error.error_cd == "RET00003" or is_nil_return: + set_gstr1_actions( + self, + "proceed_to_file", + response.get("reference_id"), + api.request_id, + status="Processed", + ) return self.fetch_and_compare_summary(api) set_gstr1_actions( 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 67ca7ef671..3620da16da 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 @@ -486,6 +486,7 @@ class GSTR1 { File: this.gstr1_action.file_gstr1_data, }; + // No need to upload if nil gstr1 const status = this.frm.doc.file_nil_gstr1 && this.status == "Not Filed" ? "Uploaded" @@ -2673,7 +2674,7 @@ class GSTR1Action extends FileGSTR1Dialog { action, r => { // already proceed to file - if (r.message) this.handle_proceed_to_file_response(r.message); + if (r.message) this.handle_proceed_to_file_response(r.message) && this.toggle_actions(true); else this.check_action_status_with_retry(action); }, { is_nil_return: this.frm.doc.file_nil_gstr1 } From 561c1386e160cbcd3c7fb154f8e4d000182225be Mon Sep 17 00:00:00 2001 From: Smit Vora Date: Sat, 11 Jan 2025 14:27:12 +0530 Subject: [PATCH 11/12] fix: retain upload or proceed to file status for nil return --- .../doctype/gst_return_log/generate_gstr_1.py | 2 ++ .../doctype/gstr_1_beta/gstr_1_beta.js | 20 +++++++++++++++++-- .../gst_india/utils/gstr_1/gstr_1_download.py | 3 +-- 3 files changed, 21 insertions(+), 4 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 6ea266a37a..245d8320fc 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 @@ -881,6 +881,8 @@ def fetch_and_compare_summary(self, api, response=None): response = {} summary = api.get_gstr_1_data("RETSUM", self.return_period) + self.db_set("is_nil", summary.isnil == "Y") + if summary.error: return 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 3620da16da..9c669fa380 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 @@ -229,6 +229,8 @@ frappe.ui.form.on(DOCTYPE, { const data = frm.doc.__gst_data; if (!data?.status) return; + frm.doc.file_nil_gstr1 = data.is_nil + // Toggle HTML fields frm.refresh(); @@ -365,6 +367,10 @@ class GSTR1 { }); } + refresh_no_data_message() { + this.tabs.filed_tab.tabmanager.refresh_no_data_message(); + } + // RENDER render() { @@ -903,6 +909,10 @@ class TabManager { this.set_creation_time_string(); } + refresh_no_data_message() { + this.datatable.refresh(null, null, this.get_no_data_message()); + } + refresh_view(view, category, filters) { if (!category && view === "Detailed") return; @@ -2139,7 +2149,10 @@ class FiledTab extends GSTR1_TabManager { get_no_data_message() { if (this.instance.data?.is_nil) - return __("You have filed a Nil GSTR-1 for this period"); + if (this.status === "Filed") + return __("You have filed a Nil GSTR-1 for this period"); + else + return __("You are filing a Nil GSTR-1 for this period"); return this.DEFAULT_NO_DATA_MESSAGE; } @@ -2670,11 +2683,14 @@ class GSTR1Action extends FileGSTR1Dialog { proceed_to_file() { const action = "proceed_to_file"; + this.frm.gstr1.data.is_nil = this.frm.doc.file_nil_gstr1; + this.frm.gstr1.refresh_no_data_message(); + this.perform_gstr1_action( action, r => { // already proceed to file - if (r.message) this.handle_proceed_to_file_response(r.message) && this.toggle_actions(true); + if (r.message) this.handle_proceed_to_file_response(r.message); else this.check_action_status_with_retry(action); }, { is_nil_return: this.frm.doc.file_nil_gstr1 } diff --git a/india_compliance/gst_india/utils/gstr_1/gstr_1_download.py b/india_compliance/gst_india/utils/gstr_1/gstr_1_download.py index 79563fbc21..307716a794 100644 --- a/india_compliance/gst_india/utils/gstr_1/gstr_1_download.py +++ b/india_compliance/gst_india/utils/gstr_1/gstr_1_download.py @@ -76,8 +76,7 @@ def download_gstr1_json_data(gstr1_log): json_data.update(response) - if json_data.isnil == "Y": - gstr1_log.db_set("is_nil", 1) + gstr1_log.db_set("is_nil", json_data.isnil == "Y") mapped_data = convert_to_internal_data_format(json_data) gstr1_log.update_json_for(data_field, mapped_data, reset_reconcile=True) From 342b47471fa35a0333e19ea3b14a942d3575b13f Mon Sep 17 00:00:00 2001 From: Smit Vora Date: Sat, 11 Jan 2025 14:40:03 +0530 Subject: [PATCH 12/12] fix: more robust algo for showing journal entry dialog --- india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.js | 2 +- india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) 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 9c669fa380..de1e9b6bc1 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 @@ -774,7 +774,7 @@ class GSTR1 { args: { month_or_quarter, year, company }, }); - if (!je_details || !je_details.data) return; + if (!je_details) return; this.create_journal_entry_dialog(je_details); } diff --git a/india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.py b/india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.py index 6c2c8f1e59..32e6e7d101 100644 --- a/india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.py +++ b/india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.py @@ -287,6 +287,9 @@ def get_journal_entries(month_or_quarter, year, company): .run(as_dict=True) ) + if not data: + return + return {"data": data, "posting_date": to_date}