From 5759810dd53de11cf05bf0ce0cf5598e847a57c3 Mon Sep 17 00:00:00 2001 From: Ninad1306 Date: Mon, 23 Dec 2024 17:44:14 +0530 Subject: [PATCH 1/5] fix: unique name for events and doctype parameter alone is redundant --- .../gst_india/doctype/gst_return_log/gst_return_log.py | 5 ++--- .../gst_india/doctype/gstr_1_beta/gstr_1_beta.js | 4 ++-- .../gst_india/doctype/gstr_1_beta/gstr_1_beta.py | 2 -- .../purchase_reconciliation_tool.js | 10 +++++----- .../purchase_reconciliation_tool.py | 1 - .../gst_india/utils/gstr_1/gstr_1_download.py | 1 - india_compliance/gst_india/utils/gstr_2/__init__.py | 9 +++------ india_compliance/gst_india/utils/gstr_2/gstr.py | 3 +-- 8 files changed, 13 insertions(+), 22 deletions(-) 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..0f8c7ce959 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 @@ -134,7 +134,7 @@ def is_gstr1_api_enabled(self, settings=None, warn_for_missing_credentials=False if not settings.has_valid_credentials(self.gstin, "Returns"): if warn_for_missing_credentials: frappe.publish_realtime( - "show_message", + "show_missing_credentials_message", dict( message=_( "Credentials are missing for GSTIN {0} for service" @@ -303,9 +303,8 @@ def update_is_not_latest_gstr1_data(posting_date, company_gstin): ) frappe.publish_realtime( - "is_not_latest_data", + "is_not_latest_gstr1_data", message={"filters": {"company_gstin": company_gstin, "period": period}}, - doctype="GSTR-1 Beta", ) 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..31d6665f54 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 @@ -118,7 +118,7 @@ frappe.ui.form.on(DOCTYPE, { frm.__setup_complete = true; // Setup Listeners - frappe.realtime.on("is_not_latest_data", message => { + frappe.realtime.on("is_not_latest_gstr1_data", message => { const { filters } = message; const [month_or_quarter, year] = @@ -143,7 +143,7 @@ frappe.ui.form.on(DOCTYPE, { ); }); - frappe.realtime.on("show_message", message => { + frappe.realtime.on("show_missing_credentials_message", message => { frappe.msgprint(message); }); 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..445d89d1d2 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 @@ -142,7 +142,6 @@ def _generate_gstr1(self): "gstr1_generation_failed", message={"error": str(e), "filters": filters}, user=frappe.session.user, - doctype=self.doctype, ) raise e @@ -163,7 +162,6 @@ def on_generate(self, filters=None): "gstr1_data_prepared", message={"filters": filters}, user=frappe.session.user, - doctype=self.doctype, ) diff --git a/india_compliance/gst_india/doctype/purchase_reconciliation_tool/purchase_reconciliation_tool.js b/india_compliance/gst_india/doctype/purchase_reconciliation_tool/purchase_reconciliation_tool.js index b8b37a27f7..2722f64c01 100644 --- a/india_compliance/gst_india/doctype/purchase_reconciliation_tool/purchase_reconciliation_tool.js +++ b/india_compliance/gst_india/doctype/purchase_reconciliation_tool/purchase_reconciliation_tool.js @@ -189,11 +189,11 @@ frappe.ui.form.on(DOCTYPE, { show_progress(frm, type) { if (type == "download") { frappe.run_serially([ - () => frm.events.update_progress(frm, "update_api_progress"), - () => frm.events.update_progress(frm, "update_transactions_progress"), + () => frm.events.update_progress(frm, "update_2a_2b_api_progress"), + () => frm.events.update_progress(frm, "update_2a_2b_transactions_progress"), ]); } else if (type == "upload") { - frm.events.update_progress(frm, "update_transactions_progress"); + frm.events.update_progress(frm, "update_2a_2b_transactions_progress"); } }, @@ -201,7 +201,7 @@ frappe.ui.form.on(DOCTYPE, { frappe.realtime.on(method, data => { const { current_progress } = data; const message = - method == "update_api_progress" + method == "update_2a_2b_api_progress" ? __("Fetching data from GSTN") : __("Updating Inward Supply for Return Period {0}", [ data.return_period, @@ -217,7 +217,7 @@ frappe.ui.form.on(DOCTYPE, { } if ( current_progress === 100 && - method != "update_api_progress" && + method != "update_2a_2b_api_progress" && frm.flag_last_return_period == data.return_period ) { setTimeout(() => { diff --git a/india_compliance/gst_india/doctype/purchase_reconciliation_tool/purchase_reconciliation_tool.py b/india_compliance/gst_india/doctype/purchase_reconciliation_tool/purchase_reconciliation_tool.py index e9dc84c188..eea1ff8afd 100644 --- a/india_compliance/gst_india/doctype/purchase_reconciliation_tool/purchase_reconciliation_tool.py +++ b/india_compliance/gst_india/doctype/purchase_reconciliation_tool/purchase_reconciliation_tool.py @@ -475,7 +475,6 @@ def download_gstr( "gstr_2a_2b_download_failed", {"error": str(e)}, user=frappe.session.user, - doctype="Purchase Reconciliation Tool", ) 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 d6366e9648..e46c211296 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 @@ -84,7 +84,6 @@ def download_gstr1_json_data(gstr1_log): "gstr1_queued", message={"gstin": gstin, "return_period": return_period}, user=frappe.session.user, - doctype="GSTR-1 Beta", ) return mapped_data, is_queued diff --git a/india_compliance/gst_india/utils/gstr_2/__init__.py b/india_compliance/gst_india/utils/gstr_2/__init__.py index 6efdf64a4b..8b38af8538 100644 --- a/india_compliance/gst_india/utils/gstr_2/__init__.py +++ b/india_compliance/gst_india/utils/gstr_2/__init__.py @@ -59,14 +59,13 @@ def download_gstr_2a(gstin, return_periods, gst_categories=None): requests_made += 1 frappe.publish_realtime( - "update_api_progress", + "update_2a_2b_api_progress", { "current_progress": requests_made * 100 / total_expected_requests, "return_period": return_period, "is_last_period": is_last_period, }, user=frappe.session.user, - doctype="Purchase Reconciliation Tool", ) if gst_categories and category.value not in gst_categories: @@ -133,14 +132,13 @@ def download_gstr_2b(gstin, return_periods): is_last_period = return_periods[-1] == return_period requests_made += 1 frappe.publish_realtime( - "update_api_progress", + "update_2a_2b_api_progress", { "current_progress": requests_made * 100 / total_expected_requests, "return_period": return_period, "is_last_period": is_last_period, }, user=frappe.session.user, - doctype="Purchase Reconciliation Tool", ) response = api.get_data(return_period) @@ -319,12 +317,11 @@ def end_transaction_progress(return_period): """ frappe.publish_realtime( - "update_transactions_progress", + "update_2a_2b_transactions_progress", { "current_progress": 100, "return_period": return_period, "is_last_period": True, }, user=frappe.session.user, - doctype="Purchase Reconciliation Tool", ) diff --git a/india_compliance/gst_india/utils/gstr_2/gstr.py b/india_compliance/gst_india/utils/gstr_2/gstr.py index 7677e0a767..ce284940b1 100644 --- a/india_compliance/gst_india/utils/gstr_2/gstr.py +++ b/india_compliance/gst_india/utils/gstr_2/gstr.py @@ -62,13 +62,12 @@ def create_transactions(self, category, suppliers): current_transaction += 1 frappe.publish_realtime( - "update_transactions_progress", + "update_2a_2b_transactions_progress", { "current_progress": current_transaction * 100 / total_transactions, "return_period": self.return_period, }, user=frappe.session.user, - doctype="Purchase Reconciliation Tool", ) if transaction.get("unique_key") in self.existing_transaction: From c9df931586bd6b1c4edb552c34f48130cd98ce2e Mon Sep 17 00:00:00 2001 From: Ninad1306 Date: Tue, 24 Dec 2024 12:59:04 +0530 Subject: [PATCH 2/5] fix: message should be published as download is enqueued --- .../purchase_reconciliation_tool.js | 10 +++++++++ .../gst_india/utils/gstr_2/__init__.py | 22 +++++++++++-------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/india_compliance/gst_india/doctype/purchase_reconciliation_tool/purchase_reconciliation_tool.js b/india_compliance/gst_india/doctype/purchase_reconciliation_tool/purchase_reconciliation_tool.js index 2722f64c01..1535ba9f26 100644 --- a/india_compliance/gst_india/doctype/purchase_reconciliation_tool/purchase_reconciliation_tool.js +++ b/india_compliance/gst_india/doctype/purchase_reconciliation_tool/purchase_reconciliation_tool.js @@ -73,6 +73,7 @@ frappe.ui.form.on(DOCTYPE, { frm.purchase_reconciliation_tool = new PurchaseReconciliationTool(frm); frm.events.handle_download_failure(frm); + frm.events.handle_queued_download(); }, onload(frm) { @@ -243,6 +244,15 @@ frappe.ui.form.on(DOCTYPE, { }); }); }, + + handle_queued_download() { + frappe.realtime.on("gstr_2a_2b_download_queued", message => { + frappe.msgprint({ + title: __("2A/2B Download Queued"), + message: message.msg, + }); + }); + }, }); class PurchaseReconciliationTool { diff --git a/india_compliance/gst_india/utils/gstr_2/__init__.py b/india_compliance/gst_india/utils/gstr_2/__init__.py index 8b38af8538..956047a031 100644 --- a/india_compliance/gst_india/utils/gstr_2/__init__.py +++ b/india_compliance/gst_india/utils/gstr_2/__init__.py @@ -115,7 +115,7 @@ def download_gstr_2a(gstin, return_periods, gst_categories=None): save_gstr_2a(gstin, return_period, json_data) if queued_message: - show_queued_message() + publish_queued_message() if not has_data: end_transaction_progress(return_period) @@ -183,7 +183,7 @@ def download_gstr_2b(gstin, return_periods): save_gstr_2b(gstin, return_period, response) if queued_message: - show_queued_message() + publish_queued_message() if not has_data: end_transaction_progress(return_period) @@ -300,13 +300,17 @@ def _download_gstr_2a(gstin, return_period, json_data): save_gstr_2a(gstin, return_period, json_data) -def show_queued_message(): - frappe.msgprint( - _( - "Some returns are queued for download at GSTN as there may be large data." - " We will retry download every few minutes until it succeeds.

" - "You can track download status from download dialog." - ) +def publish_queued_message(): + frappe.publish_realtime( + "gstr_2a_2b_download_queued", + { + "msg": _( + "Some returns are queued for download at GSTN as there may be large data." + " We will retry download every few minutes until it succeeds.

" + "You can track download status from download dialog." + ), + }, + user=frappe.session.user, ) From 23e94126073a4be0c46e21e2de04f4ebfde1c297 Mon Sep 17 00:00:00 2001 From: Ninad1306 Date: Thu, 26 Dec 2024 14:58:39 +0530 Subject: [PATCH 3/5] fix: more specific message related to functionality --- .../gst_india/doctype/gst_return_log/gst_return_log.py | 2 +- india_compliance/gst_india/doctype/gstr_1_beta/gstr_1_beta.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 0f8c7ce959..39febdc583 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 @@ -134,7 +134,7 @@ def is_gstr1_api_enabled(self, settings=None, warn_for_missing_credentials=False if not settings.has_valid_credentials(self.gstin, "Returns"): if warn_for_missing_credentials: frappe.publish_realtime( - "show_missing_credentials_message", + "show_missing_gst_credentials_message", dict( message=_( "Credentials are missing for GSTIN {0} for service" 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 31d6665f54..4af092fb23 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 @@ -143,7 +143,7 @@ frappe.ui.form.on(DOCTYPE, { ); }); - frappe.realtime.on("show_missing_credentials_message", message => { + frappe.realtime.on("show_missing_gst_credentials_message", message => { frappe.msgprint(message); }); From a700eb83c68159e2c0690ffbb73694700e3f5c6a Mon Sep 17 00:00:00 2001 From: Smit Vora Date: Wed, 8 Jan 2025 14:24:20 +0530 Subject: [PATCH 4/5] refactor: common listener for queued and failure --- .../purchase_reconciliation_tool.js | 22 ++++--------------- .../purchase_reconciliation_tool.py | 9 ++++++-- .../gst_india/utils/gstr_2/__init__.py | 5 +++-- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/india_compliance/gst_india/doctype/purchase_reconciliation_tool/purchase_reconciliation_tool.js b/india_compliance/gst_india/doctype/purchase_reconciliation_tool/purchase_reconciliation_tool.js index 1535ba9f26..2536225abb 100644 --- a/india_compliance/gst_india/doctype/purchase_reconciliation_tool/purchase_reconciliation_tool.js +++ b/india_compliance/gst_india/doctype/purchase_reconciliation_tool/purchase_reconciliation_tool.js @@ -72,8 +72,7 @@ frappe.ui.form.on(DOCTYPE, { frm.trigger("company"); frm.purchase_reconciliation_tool = new PurchaseReconciliationTool(frm); - frm.events.handle_download_failure(frm); - frm.events.handle_queued_download(); + frm.events.handle_download_message(frm); }, onload(frm) { @@ -234,23 +233,10 @@ frappe.ui.form.on(DOCTYPE, { }); }, - handle_download_failure(frm) { - frappe.realtime.on("gstr_2a_2b_download_failed", message => { + handle_download_message(frm) { + frappe.realtime.on("gstr_2a_2b_download_message", message => { frm.dashboard.hide(); - frappe.msgprint({ - title: __("2A/2B Download Failed"), - message: message.error, - indicator: "red", - }); - }); - }, - - handle_queued_download() { - frappe.realtime.on("gstr_2a_2b_download_queued", message => { - frappe.msgprint({ - title: __("2A/2B Download Queued"), - message: message.msg, - }); + frappe.msgprint(message); }); }, }); diff --git a/india_compliance/gst_india/doctype/purchase_reconciliation_tool/purchase_reconciliation_tool.py b/india_compliance/gst_india/doctype/purchase_reconciliation_tool/purchase_reconciliation_tool.py index eea1ff8afd..5c5b5c9e76 100644 --- a/india_compliance/gst_india/doctype/purchase_reconciliation_tool/purchase_reconciliation_tool.py +++ b/india_compliance/gst_india/doctype/purchase_reconciliation_tool/purchase_reconciliation_tool.py @@ -6,6 +6,7 @@ from typing import List import frappe +from frappe import _ from frappe.model.document import Document from frappe.query_builder.functions import IfNull from frappe.utils import add_to_date, cint, now_datetime @@ -472,8 +473,12 @@ def download_gstr( except Exception as e: frappe.publish_realtime( - "gstr_2a_2b_download_failed", - {"error": str(e)}, + "gstr_2a_2b_download_message", + { + "title": _("2A/2B Download Failed"), + "message": str(e), + "indicator": "red", + }, user=frappe.session.user, ) diff --git a/india_compliance/gst_india/utils/gstr_2/__init__.py b/india_compliance/gst_india/utils/gstr_2/__init__.py index 956047a031..01ad6d012b 100644 --- a/india_compliance/gst_india/utils/gstr_2/__init__.py +++ b/india_compliance/gst_india/utils/gstr_2/__init__.py @@ -302,9 +302,10 @@ def _download_gstr_2a(gstin, return_period, json_data): def publish_queued_message(): frappe.publish_realtime( - "gstr_2a_2b_download_queued", + "gstr_2a_2b_download_message", { - "msg": _( + "title": _("2A/2B Download Queued"), + "message": _( "Some returns are queued for download at GSTN as there may be large data." " We will retry download every few minutes until it succeeds.

" "You can track download status from download dialog." From 51cfa462e2bac09657a603b789d160cb5fdfb56e Mon Sep 17 00:00:00 2001 From: Smit Vora Date: Wed, 8 Jan 2025 14:31:05 +0530 Subject: [PATCH 5/5] fix: linters to have a specific room for latest gstr1 data --- .../gst_india/doctype/gst_return_log/gst_return_log.py | 2 ++ 1 file changed, 2 insertions(+) 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 39febdc583..08bfec9606 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 @@ -305,6 +305,8 @@ def update_is_not_latest_gstr1_data(posting_date, company_gstin): frappe.publish_realtime( "is_not_latest_gstr1_data", message={"filters": {"company_gstin": company_gstin, "period": period}}, + doctype="GSTR-1 Beta", + docname="GSTR-1 Beta", )