Skip to content

Commit

Permalink
fix: unique name for events and doctype parameter alone is redundant (#…
Browse files Browse the repository at this point in the history
…2903)

<sub><a href="https://huly.app/guest/resilienttech?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsaW5rSWQiOiI2NzY5NTQ2YWYxNDRmNTg1YWU0ZjQ0MzciLCJndWVzdCI6InRydWUiLCJlbWFpbCI6IiNndWVzdEBoYy5lbmdpbmVlcmluZyIsIndvcmtzcGFjZSI6Inctc21pdHZvcmEyMDMtcmVzaWxpZW50dGVjLTY2N2U0MjkxLWEwNWMwNjY4N2EtNjM4MjY3In0.rQ77T2lxpZdRqwFHPyoHa18VMzo4Qv2xyzoj9Jlr6fw">Huly&reg;: <b>IC-3030</b></a></sub>

(cherry picked from commit dc0be5d)

# Conflicts:
#	india_compliance/gst_india/doctype/gst_return_log/gst_return_log.py
#	india_compliance/gst_india/doctype/purchase_reconciliation_tool/purchase_reconciliation_tool.js
  • Loading branch information
Ninad1306 authored and mergify[bot] committed Jan 8, 2025
1 parent 8455e7d commit 0a94bb9
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,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 @@ -252,6 +252,40 @@ def _update_gstr_1_filed_upto(filing_date):
_update_gstr_1_filed_upto(filed_upto)


<<<<<<< HEAD
=======
def get_gst_return_log(posting_date, company_gstin):
period = getdate(posting_date).strftime("%m%Y")
if name := frappe.db.exists(DOCTYPE, f"GSTR1-{period}-{company_gstin}"):
return frappe.get_doc(DOCTYPE, name)


def add_comment_to_gst_return_log(doc, action):
if not (log := get_gst_return_log(doc.posting_date, doc.company_gstin)):
return

log.add_comment(
"Comment",
f"{doc.doctype} : {get_link_to_form(doc.doctype, doc.name)} has been {action} by {frappe.session.user}",
)


def update_is_not_latest_gstr1_data(posting_date, company_gstin):
period = posting_date.strftime("%m%Y")

frappe.db.set_value(
"GST Return Log", f"GSTR1-{period}-{company_gstin}", "is_latest_data", 0
)

frappe.publish_realtime(
"is_not_latest_gstr1_data",
message={"filters": {"company_gstin": company_gstin, "period": period}},
doctype="GSTR-1 Beta",
docname="GSTR-1 Beta",
)


>>>>>>> dc0be5df (fix: unique name for events and doctype parameter alone is redundant (#2903))
def get_file_doc(doctype, docname, attached_to_field):
try:
return frappe.get_doc(
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 @@ -140,7 +140,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 @@ -138,7 +138,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 @@ -159,7 +158,6 @@ def on_generate(self, data, filters=None):
"gstr1_data_prepared",
message={"data": data, "filters": filters},
user=frappe.session.user,
doctype=self.doctype,
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ frappe.ui.form.on("Purchase Reconciliation Tool", {
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 @@ -186,19 +186,19 @@ frappe.ui.form.on("Purchase Reconciliation Tool", {
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 @@ -214,7 +214,7 @@ frappe.ui.form.on("Purchase Reconciliation Tool", {
}
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 @@ -230,15 +230,20 @@ frappe.ui.form.on("Purchase Reconciliation Tool", {
});
},

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();
<<<<<<< HEAD
frappe.msgprint({
title: __("2A/2B Download Failed"),
message: message.error,
indicator: "red"
});
})
=======
frappe.msgprint(message);
});
>>>>>>> dc0be5df (fix: unique name for events and doctype parameter alone is redundant (#2903))
},
});

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 @@ -499,10 +500,13 @@ def download_pending_gstr_2(

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 @@ -87,7 +87,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 @@ -118,7 +117,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 @@ -135,14 +134,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 @@ -189,7 +187,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 @@ -318,13 +316,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 @@ -335,12 +338,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 @@ -63,13 +63,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

0 comments on commit 0a94bb9

Please sign in to comment.