19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:31:39 +01:00
parent 5df8c07b59
commit daa394e8b0
2114 changed files with 564841 additions and 299642 deletions

View file

@ -2,5 +2,6 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import event_mail
from . import event_registration
from . import event_mail_registration
from . import event_type_mail
from . import sms_template

View file

@ -1,93 +1,30 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
from odoo import fields, models
class EventTypeMail(models.Model):
_inherit = 'event.type.mail'
@api.model
def _selection_template_model(self):
return super(EventTypeMail, self)._selection_template_model() + [('sms.template', 'SMS')]
notification_type = fields.Selection(selection_add=[('sms', 'SMS')], ondelete={'sms': 'set default'})
@api.depends('notification_type')
def _compute_template_model_id(self):
sms_model = self.env['ir.model']._get('sms.template')
sms_mails = self.filtered(lambda mail: mail.notification_type == 'sms')
sms_mails.template_model_id = sms_model
super(EventTypeMail, self - sms_mails)._compute_template_model_id()
class EventMailScheduler(models.Model):
class EventMail(models.Model):
_inherit = 'event.mail'
@api.model
def _selection_template_model(self):
return super(EventMailScheduler, self)._selection_template_model() + [('sms.template', 'SMS')]
notification_type = fields.Selection(selection_add=[('sms', 'SMS')])
template_ref = fields.Reference(ondelete={'sms.template': 'cascade'}, selection_add=[('sms.template', 'SMS')])
def _selection_template_model_get_mapping(self):
return {**super(EventMailScheduler, self)._selection_template_model_get_mapping(), 'sms': 'sms.template'}
def _compute_notification_type(self):
super()._compute_notification_type()
sms_schedulers = self.filtered(lambda scheduler: scheduler.template_ref and scheduler.template_ref._name == 'sms.template')
sms_schedulers.notification_type = 'sms'
notification_type = fields.Selection(selection_add=[('sms', 'SMS')], ondelete={'sms': 'set default'})
def _execute_event_based_for_registrations(self, registrations):
if self.notification_type == "sms":
self._send_sms(registrations)
return super()._execute_event_based_for_registrations(registrations)
@api.depends('notification_type')
def _compute_template_model_id(self):
sms_model = self.env['ir.model']._get('sms.template')
sms_mails = self.filtered(lambda mail: mail.notification_type == 'sms')
sms_mails.template_model_id = sms_model
super(EventMailScheduler, self - sms_mails)._compute_template_model_id()
def execute(self):
for scheduler in self:
now = fields.Datetime.now()
if scheduler.interval_type != 'after_sub' and scheduler.notification_type == 'sms':
# before or after event -> one shot email
if scheduler.mail_done:
continue
# no template -> ill configured, skip and avoid crash
if not scheduler.template_ref:
continue
# Do not send SMS if the communication was scheduled before the event but the event is over
if scheduler.scheduled_date <= now and (scheduler.interval_type != 'before_event' or scheduler.event_id.date_end > now):
scheduler.event_id.registration_ids.filtered(lambda registration: registration.state != 'cancel')._message_sms_schedule_mass(
template=scheduler.template_ref,
mass_keep_log=True
)
scheduler.update({
'mail_done': True,
'mail_count_done': scheduler.event_id.seats_expected,
})
return super(EventMailScheduler, self).execute()
@api.onchange('notification_type')
def set_template_ref_model(self):
super().set_template_ref_model()
mail_model = self.env['sms.template']
if self.notification_type == 'sms':
record = mail_model.search([('model', '=', 'event.registration')], limit=1)
self.template_ref = "{},{}".format('sms.template', record.id) if record else False
class EventMailRegistration(models.Model):
_inherit = 'event.mail.registration'
def execute(self):
now = fields.Datetime.now()
todo = self.filtered(lambda reg_mail:
not reg_mail.mail_sent and \
reg_mail.registration_id.state in ['open', 'done'] and \
(reg_mail.scheduled_date and reg_mail.scheduled_date <= now) and \
reg_mail.scheduler_id.notification_type == 'sms'
def _send_sms(self, registrations):
""" SMS action: send SMS to attendees """
registrations._message_sms_schedule_mass(
template=self.template_ref,
mass_keep_log=True
)
for reg_mail in todo:
reg_mail.registration_id._message_sms_schedule_mass(
template=reg_mail.scheduler_id.template_ref,
mass_keep_log=True
)
todo.write({'mail_sent': True})
return super(EventMailRegistration, self).execute()
def _template_model_by_notification_type(self):
info = super()._template_model_by_notification_type()
info["sms"] = "sms.template"
return info

View file

@ -0,0 +1,15 @@
from odoo import fields, models
class EventMailRegistration(models.Model):
_inherit = 'event.mail.registration'
def _execute_on_registrations(self):
todo = self.filtered(
lambda r: r.scheduler_id.notification_type == "sms"
)
for scheduler, reg_mails in todo.grouped('scheduler_id').items():
scheduler._send_sms(reg_mails.registration_id)
todo.mail_sent = True
return super(EventMailRegistration, self - todo)._execute_on_registrations()

View file

@ -1,13 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models
class Registration(models.Model):
_inherit = 'event.registration'
def _sms_get_number_fields(self):
""" This method returns the fields to use to find the number to use to
send an SMS on a record. """
return ['mobile', 'phone']

View file

@ -0,0 +1,13 @@
from odoo import fields, models
class EventTypeMail(models.Model):
_inherit = 'event.type.mail'
notification_type = fields.Selection(selection_add=[('sms', 'SMS')])
template_ref = fields.Reference(ondelete={'sms.template': 'cascade'}, selection_add=[('sms.template', 'SMS')])
def _compute_notification_type(self):
super()._compute_notification_type()
sms_schedulers = self.filtered(lambda scheduler: scheduler.template_ref and scheduler.template_ref._name == 'sms.template')
sms_schedulers.notification_type = 'sms'

View file

@ -1,25 +1,24 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, models
from odoo.osv import expression
from odoo.fields import Domain
class SmsTemplate(models.Model):
_inherit = 'sms.template'
@api.model
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None):
def _search(self, domain, *args, **kwargs):
"""Context-based hack to filter reference field in a m2o search box to emulate a domain the ORM currently does not support.
As we can not specify a domain on a reference field, we added a context
key `filter_template_on_event` on the template reference field. If this
key is set, we add our domain in the `args` in the `_name_search`
key is set, we add our domain in the `domain` in the `_search`
method to filtrate the SMS templates.
"""
if self.env.context.get('filter_template_on_event'):
args = expression.AND([[('model', '=', 'event.registration')], args])
return super(SmsTemplate, self)._name_search(name, args, operator, limit, name_get_uid)
domain = Domain('model', '=', 'event.registration') & Domain(domain)
return super()._search(domain, *args, **kwargs)
def unlink(self):
res = super().unlink()