Skip to content
Snippets Groups Projects
Commit b61ece38 authored by Mayurrajsinh Rathod's avatar Mayurrajsinh Rathod
Browse files

[FIX] event: prevent scheduled communication for inactive events


Prior this commit:
The mail scheduler of the event notifies the attendees even when the event is
no longer active.

After this commit:
Inactive events no longer notify attendees.

Task-3381876

closes odoo/odoo#136324

X-original-commit: d23566c3594454c62bb5c177db1d28a8c29a59ca
Signed-off-by: default avatarThibault Delavallee (tde) <tde@openerp.com>
parent f4426c5c
Branches
Tags
No related merge requests found
......@@ -259,6 +259,7 @@ You receive this email because you are:
@api.model
def schedule_communications(self, autocommit=False):
schedulers = self.search([
('event_id.active', '=', True),
('mail_done', '=', False),
('scheduled_date', '<=', fields.Datetime.now())
])
......
......@@ -336,3 +336,69 @@ class TestMailSchedule(EventCase, MockEmail):
self.assertEqual(len(duplicate_mails), 0,
"The duplicate configuration (first one from event_type.event_type_mail_ids which has same configuration as the sent one) should not have been added")
@mute_logger('odoo.addons.base.models.ir_model', 'odoo.models')
def test_archived_event_mail_schedule(self):
""" Test mail scheduling for archived events """
event_cron_id = self.env.ref('event.event_mail_scheduler')
# deactivate other schedulers to avoid messing with crons
self.env['event.mail'].search([]).unlink()
# freeze some datetimes, and ensure more than 1D+1H before event starts
# to ease time-based scheduler check
now = datetime(2023, 7, 24, 14, 30, 15)
event_date_begin = datetime(2023, 7, 26, 8, 0, 0)
event_date_end = datetime(2023, 7, 28, 18, 0, 0)
with freeze_time(now):
test_event = self.env['event.event'].with_user(self.user_eventmanager).create({
'name': 'TestEventMail',
'auto_confirm': True,
'date_begin': event_date_begin,
'date_end': event_date_end,
'event_mail_ids': [
(0, 0, { # right at subscription
'interval_unit': 'now',
'interval_type': 'after_sub',
'template_ref': 'mail.template,%i' % self.env['ir.model.data']._xmlid_to_res_id('event.event_subscription')}),
(0, 0, { # 3 hours before event
'interval_nbr': 3,
'interval_unit': 'hours',
'interval_type': 'before_event',
'template_ref': 'mail.template,%i' % self.env['ir.model.data']._xmlid_to_res_id('event.event_reminder')})
]
})
# check event scheduler
scheduler = self.env['event.mail'].search([('event_id', '=', test_event.id)])
self.assertEqual(len(scheduler), 2, 'event: wrong scheduler creation')
event_prev_scheduler = self.env['event.mail'].search([('event_id', '=', test_event.id), ('interval_type', '=', 'before_event')])
with freeze_time(now), self.mock_mail_gateway():
self.env['event.registration'].create({
'create_date': now,
'event_id': test_event.id,
'name': 'Reg1',
'email': 'reg1@example.com',
})
self.env['event.registration'].create({
'create_date': now,
'event_id': test_event.id,
'name': 'Reg2',
'email': 'reg2@example.com',
})
# check emails effectively sent
self.assertEqual(len(self._new_mails), 2, 'event: should have 2 scheduled emails (1 / registration)')
# Archive the Event
test_event.action_archive()
# execute cron to run schedulers
now_start = event_date_begin + relativedelta(hours=-3)
with freeze_time(now_start), self.mock_mail_gateway():
event_cron_id.method_direct_trigger()
# check that scheduler is not executed
self.assertFalse(event_prev_scheduler.mail_done, 'event: reminder scheduler should should have run')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment