From d14629df80006fdca8a0ead92a77843e26900763 Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Fri, 20 Dec 2024 18:34:47 +0530 Subject: [PATCH 1/5] fix: handle gov api error --- .../doctype/gst_return_log/generate_gstr_1.py | 18 +++++++++++++++--- .../doctype/gst_return_log/gst_return_log.py | 4 ++-- .../doctype/gstr_1_beta/gstr_1_beta.js | 14 ++++++++++++-- .../doctype/gstr_1_beta/gstr_1_beta.py | 13 ++++++++++--- 4 files changed, 39 insertions(+), 10 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 e62a22490c..2988911abd 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 @@ -556,7 +556,19 @@ def generate_gstr1_data(self, filters, callback=None): gov_data_field = "unfiled" # Get Data - gov_data, is_enqueued = self.get_gov_gstr1_data() + try: + gov_data, is_enqueued = self.get_gov_gstr1_data() + except frappe.ValidationError as e: + frappe.throw(str(e)) + except Exception as e: + doc = frappe.get_doc( + doctype="Error Log", + error=frappe.get_traceback(), + method=str(e), + reference_doctype="GSTR-1 Beta", + ).save() + + return self.generate_only_books_data(data, filters, callback, doc.name) books_data = self.get_books_gstr1_data(filters) @@ -579,7 +591,7 @@ def generate_gstr1_data(self, filters, callback=None): self.summarize_data(data) return callback and callback(filters) - def generate_only_books_data(self, data, filters, callback=None): + def generate_only_books_data(self, data, filters, callback=None, error_log=None): status = "Not Filed" books_data = self.get_books_gstr1_data(filters, aggregate=True) @@ -588,7 +600,7 @@ def generate_only_books_data(self, data, filters, callback=None): data["status"] = status self.summarize_data(data) - return callback and callback(filters) + return callback and callback(filters, error_log) # GET DATA def get_gov_gstr1_data(self): diff --git a/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.py b/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.py index 52283eb89a..d8cafbb828 100644 --- a/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.py +++ b/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.py @@ -33,11 +33,11 @@ def update_status(self, status, commit=False): self.db_set("generation_status", status, commit=commit) # FILE UTILITY - def load_data(self, file_field=None): + def load_data(self, *file_field): data = {} if file_field: - file_fields = [file_field] + file_fields = list(file_field) else: file_fields = self.get_applicable_file_fields() 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..f9a9c495e1 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 @@ -158,7 +158,7 @@ frappe.ui.form.on(DOCTYPE, { }); frappe.realtime.on("gstr1_data_prepared", message => { - const { filters } = message; + const { filters, error_log } = message; if ( frm.doc.company_gstin !== filters.company_gstin || @@ -167,7 +167,17 @@ frappe.ui.form.on(DOCTYPE, { ) return; - frm.taxpayer_api_call("generate_gstr1").then(r => { + const only_books_data = error_log != null ; + if (error_log) { + frappe.msgprint({ + message: __("Error while preparing GSTR-1 data, Please Check {0} for more deatils", + [`Error Log`]), + title: "GSTR-1 Download Failed", + indicator: "red", + }) + } + + frm.taxpayer_api_call("generate_gstr1", {only_books_data}).then(r => { frm.doc.__gst_data = r.message; frm.trigger("load_gstr1_data"); }); 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 e4f4277763..fe88f8582e 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 @@ -56,7 +56,9 @@ def mark_as_filed(self): @frappe.whitelist() @otp_handler - def generate_gstr1(self, sync_for=None, recompute_books=False, message=None): + def generate_gstr1( + self, sync_for=None, recompute_books=False, only_books_data=None, message=None + ): period = get_period(self.month_or_quarter, self.year) # get gstr1 log @@ -99,6 +101,11 @@ def generate_gstr1(self, sync_for=None, recompute_books=False, message=None): gstr1_log.remove_json_for("books") # files are already present + if only_books_data: + data = gstr1_log.load_data("books", "books_summary") + data["status"] = "Error While Generation" + return data + if gstr1_log.has_all_files(settings): data = gstr1_log.get_gstr1_data() @@ -147,7 +154,7 @@ def _generate_gstr1(self): raise e - def on_generate(self, filters=None): + def on_generate(self, filters=None, error_log=None): """ Once data is generated, update the status and publish the data """ @@ -161,7 +168,7 @@ def on_generate(self, filters=None): frappe.publish_realtime( "gstr1_data_prepared", - message={"filters": filters}, + message={"filters": filters, "error_log": error_log}, user=frappe.session.user, doctype=self.doctype, ) From d36a549931e719e1f7b71cc8f14ae8ec969ab1f0 Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Mon, 23 Dec 2024 18:17:25 +0530 Subject: [PATCH 2/5] fix: added function for handling gstr-1 gov error --- .../doctype/gst_return_log/generate_gstr_1.py | 35 ++++++++++++------- .../doctype/gstr_1_beta/gstr_1_beta.js | 2 +- .../doctype/gstr_1_beta/gstr_1_beta.py | 4 +-- 3 files changed, 25 insertions(+), 16 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 2988911abd..b54df610fa 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 @@ -558,17 +558,8 @@ def generate_gstr1_data(self, filters, callback=None): # Get Data try: gov_data, is_enqueued = self.get_gov_gstr1_data() - except frappe.ValidationError as e: - frappe.throw(str(e)) - except Exception as e: - doc = frappe.get_doc( - doctype="Error Log", - error=frappe.get_traceback(), - method=str(e), - reference_doctype="GSTR-1 Beta", - ).save() - - return self.generate_only_books_data(data, filters, callback, doc.name) + except frappe.ValidationError as error: + return self.handle_gstr1_gov_failure(data, filters, error) books_data = self.get_books_gstr1_data(filters) @@ -591,7 +582,7 @@ def generate_gstr1_data(self, filters, callback=None): self.summarize_data(data) return callback and callback(filters) - def generate_only_books_data(self, data, filters, callback=None, error_log=None): + def generate_only_books_data(self, data, filters, callback=None): status = "Not Filed" books_data = self.get_books_gstr1_data(filters, aggregate=True) @@ -600,7 +591,7 @@ def generate_only_books_data(self, data, filters, callback=None, error_log=None) data["status"] = status self.summarize_data(data) - return callback and callback(filters, error_log) + return callback and callback(filters) # GET DATA def get_gov_gstr1_data(self): @@ -619,6 +610,24 @@ def get_gov_gstr1_data(self): # download data return download_gstr1_json_data(self) + def handle_gstr1_gov_failure(self, data, filters, error): + self.generate_only_books_data(data, filters) + error_log = frappe.log_error( + title="GSTR-1 Generation Failed", + message=str(error), + reference_doctype="GSTR-1 Beta", + ) + self.update_status("Failed", commit=True) + frappe.publish_realtime( + "gstr1_data_prepared", + message={ + "filters": filters, + "error_log": error_log.name, + }, + user=frappe.session.user, + doctype=self.doctype, + ) + def get_books_gstr1_data(self, filters, aggregate=False): from india_compliance.gst_india.doctype.gstr_1_beta.gstr_1_beta import ( get_gstr_1_from_and_to_date, 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 f9a9c495e1..8548a62f94 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 @@ -167,7 +167,7 @@ frappe.ui.form.on(DOCTYPE, { ) return; - const only_books_data = error_log != null ; + 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", 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 fe88f8582e..7eb476b22b 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 @@ -154,7 +154,7 @@ def _generate_gstr1(self): raise e - def on_generate(self, filters=None, error_log=None): + def on_generate(self, filters=None): """ Once data is generated, update the status and publish the data """ @@ -168,7 +168,7 @@ def on_generate(self, filters=None, error_log=None): frappe.publish_realtime( "gstr1_data_prepared", - message={"filters": filters, "error_log": error_log}, + message={"filters": filters}, user=frappe.session.user, doctype=self.doctype, ) From 16bb292b2f45f3408c178e19b1e0cae07343ce17 Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Tue, 24 Dec 2024 12:40:54 +0530 Subject: [PATCH 3/5] fix: fetch gov data based on requirement --- .../doctype/gst_return_log/generate_gstr_1.py | 3 +++ .../doctype/gst_return_log/gst_return_log.py | 6 +++++- .../gst_india/doctype/gst_settings/gst_settings.json | 12 ++++++++++-- 3 files changed, 18 insertions(+), 3 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 b54df610fa..426079dd9c 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 @@ -595,6 +595,9 @@ def generate_only_books_data(self, data, filters, callback=None): # GET DATA def get_gov_gstr1_data(self): + if frappe.get_cached_value("GST Settings", None, "compare_for_pre_upload") != 1: + return frappe._dict(), False + if self.filing_status == "Filed": data_field = "filed" else: diff --git a/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.py b/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.py index d8cafbb828..78242336a3 100644 --- a/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.py +++ b/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.py @@ -184,6 +184,9 @@ def get_return_status(self): def get_applicable_file_fields(self, settings=None): # Books aggregated data stored in filed (as to file) + if not settings: + settings = frappe.get_cached_doc("GST Settings") + fields = ["books", "books_summary"] if self.is_gstr1_api_enabled(settings): @@ -192,7 +195,8 @@ def get_applicable_file_fields(self, settings=None): if self.filing_status == "Filed": fields.extend(["filed", "filed_summary"]) else: - fields.extend(["unfiled", "unfiled_summary"]) + if settings.compare_for_pre_upload: + fields.extend(["unfiled", "unfiled_summary"]) return fields diff --git a/india_compliance/gst_india/doctype/gst_settings/gst_settings.json b/india_compliance/gst_india/doctype/gst_settings/gst_settings.json index 391cabae49..923966c6ad 100644 --- a/india_compliance/gst_india/doctype/gst_settings/gst_settings.json +++ b/india_compliance/gst_india/doctype/gst_settings/gst_settings.json @@ -48,6 +48,7 @@ "e_invoice_applicable_from", "e_invoice_applicable_companies", "gstr_1_section_break", + "compare_for_pre_upload", "compare_gstr_1_data", "filing_frequency", "column_break_cxmn", @@ -613,7 +614,7 @@ { "default": "0", "depends_on": "eval: india_compliance.is_api_enabled(doc)", - "description": "Use APIs to compare records with GST Portal Data Before and After Filing", + "description": "Use APIs to compare records with GST Portal After Filing", "fieldname": "compare_gstr_1_data", "fieldtype": "Check", "label": "Compare Data with GST Portal" @@ -668,12 +669,19 @@ "label": "Default Reason for e-Invoice Cancellation", "mandatory_depends_on": "eval: doc.auto_cancel_e_invoice", "options": "Duplicate\nOrder Cancelled\nData Entry Mistake" + }, + { + "default": "1", + "description": "Use API to compare records with GST Portal Before Filing and upload Invoices ", + "fieldname": "compare_for_pre_upload", + "fieldtype": "Check", + "label": "Compare Data with GST Portal and Upload Invoices" } ], "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2024-12-12 19:09:07.185191", + "modified": "2024-12-24 11:00:01.686079", "modified_by": "Administrator", "module": "GST India", "name": "GST Settings", From d75f40ad4039f582ac6c5cb12c55ea5ba5e4edb5 Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Thu, 26 Dec 2024 22:54:59 +0530 Subject: [PATCH 4/5] fix: rename field and depends on --- .../gst_india/doctype/gst_return_log/generate_gstr_1.py | 7 ++++++- .../gst_india/doctype/gst_return_log/gst_return_log.py | 2 +- .../gst_india/doctype/gst_settings/gst_settings.json | 9 +++++---- 3 files changed, 12 insertions(+), 6 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 426079dd9c..dab30dc89c 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 @@ -595,7 +595,12 @@ def generate_only_books_data(self, data, filters, callback=None): # GET DATA def get_gov_gstr1_data(self): - if frappe.get_cached_value("GST Settings", None, "compare_for_pre_upload") != 1: + if ( + frappe.get_cached_value( + "GST Settings", None, "pre_filing_and_upload_invoices" + ) + != 1 + ): return frappe._dict(), False if self.filing_status == "Filed": diff --git a/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.py b/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.py index 78242336a3..418b92c95d 100644 --- a/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.py +++ b/india_compliance/gst_india/doctype/gst_return_log/gst_return_log.py @@ -195,7 +195,7 @@ def get_applicable_file_fields(self, settings=None): if self.filing_status == "Filed": fields.extend(["filed", "filed_summary"]) else: - if settings.compare_for_pre_upload: + if settings.pre_filing_and_upload_invoices: fields.extend(["unfiled", "unfiled_summary"]) return fields diff --git a/india_compliance/gst_india/doctype/gst_settings/gst_settings.json b/india_compliance/gst_india/doctype/gst_settings/gst_settings.json index 923966c6ad..ef9c217f64 100644 --- a/india_compliance/gst_india/doctype/gst_settings/gst_settings.json +++ b/india_compliance/gst_india/doctype/gst_settings/gst_settings.json @@ -48,7 +48,7 @@ "e_invoice_applicable_from", "e_invoice_applicable_companies", "gstr_1_section_break", - "compare_for_pre_upload", + "pre_filing_and_upload_invoices", "compare_gstr_1_data", "filing_frequency", "column_break_cxmn", @@ -672,8 +672,9 @@ }, { "default": "1", - "description": "Use API to compare records with GST Portal Before Filing and upload Invoices ", - "fieldname": "compare_for_pre_upload", + "depends_on": "eval: india_compliance.is_api_enabled(doc)", + "description": "Use API to compare records with GST Portal Before Filing and upload Invoices", + "fieldname": "pre_filing_and_upload_invoices", "fieldtype": "Check", "label": "Compare Data with GST Portal and Upload Invoices" } @@ -681,7 +682,7 @@ "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2024-12-24 11:00:01.686079", + "modified": "2024-12-26 22:44:14.011319", "modified_by": "Administrator", "module": "GST India", "name": "GST Settings", From 90c347059cc1c8ce1b27a79a85477fe19bdb36cf Mon Sep 17 00:00:00 2001 From: Sanket322 Date: Fri, 27 Dec 2024 12:05:32 +0530 Subject: [PATCH 5/5] fix: show upload button ap per gst settings --- .../gst_india/doctype/gstr_1_beta/gstr_1_beta.js | 5 +++++ 1 file changed, 5 insertions(+) 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 8548a62f94..31566daf88 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 @@ -490,6 +490,11 @@ class GSTR1 { }); } + if( + gst_settings.pre_filing_and_upload_invoices === 0 + && primary_button_label == "Upload" + ) return; + this.frm.page.set_primary_action(__(primary_button_label), () => actions[primary_button_label].call(this.gstr1_action) );