Files
odoo_source/addons/calendar_sms/models/calendar.py
T
Julien Castiaux 193fee519c [FIX] calendar: missing cron compat fom sms_calendar
Fine tunning of c8f031ad77, this commit has the missing code
compatibility for sms_calendar.

closes odoo/odoo#65064

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-01-29 15:38:24 +00:00

51 lines
1.7 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import logging
from odoo import api, fields, models, _
_logger = logging.getLogger(__name__)
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').mapped('partner_id')
def _do_sms_reminder(self):
""" Send an SMS text reminder to attendees that haven't declined the event """
for event in self:
event._message_sms_with_template(
template_xmlid='calendar_sms.sms_template_data_calendar_reminder',
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 _get_trigger_alarm_types(self):
return super()._get_trigger_alarm_types() + ['sms']
class CalendarAlarm(models.Model):
_inherit = 'calendar.alarm'
alarm_type = fields.Selection(selection_add=[
('sms', 'SMS Text Message')
], ondelete={'sms': 'set default'})
class AlarmManager(models.AbstractModel):
_inherit = 'calendar.alarm_manager'
@api.model
def _send_reminder(self):
""" Cron method, overridden here to send SMS reminders as well
"""
super()._send_reminder()
self._get_events_to_notify(ttype='sms')._do_sms_reminder()