summaryrefslogtreecommitdiff
path: root/addons/event_sms/models/event_mail.py
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2021-03-19 13:30:15 +0000
committerThibault Delavallée <tde@odoo.com>2021-03-19 16:36:25 +0000
commit353bc5de9fafbc1527c382614e02438ee799c8a4 (patch)
treede28f9344bf2ae2dda0111c8ce16ba293a36a1a7 /addons/event_sms/models/event_mail.py
parent73d09268922a7d242af85e36a3d81ed25ab4ca33 (diff)
[FIX] event: respect scheduled date when calling mail schedulers execute
In this commit we ensure calling ``execute`` method on communication schedulers do not send emails or SMS if their scheduled date is still not achieved. Currently only the cron method does it (see ``run``). It is now safe to call ``execute`` directly on event communication schedulers. Related to Task ID-2414658 COM PR odoo/odoo#68158
Diffstat (limited to 'addons/event_sms/models/event_mail.py')
-rw-r--r--addons/event_sms/models/event_mail.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/addons/event_sms/models/event_mail.py b/addons/event_sms/models/event_mail.py
index 53562875f10..3e56a0552a7 100644
--- a/addons/event_sms/models/event_mail.py
+++ b/addons/event_sms/models/event_mail.py
@@ -36,7 +36,9 @@ class EventMailScheduler(models.Model):
now = fields.Datetime.now()
if mail.interval_type != 'after_sub':
# Do not send SMS if the communication was scheduled before the event but the event is over
- if not mail.mail_sent and (mail.interval_type != 'before_event' or mail.event_id.date_end > now) and mail.notification_type == 'sms' and mail.sms_template_id:
+ if not mail.mail_sent and mail.scheduled_date <= now and mail.notification_type == 'sms' and \
+ (mail.interval_type != 'before_event' or mail.event_id.date_end > now) and \
+ mail.sms_template_id:
self.env['event.registration']._message_sms_schedule_mass(
template=mail.sms_template_id,
active_domain=[('event_id', '=', mail.event_id.id), ('state', '!=', 'cancel')],
@@ -50,8 +52,18 @@ class EventMailRegistration(models.Model):
_inherit = 'event.mail.registration'
def execute(self):
- for record in self:
- if record.registration_id.state in ['open', 'done'] and not record.mail_sent and record.scheduler_id.notification_type == 'sms':
- record.registration_id._message_sms_schedule_mass(template=record.scheduler_id.sms_template_id, mass_keep_log=True)
- record.write({'mail_sent': True})
+ now = fields.Datetime.now()
+ todo = self.filtered(lambda reg_mail:
+ not reg_mail.mail_sent and \
+ reg_mail.registration_id.state in ['open', 'done'] and \
+ (reg_mail.scheduled_date and reg_mail.scheduled_date <= now) and \
+ reg_mail.scheduler_id.notification_type == 'sms'
+ )
+ for reg_mail in todo:
+ reg_mail.registration_id._message_sms_schedule_mass(
+ template=reg_mail.scheduler_id.sms_template_id,
+ mass_keep_log=True
+ )
+ todo.write({'mail_sent': True})
+
return super(EventMailRegistration, self).execute()