[FIX] calendar: prevent userError when base_event is not defined

Before this commit, the follwing traceback was sometimes raised.

Error message
ERROR: TestCalendar.test_event_creation_mail
Traceback (most recent call last):
  File "/data/build/odoo/addons/calendar/tests/test_calendar.py", line 339, in test_event_creation_mail
    m.write({
  File "/data/build/odoo/addons/calendar/models/calendar_event.py", line 574, in write
    self._rewrite_recurrence(values, time_values, recurrence_values)
  File "/data/build/odoo/addons/calendar/models/calendar_event.py", line 1084, in _rewrite_recurrence
    update_dict = self._get_time_update_dict(base_event, time_values)
  File "/data/build/odoo/addons/calendar/models/calendar_event.py", line 993, in _get_time_update_dict
    raise UserError(_("You can't update a recurrence without base event."))
odoo.exceptions.UserError: You can't update a recurrence without base event.

closes odoo/odoo#139486

X-original-commit: bd1c46a79ea3d41a374fac47dd16af802d18045d
Signed-off-by: Arnaud Joset (arj) <arj@odoo.com>
This commit is contained in:
Arnaud Joset
2023-10-24 15:23:14 +00:00
parent 560e6ed4fd
commit 61eaaae4a6
2 changed files with 7 additions and 7 deletions
+3 -2
View File
@@ -1150,7 +1150,8 @@ class Meeting(models.Model):
deactivate the detached events except for the updated event and apply recurrence values.
"""
self.ensure_one()
update_dict = self._get_time_update_dict(self, time_values)
base_event = self
update_dict = self._get_time_update_dict(base_event, time_values)
time_values.update(update_dict)
# Get base values from the previous recurrence and update the start date weekday field.
start_date = time_values['start'].date() if 'start' in time_values else self.start.date()
@@ -1183,7 +1184,7 @@ class Meeting(models.Model):
def _rewrite_recurrence(self, values, time_values, recurrence_values):
""" Delete the current recurrence, reactivate base event and apply updated recurrence values. """
self.ensure_one()
base_event = self.recurrence_id.base_event_id
base_event = self.recurrence_id.base_event_id or self.recurrence_id._get_first_event(include_outliers=False)
update_dict = self._get_time_update_dict(base_event, time_values)
time_values.update(update_dict)
+4 -5
View File
@@ -316,15 +316,14 @@ class TestCalendar(SavepointCaseWithUserDemo):
self.env['res.partner'].create({'name': 'testuser1', 'email': u'alice@example.com'}),
]
partner_ids = [(6, False, [p.id for p in partners]),]
now = fields.Datetime.context_timestamp(partners[0], fields.Datetime.now())
m = self.CalendarEvent.create({
'name': "mailTest1",
'allday': False,
'rrule': u'FREQ=DAILY;INTERVAL=1;COUNT=5',
'recurrency': True,
'partner_ids': partner_ids,
'start': fields.Datetime.to_string(now + timedelta(days=10)),
'stop': fields.Datetime.to_string(now + timedelta(days=15)),
'start': "2023-10-29 08:00:00",
'stop': "2023-11-03 08:00:00",
})
# every partner should have 1 mail sent
@@ -351,8 +350,8 @@ class TestCalendar(SavepointCaseWithUserDemo):
'allday': False,
'recurrency': False,
'partner_ids': partner_ids,
'start': fields.Datetime.to_string(now - timedelta(days=10)),
'stop': fields.Datetime.to_string(now - timedelta(days=9)),
'start': "2023-10-09 08:00:00",
'stop': "2023-10-10 08:00:00",
})
# no more email should be sent