PURPOSE
Allow the user to schedule SMS communication on events
SPECIFICATION
In event.event form view:
* rename tab 'Email Schedule' to 'Communication'
* add a selection field at the beginning of event_mail_ids with label 'Send'
and values 'Email' and 'SMS Text Message' (required with default value
'Email');
* add support of SMS template and SMS sending in event communication;
When sending SMS on event registrations, keep a log of what has been sent.
Use mobile or phone field of event registration as both may contain valid
values, like partner model.
Add SMS template data
* Name: Event: Registration (see data)
* Name: Event: Reminder (see data)
Improve registration model
* add a mobile field to the attendees form view: https://nimb.ws/p0VvyS
Technically this task uses the newly-introduced API methods allowing to
send and schedule SMS.
LINKS
Task 1922187
Part of PR #34705
50 lines
2.2 KiB
Python
50 lines
2.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import fields, models
|
|
|
|
|
|
class EventTypeMail(models.Model):
|
|
_inherit = 'event.type.mail'
|
|
|
|
notification_type = fields.Selection(selection_add=[('sms', 'SMS')])
|
|
sms_template_id = fields.Many2one(
|
|
'sms.template', string='SMS Template',
|
|
domain=[('model', '=', 'event.registration')], ondelete='restrict',
|
|
help='This field contains the template of the SMS that will be automatically sent')
|
|
|
|
|
|
class EventMailScheduler(models.Model):
|
|
_inherit = 'event.mail'
|
|
|
|
notification_type = fields.Selection(selection_add=[('sms', 'SMS')])
|
|
sms_template_id = fields.Many2one(
|
|
'sms.template', string='SMS Template',
|
|
domain=[('model', '=', 'event.registration')], ondelete='restrict',
|
|
help='This field contains the template of the SMS that will be automatically sent')
|
|
|
|
def execute(self):
|
|
for mail in self:
|
|
now = fields.Datetime.now()
|
|
if mail.interval_type != 'after_sub':
|
|
# Do not send SMS if the communication was scheduled before the event but the event is over
|
|
if not mail.mail_sent and (mail.interval_type != 'before_event' or mail.event_id.date_end > now) and mail.notification_type == 'sms' and mail.sms_template_id:
|
|
self.env['event.registration']._message_sms_schedule_mass(
|
|
template=mail.sms_template_id,
|
|
active_domain=[('event_id', '=', mail.event_id.id), ('state', '!=', 'cancel')],
|
|
mass_keep_log=True
|
|
)
|
|
mail.write({'mail_sent': True})
|
|
return super(EventMailScheduler, self).execute()
|
|
|
|
|
|
class EventMailRegistration(models.Model):
|
|
_inherit = 'event.mail.registration'
|
|
|
|
def execute(self):
|
|
for record in self:
|
|
if record.registration_id.state in ['open', 'done'] and not record.mail_sent and record.scheduler_id.notification_type == 'sms':
|
|
record.registration_id._message_sms_schedule_mass(template=record.scheduler_id.sms_template_id, mass_keep_log=True)
|
|
record.write({'mail_sent': True})
|
|
return super(EventMailRegistration, self).execute()
|