[FIX] calendar_sms: send reminder sms

Steps to reproduce:
- Create a contact with email address and mobile number set.
- In Calendar > Reminders, create a reminder of type SMS and one of type Email (e.g. 24 hours before the event).
- Create an event, with the created contact as attendee, and the SMS and Email reminders you have created.
- Less than 24 hours before the event, run manually the scheduled action « Calendar : Event Reminder ».
- Go to Technical > Messages. You’ll see that the email reminder was triggered, but no SMS was sent. It seems the scheduled action doesn’t have any effect on the SMS type of reminder.

Solution:
In the `_send_reminder()` method, there was a confusion between alarm_id and event_id.
The correction has been made so it considers every events returned by the sql-query for which there is a `sms` reminder set and use the correct alarm_id for this event. (https://github.com/odoo/odoo/blob/543af27c7d6836ffac9e80ff8490b6ddbd849221/addons/calendar/models/calendar_alarm_manager.py#L149-L161)
Please note that in comparison with the email reminder there is no check for attendency (https://github.com/odoo/odoo/blob/543af27c7d6836ffac9e80ff8490b6ddbd849221/addons/calendar/models/calendar_alarm_manager.py#L177)
-> That is because this check is done a little further in the code. See: https://github.com/odoo/odoo/blob/744ad956f944065cf98fd89e3d1078de32569897/addons/calendar_sms/models/calendar_event.py#L10-L14

closes odoo/odoo#81438

X-original-commit: d14c708405bacb2935bcd6a11966816b50e3e477
Signed-off-by: Arnaud Joset <arj@odoo.com>
Signed-off-by: yosa-odoo <yosa@odoo.com>
This commit is contained in:
Yolann Sabaux
2021-12-16 09:00:19 +00:00
parent 16f63fa55b
commit 2e10595925
@@ -12,13 +12,13 @@ class AlarmManager(models.AbstractModel):
""" Cron method, overridden here to send SMS reminders as well
"""
super()._send_reminder()
alarms_by_event = self._get_events_by_alarm_to_notify('sms')
if not alarms_by_event:
events_by_alarm = self._get_events_by_alarm_to_notify('sms')
if not events_by_alarm:
return
events = self.env['calendar.event'].browse(list(alarms_by_event.keys()))
attendees = events.attendee_ids.filtered(lambda a: a.state != 'declined')
for event_id in alarms_by_event.keys():
event_alarms = attendees.event_id.alarm_ids.filtered(lambda alarm: alarm.id in alarms_by_event.get(event_id, []))
for alarm in event_alarms:
events.browse(event_id)._do_sms_reminder(alarm)
event_ids = list(set(event_id for event_ids in events_by_alarm.values() for event_id in event_ids))
events = self.env['calendar.event'].browse(event_ids)
alarms = self.env['calendar.alarm'].browse(events_by_alarm.keys())
for event in events:
alarm = event.alarm_ids.filtered(lambda alarm: alarm.id in alarms.ids)
event._do_sms_reminder(alarm)