PURPOSE
This commit 62ac23f0b9 introduced SMS capabilities on for
event.type.mail and event.mail models.
Values of event_type_mail_ids on event.type are supposed to be copied to
event_mail_ids on event.event when changing the event_type_id of an event.
There are however 2 issues with that integration:
- The 'notification_type' field was not correctly set on default
event_type_mail_ids on event.type;
- The 'notification_type' and 'sms_template' fields were not copied from
event_type_mail_ids to event_mail_ids;
LINKS
PR #39892
Task ID 2115792
closes odoo/odoo#41736
X-original-commit: 3fd66d844aa66ca8d54223071c787974e6c88c94
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
54 lines
2.4 KiB
Python
54 lines
2.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import api, 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')
|
|
|
|
@api.model
|
|
def _get_event_mail_fields_whitelist(self):
|
|
return super(EventTypeMail, self)._get_event_mail_fields_whitelist() + ['sms_template_id']
|
|
|
|
|
|
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()
|