Skip to content

Commit

Permalink
refactory: for whatsapp notification scheduled, must be setted on hoo…
Browse files Browse the repository at this point in the history
…ks.py
  • Loading branch information
HarryPaulo committed Jan 7, 2025
1 parent 78b3d7d commit 0f9e8eb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,24 +235,8 @@ def notify(self, data):

def on_trash(self):
"""On delete remove from schedule."""
if self.notification_type == "Scheduler Event":
frappe.delete_doc("Scheduled Job Type", self.name)

frappe.cache().delete_value("whatsapp_notification_map")

def after_insert(self):
"""After insert hook."""
if self.notification_type == "Scheduler Event":
method = f"frappe_whatsapp.utils.trigger_whatsapp_notifications_{self.event_frequency.lower().replace(' ', '_')}" # noqa
job = frappe.get_doc(
{
"doctype": "Scheduled Job Type",
"method": method,
"frequency": self.event_frequency
}
)

job.insert()

def format_number(self, number):
"""Format number."""
Expand Down
40 changes: 28 additions & 12 deletions frappe_whatsapp/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,34 @@
# ---------------

scheduler_events = {
# "all": [
# "frappe_whatsapp.tasks.all"
# ],
"daily": [
"frappe_whatsapp.frappe_whatsapp.doctype.whatsapp_notification.whatsapp_notification.trigger_notifications"
],
# "weekly": [
# "frappe_whatsapp.tasks.weekly"
# ],
# "monthly": [
# "frappe_whatsapp.tasks.monthly"
# ],
"all": [
"frappe_whatsapp.utils.trigger_whatsapp_notifications_all"
],
"hourly": [
"frappe_whatsapp.utils.trigger_whatsapp_notifications_hourly"
],
"hourly_long": [
"frappe_whatsapp.utils.trigger_whatsapp_notifications_hourly_long"
],
"daily": [
"frappe_whatsapp.utils.trigger_whatsapp_notifications_daily",
"frappe_whatsapp.frappe_whatsapp.doctype.whatsapp_notification.whatsapp_notification.trigger_notifications",
],
"daily_long": [
"frappe_whatsapp.utils.trigger_whatsapp_notifications_daily_long",
],
"weekly": [
"frappe_whatsapp.utils.trigger_whatsapp_notifications_weekly",
],
"weekly_long": [
"frappe_whatsapp.utils.trigger_whatsapp_notifications_weekly_long",
],
"monthly": [
"frappe_whatsapp.utils.trigger_whatsapp_notifications_monthly",
],
"monthly_long": [
"frappe_whatsapp.utils.trigger_whatsapp_notifications_monthly_long",
],
}

# Testing
Expand Down

0 comments on commit 0f9e8eb

Please sign in to comment.