Initial commit: Mail packages

This commit is contained in:
Ernad Husremovic 2025-08-29 15:20:51 +02:00
commit 4e53507711
1948 changed files with 751201 additions and 0 deletions

View file

@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import calendar_alarm
from . import calendar_alarm_manager
from . import calendar_event

View file

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
class CalendarAlarm(models.Model):
_inherit = 'calendar.alarm'
alarm_type = fields.Selection(selection_add=[
('sms', 'SMS Text Message')
], ondelete={'sms': 'set default'})
sms_template_id = fields.Many2one(
'sms.template', string="SMS Template",
domain=[('model', 'in', ['calendar.event'])],
compute='_compute_sms_template_id', readonly=False, store=True,
help="Template used to render SMS reminder content.")
@api.depends('alarm_type', 'sms_template_id')
def _compute_sms_template_id(self):
for alarm in self:
if alarm.alarm_type == 'sms' and not alarm.sms_template_id:
alarm.sms_template_id = self.env['ir.model.data']._xmlid_to_res_id('calendar_sms.sms_template_data_calendar_reminder')
elif alarm.alarm_type != 'sms' or not alarm.sms_template_id:
alarm.sms_template_id = False

View file

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, models
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()
events_by_alarm = self._get_events_by_alarm_to_notify('sms')
if not events_by_alarm:
return
all_events_ids = list({event_id for event_ids in events_by_alarm.values() for event_id in event_ids})
for alarm_id, event_ids in events_by_alarm.items():
alarm = self.env['calendar.alarm'].browse(alarm_id).with_prefetch(list(events_by_alarm.keys()))
events = self.env['calendar.event'].browse(event_ids).with_prefetch(all_events_ids)
events._do_sms_reminder(alarm)

View file

@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models, _
from odoo.exceptions import UserError
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' and att.partner_id.phone_sanitized).mapped('partner_id')
def _do_sms_reminder(self, alarm):
""" Send an SMS text reminder to attendees that haven't declined the event """
for event in self:
event._message_sms_with_template(
template=alarm.sms_template_id,
template_fallback=_("Event reminder: %(name)s, %(time)s.", name=event.name, time=event.display_time),
partner_ids=event._sms_get_default_partners().ids,
put_in_queue=False
)
def action_send_sms(self):
if not self.partner_ids:
raise UserError(_("There are no attendees on these events"))
return {
'type': 'ir.actions.act_window',
'name': _("Send SMS Text Message"),
'res_model': 'sms.composer',
'view_mode': 'form',
'target': 'new',
'context': {
'default_composition_mode': 'mass',
'default_res_model': 'res.partner',
'default_res_ids': self.partner_ids.ids,
'default_mass_keep_log': True,
},
}
def _get_trigger_alarm_types(self):
return super()._get_trigger_alarm_types() + ['sms']