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

@ -3,19 +3,22 @@
from datetime import datetime, timedelta
from odoo import fields
from odoo.addons.event.tests.common import EventCase
from odoo.addons.phone_validation.tools import phone_validation
from odoo.addons.sms.tests.common import SMSCase
from odoo.tests import users
from odoo.tests import tagged, users
@tagged('event_mail', 'post_install', '-at_install')
class TestSMSSchedule(EventCase, SMSCase):
@classmethod
def setUpClass(cls):
super(TestSMSSchedule, cls).setUpClass()
# consider asynchronous sending as default sending
cls.env["ir.config_parameter"].set_param("event.event_mail_async", False)
cls.sms_template_sub = cls.env['sms.template'].create({
'name': 'Test subscription',
'model_id': cls.env.ref('event.model_event_registration').id,
@ -29,33 +32,36 @@ class TestSMSSchedule(EventCase, SMSCase):
'lang': '{{ object.partner_id.lang }}'
})
cls.test_event = cls.env['event.event'].create({
'auto_confirm': True,
'date_begin': fields.Datetime.to_string(datetime.today() + timedelta(days=1)),
'date_end': fields.Datetime.to_string(datetime.today() + timedelta(days=15)),
'date_tz': 'Europe/Brussels',
'event_mail_ids': [
(5, 0),
(0, 0, { # right at subscription
'interval_unit': 'now',
'interval_type': 'after_sub',
'notification_type': 'sms',
'template_ref': 'sms.template,%i' % cls.sms_template_sub.id}),
(0, 0, { # 3 days before event
'interval_nbr': 3,
'interval_unit': 'days',
'interval_type': 'before_event',
'notification_type': 'sms',
'template_ref': 'sms.template,%i' % cls.sms_template_rem.id}),
],
'name': 'TestEvent',
})
cls.reference_now = datetime(2021, 3, 20, 14, 30, 15, 123456)
cls.event_date_begin = datetime(2021, 3, 25, 8, 0, 0)
cls.event_date_end = datetime(2021, 3, 27, 18, 0, 0)
with cls.mock_datetime_and_now(cls, cls.reference_now):
cls.test_event = cls.env['event.event'].create({
'date_begin': cls.event_date_begin,
'date_end': cls.event_date_end,
'date_tz': 'Europe/Brussels',
'event_mail_ids': [
(5, 0),
(0, 0, { # right at subscription
'interval_unit': 'now',
'interval_type': 'after_sub',
'notification_type': 'sms',
'template_ref': 'sms.template,%i' % cls.sms_template_sub.id}),
(0, 0, { # 3 days before event
'interval_nbr': 3,
'interval_unit': 'days',
'interval_type': 'before_event',
'notification_type': 'sms',
'template_ref': 'sms.template,%i' % cls.sms_template_rem.id}),
],
'name': 'TestEvent',
})
@users('user_eventmanager')
def test_sms_schedule(self):
test_event = self.env['event.event'].browse(self.test_event.ids)
with self.mockSMSGateway():
with self.mock_datetime_and_now(self.reference_now), self.mockSMSGateway():
self._create_registrations(test_event, 3)
# check subscription scheduler
@ -75,7 +81,6 @@ class TestSMSSchedule(EventCase, SMSCase):
self.assertSMSOutgoing(
self.env['res.partner'], reg_sanitized_number,
content='%s registration confirmation.' % test_event.organizer_id.name)
self.assertTrue(sub_scheduler.mail_done)
self.assertEqual(sub_scheduler.mail_count_done, 3)
# clear notification queue to avoid conflicts when checking next notifications
@ -88,7 +93,7 @@ class TestSMSSchedule(EventCase, SMSCase):
self.assertEqual(before_scheduler.scheduled_date, test_event.date_begin + timedelta(days=-3))
# execute event reminder scheduler explicitly
with self.mockSMSGateway():
with self.mock_datetime_and_now(self.reference_now + timedelta(days=3)), self.mockSMSGateway():
before_scheduler.execute()
# verify that subscription scheduler was auto-executed after each registration
@ -99,3 +104,10 @@ class TestSMSSchedule(EventCase, SMSCase):
content='%s reminder' % test_event.organizer_id.name)
self.assertTrue(before_scheduler.mail_done)
self.assertEqual(before_scheduler.mail_count_done, 3)
@users('user_eventmanager')
def test_sms_schedule_fail_registration_template_removed(self):
""" Test flow where scheduler fails due to template being removed. """
self.sms_template_sub.sudo().unlink()
after_sub_scheduler = self.test_event.event_mail_ids.filtered(lambda s: s.interval_type == 'after_sub')
self.assertFalse(after_sub_scheduler, "When removing template, scheduler should be removed")