Skip to content

Commit

Permalink
Merge pull request #92 from nilpatel42/master
Browse files Browse the repository at this point in the history
Add Button : Get Alerts for Today
  • Loading branch information
shridarpatil authored Aug 19, 2024
2 parents 53609cc + a504d4e commit 0f56a42
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
});
});
}
});





Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

0 comments on commit 0f56a42

Please sign in to comment.