Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Button : Get Alerts for Today #92

Merged
merged 11 commits into from
Aug 19, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,34 @@ 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) {
console.log(response.message);
nilpatel42 marked this conversation as resolved.
Show resolved Hide resolved
nilpatel42 marked this conversation as resolved.
Show resolved Hide resolved
} else {
frappe.msgprint(__('No alerts for today'));
}
},
error: function (error) {
console.error('Error:', error);
nilpatel42 marked this conversation as resolved.
Show resolved Hide resolved
nilpatel42 marked this conversation as resolved.
Show resolved Hide resolved
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
nilpatel42 marked this conversation as resolved.
Show resolved Hide resolved
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()