diff --git a/erpnext/setup/doctype/email_digest/email_digest.js b/erpnext/setup/doctype/email_digest/email_digest.js index c0a887e4b11..1d5c9d2fa12 100644 --- a/erpnext/setup/doctype/email_digest/email_digest.js +++ b/erpnext/setup/doctype/email_digest/email_digest.js @@ -5,23 +5,33 @@ frappe.ui.form.on("Email Digest", { refresh: function (frm) { if (!frm.is_new()) { frm.add_custom_button(__("View Now"), function () { - frappe.call({ - method: "erpnext.setup.doctype.email_digest.email_digest.get_digest_msg", - args: { - name: frm.doc.name, - }, - callback: function (r) { - let d = new frappe.ui.Dialog({ - title: __("Email Digest: {0}", [frm.doc.name]), - width: 800, - }); - $(d.body).html(r.message); - d.show(); - }, + if (frm.is_dirty()) { + frappe.show_alert({ + message: __("Save the Email Digest first.", "yellow"), + indicator: "yellow", + }); + return; + } + + frm.call("get_digest_msg").then((r) => { + let d = new frappe.ui.Dialog({ + title: __("Email Digest: {0}", [frm.doc.name]), + width: 800, + }); + $(d.body).html(r.message); + d.show(); }); }); frm.add_custom_button(__("Send Now"), function () { + if (frm.is_dirty()) { + frappe.show_alert({ + message: __("Save the Email Digest first.", "yellow"), + indicator: "yellow", + }); + return; + } + return frm.call("send", null, () => { frappe.show_alert({ message: __("Message Sent"), indicator: "green" }); }); diff --git a/erpnext/setup/doctype/email_digest/email_digest.py b/erpnext/setup/doctype/email_digest/email_digest.py index 214ef288b03..d5eb87b3d4e 100644 --- a/erpnext/setup/doctype/email_digest/email_digest.py +++ b/erpnext/setup/doctype/email_digest/email_digest.py @@ -944,6 +944,10 @@ class EmailDigest(Document): return items_by_parent + @frappe.whitelist() + def get_digest_msg(self): + return self.get_msg_html() + def send(): now_date = now_datetime().date() @@ -956,11 +960,6 @@ def send(): ed_obj.send() -@frappe.whitelist() -def get_digest_msg(name: str): - return frappe.get_doc("Email Digest", name).get_msg_html() - - def get_incomes_expenses_for_period(account, from_date, to_date): """Get amounts for current and past periods"""