diff --git a/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_notification/whatsapp_notification.js b/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_notification/whatsapp_notification.js index d73ad38..a8ae7c5 100644 --- a/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_notification/whatsapp_notification.js +++ b/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_notification/whatsapp_notification.js @@ -107,3 +107,32 @@ frappe.ui.form.on('WhatsApp Notification', { frappe.notification.setup_fieldname_select(frm); }, }); + + + +frappe.ui.form.on('WhatsApp Notification', { + refresh: function (frm) { + frm.add_custom_button(__('Get Alerts for Today'), function () { + frappe.call({ + method: 'frappe_whatsapp.frappe_whatsapp.doctype.whatsapp_notification.whatsapp_notification.call_trigger_notifications', + args: { + method: 'daily' + }, + callback: function (response) { + if (response.message && response.message.length > 0) { + } else { + frappe.msgprint(__('No alerts for today')); + } + }, + error: function (error) { + frappe.msgprint(__('Failed to trigger notifications')); + } + }); + }); + } +}); + + + + + diff --git a/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_notification/whatsapp_notification.py b/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_notification/whatsapp_notification.py index 75f634f..5caa3a7 100644 --- a/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_notification/whatsapp_notification.py +++ b/frappe_whatsapp/frappe_whatsapp/doctype/whatsapp_notification/whatsapp_notification.py @@ -289,6 +289,18 @@ def get_documents_for_today(self): # print(doc.name) +@frappe.whitelist() +def call_trigger_notifications(): + """Trigger notifications.""" + try: + # Directly call the trigger_notifications function + trigger_notifications() + except Exception as e: + # Log the error but do not show any popup or alert + frappe.log_error(frappe.get_traceback(), "Error in call_trigger_notifications") + # Optionally, you could raise the exception to be handled elsewhere if needed + raise e + def trigger_notifications(method="daily"): if frappe.flags.in_import or frappe.flags.in_patch: # don't send notifications while syncing or patching @@ -300,5 +312,5 @@ def trigger_notifications(method="daily"): ) for d in doc_list: alert = frappe.get_doc("WhatsApp Notification", d.name) - alert.get_documents_for_today() + \ No newline at end of file