[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) <tde@openerp.com>
This commit is contained in:
Jérémy Hennecart
2020-10-23 09:08:54 +00:00
committed by Thibault Delavallée
parent 6c280e1fd8
commit 588086235e
@@ -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)