From 588086235ea53d3a56dd11cfb3e0de6ad088e732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Hennecart?= Date: Tue, 8 Sep 2020 07:07:35 +0000 Subject: [PATCH] [FIX] base,calendar: fix calendar reminder The purpose of this commit is to have reliable calendar event reminder. Before, the reminders was not send directly and was instead put in mailing queue, which was leading to some delay. This is due do mail_notify_force_send context key being force to False when being in cron mode. However here we do not want to have calendar cron scheduling emails, then mailing cron sending them as it implies two delays. In order to try to send reminder mails as soon as possible compared to their schedule let us send mails directly during the calendar cron. Task ID-2331999 closes odoo/odoo#60598 X-original-commit: 232a3c4c65dd60215a5def010da8559a9ffb2378 Signed-off-by: Thibault Delavallee (tde) --- addons/calendar/models/calendar_alarm_manager.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/calendar/models/calendar_alarm_manager.py b/addons/calendar/models/calendar_alarm_manager.py index 2fb8ca1d099..83cdd1add40 100644 --- a/addons/calendar/models/calendar_alarm_manager.py +++ b/addons/calendar/models/calendar_alarm_manager.py @@ -115,10 +115,10 @@ class AlarmManager(models.AbstractModel): """ result = [] # TODO: remove event_maxdelta and if using it - if one_date - timedelta(minutes=(missing and 0 or event_maxdelta)) < fields.Datetime.now() + timedelta(seconds=in_the_next_X_seconds): # if an alarm is possible for this date + if one_date - timedelta(minutes=(missing * event_maxdelta)) < fields.Datetime.now() + timedelta(seconds=in_the_next_X_seconds): # if an alarm is possible for this date for alarm in event.alarm_ids: if alarm.alarm_type == alarm_type and \ - one_date - timedelta(minutes=(missing and 0 or alarm.duration_minutes)) < fields.Datetime.now() + timedelta(seconds=in_the_next_X_seconds) and \ + one_date - timedelta(minutes=(missing * alarm.duration_minutes)) < fields.Datetime.now() + timedelta(seconds=in_the_next_X_seconds) and \ (not after or one_date - timedelta(minutes=alarm.duration_minutes) > fields.Datetime.from_string(after)): alert = { 'alarm_id': alarm.id, @@ -134,6 +134,7 @@ class AlarmManager(models.AbstractModel): @api.model def _get_partner_next_mail(self, partners=None): + self = self.with_context(mail_notify_force_send=True) last_notif_mail = fields.Datetime.to_string(self.env.context.get('lastcall') or fields.Datetime.now()) cron = self.env.ref('calendar.ir_cron_scheduler_alarm', raise_if_not_found=False)