Skip to content

Commit 93b8b58

Browse files
karm1000mergify[bot]
authored andcommitted
fix(gst-ims): enhance download job handling with job ID and alert for ongoing jobs
(cherry picked from commit 2e6cb95)
1 parent b986ea2 commit 93b8b58

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

india_compliance/gst_india/doctype/gst_invoice_management_system/gst_invoice_management_system.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -684,14 +684,21 @@ class IMSAction {
684684
}
685685

686686
async download_ims_data() {
687-
await taxpayer_api.call({
687+
const { message } = await taxpayer_api.call({
688688
method: `${DOC_PATH}.download_invoices`,
689689
args: { company_gstin: this.frm.doc.company_gstin },
690690
});
691691

692-
frappe.show_alert({
693-
message: __("Downloading Invoices"),
694-
});
692+
if (message?.message) {
693+
frappe.show_alert({
694+
message: message.message,
695+
indicator: message?.indicator || "blue",
696+
});
697+
} else {
698+
frappe.show_alert({
699+
message: __("Downloading Invoices"),
700+
});
701+
}
695702
}
696703

697704
async get_ims_data() {

india_compliance/gst_india/doctype/gst_invoice_management_system/gst_invoice_management_system.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from frappe.model.document import Document
77
from frappe.query_builder.functions import IfNull
88
from frappe.utils import add_to_date, format_date
9+
from frappe.utils.background_jobs import is_job_enqueued
910

1011
from india_compliance.gst_india.api_classes.taxpayer_base import (
1112
TaxpayerBaseAPI,
@@ -248,9 +249,23 @@ def get_link_options(self, doctype, filters):
248249
def download_invoices(company_gstin):
249250
frappe.has_permission("GST Invoice Management System", "write", throw=True)
250251

252+
job_id = f"gst_ims:{company_gstin}"
253+
254+
if is_job_enqueued(job_id):
255+
return {
256+
"message": _(
257+
"A download job is already in progress for the GSTIN - {0}"
258+
).format(company_gstin),
259+
}
260+
251261
TaxpayerBaseAPI(company_gstin).validate_auth_token()
252262

253-
frappe.enqueue(download_ims_invoices, queue="long", gstin=company_gstin)
263+
frappe.enqueue(
264+
download_ims_invoices,
265+
queue="long",
266+
gstin=company_gstin,
267+
job_id=job_id,
268+
)
254269

255270

256271
@frappe.whitelist()

0 commit comments

Comments
 (0)