calendar_event.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import models, _
  4. from odoo.exceptions import UserError
  5. class CalendarEvent(models.Model):
  6. _inherit = 'calendar.event'
  7. def _sms_get_default_partners(self):
  8. """ Method overridden from mail.thread (defined in the sms module).
  9. SMS text messages will be sent to attendees that haven't declined the event(s).
  10. """
  11. return self.mapped('attendee_ids').filtered(lambda att: att.state != 'declined' and att.partner_id.phone_sanitized).mapped('partner_id')
  12. def _do_sms_reminder(self, alarm):
  13. """ Send an SMS text reminder to attendees that haven't declined the event """
  14. for event in self:
  15. event._message_sms_with_template(
  16. template=alarm.sms_template_id,
  17. template_fallback=_("Event reminder: %(name)s, %(time)s.", name=event.name, time=event.display_time),
  18. partner_ids=self._sms_get_default_partners().ids,
  19. put_in_queue=False
  20. )
  21. def action_send_sms(self):
  22. if not self.partner_ids:
  23. raise UserError(_("There are no attendees on these events"))
  24. return {
  25. 'type': 'ir.actions.act_window',
  26. 'name': _("Send SMS Text Message"),
  27. 'res_model': 'sms.composer',
  28. 'view_mode': 'form',
  29. 'target': 'new',
  30. 'context': {
  31. 'default_composition_mode': 'mass',
  32. 'default_res_model': 'res.partner',
  33. 'default_res_ids': self.partner_ids.ids,
  34. 'default_mass_keep_log': True,
  35. },
  36. }
  37. def _get_trigger_alarm_types(self):
  38. return super()._get_trigger_alarm_types() + ['sms']