in a cron run frequently. The cron "ir_cron_scheduler_alarm" stores its last run datetime in an ir.config.parameter. Since modifying config parameters cleans the cache, the cron clears the cache every 30 minutes, unless modified... As the cache is used to improve global system performance, clearing it frequently should be avoided as much as possible. Since v13, ir.cron records now store their lastcall datetime, there is no need to keep the information in a config parameter anymore. This commit uses this lastcall information instead, as it was done for the calendar module: See https://github.com/odoo/odoo/commit/52645a7b43be157be0782674a0f6b38359293f21 Fixes #63354 for 13+ versions. For earlier versions (12.0), it cannot be "fixed" since the lastcall information isn't available (note that the cache clear also happens in the base calendar method in 12.0). closes odoo/odoo#63560 X-original-commit: 10c08157cb152f111bc9df783e15632c52a61b39 Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
73 lines
2.6 KiB
Python
73 lines
2.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
import logging
|
|
|
|
from odoo import api, fields, models, _
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
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').mapped('partner_id')
|
|
|
|
def _do_sms_reminder(self):
|
|
""" Send an SMS text reminder to attendees that haven't declined the event """
|
|
for event in self:
|
|
event._message_sms_with_template(
|
|
template_xmlid='calendar_sms.sms_template_data_calendar_reminder',
|
|
template_fallback=_("Event reminder: %(name)s, %(time)s.", name=event.name, time=event.display_time),
|
|
partner_ids=self._sms_get_default_partners().ids,
|
|
put_in_queue=False
|
|
)
|
|
|
|
|
|
class CalendarAlarm(models.Model):
|
|
_inherit = 'calendar.alarm'
|
|
|
|
alarm_type = fields.Selection(selection_add=[
|
|
('sms', 'SMS Text Message')
|
|
], ondelete={'sms': 'set default'})
|
|
|
|
|
|
class AlarmManager(models.AbstractModel):
|
|
_inherit = 'calendar.alarm_manager'
|
|
|
|
@api.model
|
|
def get_next_mail(self):
|
|
""" Cron method, overridden here to send SMS reminders as well
|
|
"""
|
|
result = super(AlarmManager, self).get_next_mail()
|
|
|
|
cron = self.env.ref('calendar.ir_cron_scheduler_alarm', raise_if_not_found=False)
|
|
if not cron:
|
|
# Like the super method, do nothing if cron doesn't exist anymore
|
|
return result
|
|
|
|
now = fields.Datetime.to_string(fields.Datetime.now())
|
|
last_sms_cron = cron.lastcall
|
|
|
|
interval_to_second = {
|
|
"weeks": 7 * 24 * 60 * 60,
|
|
"days": 24 * 60 * 60,
|
|
"hours": 60 * 60,
|
|
"minutes": 60,
|
|
"seconds": 1
|
|
}
|
|
|
|
cron_interval = cron.interval_number * interval_to_second[cron.interval_type]
|
|
events_data = self._get_next_potential_limit_alarm('sms', seconds=cron_interval)
|
|
|
|
for event in self.env['calendar.event'].browse(events_data):
|
|
max_delta = events_data[event.id]['max_duration']
|
|
event_start = fields.Datetime.from_string(event.start)
|
|
for alert in self.do_check_alarm_for_one_date(event_start, event, max_delta, 0, 'sms', after=last_sms_cron, missing=True):
|
|
event.browse(alert['event_id'])._do_sms_reminder()
|
|
return result
|