Files
odoo_source/addons/calendar_sms/models/calendar_event.py
T
Yolann Sabaux 842c279e1d [FIX] calendar_sms: send sms to partner with phone numbers
Steps to reproduce:
- create a contact with a phone number
- enable IAP-sms
- take off the number of the admin-contact
- create an event in the calendar with a "text-sms reminder" with the new created user

Issue:
No sms will be sent

Cause:
The IAP server-side does not accept request with `number` set to False such as in:
```{'messages': [{'res_id': 23, 'number': False, 'content': 'Event reminder: test-local, 07/11/2022 at (15:46:00 To 16:46:00) (Europe/Brussels)'}, {'res_id': 24, 'number': '+32487253270', 'content': 'Event reminder: test-local, 07/1>

Solution:
Filter partners with a valid phone number in `_sms_get_default_partner`

opw-2867763

closes odoo/odoo#99697

X-original-commit: 512010cfeb80fd6f5511888ddbd58dd26212105b
Signed-off-by: Yolann Sabaux (yosa) <yosa@odoo.com>
Signed-off-by: Arnaud Joset <arj@odoo.com>
2022-09-08 09:38:35 +02:00

45 lines
1.7 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models, _
from odoo.exceptions import UserError
class CalendarEvent(models.Model):
_inherit = 'calendar.event'
def _sms_get_default_partners(self):
""" Method overridden from mail.thread (defined in the sms module).
SMS text messages will be sent to attendees that haven't declined the event(s).
"""
return self.mapped('attendee_ids').filtered(lambda att: att.state != 'declined' and att.partner_id.phone_sanitized).mapped('partner_id')
def _do_sms_reminder(self, alarm):
""" Send an SMS text reminder to attendees that haven't declined the event """
for event in self:
event._message_sms_with_template(
template=alarm.sms_template_id,
template_fallback=_("Event reminder: %(name)s, %(time)s.", name=event.name, time=event.display_time),
partner_ids=self._sms_get_default_partners().ids,
put_in_queue=False
)
def action_send_sms(self):
if not self.partner_ids:
raise UserError(_("There are no attendees on these events"))
return {
'type': 'ir.actions.act_window',
'name': _("Send SMS Text Message"),
'res_model': 'sms.composer',
'view_mode': 'form',
'target': 'new',
'context': {
'default_composition_mode': 'mass',
'default_res_model': 'res.partner',
'default_res_ids': self.partner_ids.ids,
'default_mass_keep_log': True,
},
}
def _get_trigger_alarm_types(self):
return super()._get_trigger_alarm_types() + ['sms']