diff --git a/frappe/email/doctype/email_queue/email_queue.js b/frappe/email/doctype/email_queue/email_queue.js index eeac20ada3..d68dff11bc 100644 --- a/frappe/email/doctype/email_queue/email_queue.js +++ b/frappe/email/doctype/email_queue/email_queue.js @@ -26,13 +26,18 @@ frappe.ui.form.on("Email Queue", { } else if (frm.doc.status == "Error") { frm.add_custom_button("Retry Sending", function () { frm.call({ - method: "retry_sending", - doc: frm.doc, + method: "frappe.email.doctype.email_queue.email_queue.retry_sending", args: { - name: frm.doc.name, + queues: [frm.doc.name], }, callback: function () { frm.reload_doc(); + frappe.show_alert({ + message: __( + "Status Updated. The email will be picked up in the next scheduled run." + ), + indicator: "green", + }); }, }); }); diff --git a/frappe/email/doctype/email_queue/email_queue.py b/frappe/email/doctype/email_queue/email_queue.py index 8f02a6e5f2..d42c3ce97e 100644 --- a/frappe/email/doctype/email_queue/email_queue.py +++ b/frappe/email/doctype/email_queue/email_queue.py @@ -222,12 +222,6 @@ class EmailQueue(Document): .where(email_recipient.creation < (Now() - Interval(days=days))) ).run() - @frappe.whitelist() - def retry_sending(self): - if self.status == "Error": - self.status = "Not Sent" - self.save(ignore_permissions=True) - @task(queue="short") @deprecated @@ -440,8 +434,9 @@ class SendMailContext: @frappe.whitelist() -def bulk_retry(queues): - frappe.only_for("System Manager") +def retry_sending(queues: str | list[str]): + if not frappe.has_permission("Email Queue", throw=True): + return if isinstance(queues, str): queues = json.loads(queues) @@ -449,11 +444,8 @@ def bulk_retry(queues): if not queues: return - frappe.msgprint( - _("Updating Email Queue Statuses. The emails will be picked up in the next scheduled run."), - _("Processing..."), - ) - + # NOTE: this will probably work fine with the way current listview works (showing and selecting 20-20 records) + # but, ideally this should be enqueued email_queue = frappe.qb.DocType("Email Queue") frappe.qb.update(email_queue).set(email_queue.status, "Not Sent").set(email_queue.modified, now()).set( email_queue.modified_by, frappe.session.user diff --git a/frappe/email/doctype/email_queue/email_queue_list.js b/frappe/email/doctype/email_queue/email_queue_list.js index fde7ddf7f3..45d606777e 100644 --- a/frappe/email/doctype/email_queue/email_queue_list.js +++ b/frappe/email/doctype/email_queue/email_queue_list.js @@ -45,8 +45,15 @@ function show_toggle_sending_button(list_view) { function add_bulk_retry_button_to_actions(list_view) { list_view.page.add_actions_menu_item(__("Retry Sending"), () => { + frappe.msgprint( + __( + "Updating Email Queue Statuses. The emails will be picked up in the next scheduled run." + ), + __("Processing...") + ); + frappe.call({ - method: "frappe.email.doctype.email_queue.email_queue.bulk_retry", + method: "frappe.email.doctype.email_queue.email_queue.retry_sending", args: { queues: list_view.get_checked_items(true), },