Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unique name for events and doctype parameter alone is redundant #2903

Merged
merged 5 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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_gst_credentials_message",
dict(
message=_(
"Credentials are missing for GSTIN {0} for service"
Expand Down Expand Up @@ -303,9 +303,10 @@ 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",
docname="GSTR-1 Beta",
)


Expand Down
4 changes: 2 additions & 2 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 @@ -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] =
Expand All @@ -143,7 +143,7 @@ frappe.ui.form.on(DOCTYPE, {
);
});

frappe.realtime.on("show_message", message => {
frappe.realtime.on("show_missing_gst_credentials_message", message => {
frappe.msgprint(message);
});

Expand Down
2 changes: 0 additions & 2 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 @@ -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
Expand All @@ -163,7 +162,6 @@ def on_generate(self, filters=None):
"gstr1_data_prepared",
message={"filters": filters},
user=frappe.session.user,
doctype=self.doctype,
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +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_download_message(frm);
},

onload(frm) {
Expand Down Expand Up @@ -189,19 +189,19 @@ 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");
}
},

update_progress(frm, method) {
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,
Expand All @@ -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(() => {
Expand All @@ -233,14 +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",
});
frappe.msgprint(message);
});
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -472,10 +473,13 @@ 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,
doctype="Purchase Reconciliation Tool",
)


Expand Down
1 change: 0 additions & 1 deletion india_compliance/gst_india/utils/gstr_1/gstr_1_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 17 additions & 15 deletions india_compliance/gst_india/utils/gstr_2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -116,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)
Expand All @@ -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)
Expand Down Expand Up @@ -185,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)
Expand Down Expand Up @@ -302,13 +300,18 @@ 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.<br><br>"
"You can track download status from download dialog."
)
def publish_queued_message():
frappe.publish_realtime(
"gstr_2a_2b_download_message",
{
"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.<br><br>"
"You can track download status from download dialog."
),
},
user=frappe.session.user,
)


Expand All @@ -319,12 +322,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",
)
3 changes: 1 addition & 2 deletions india_compliance/gst_india/utils/gstr_2/gstr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading