Skip to content

Commit

Permalink
[FIX] calendar: prevent userError when base_event is not defined
Browse files Browse the repository at this point in the history
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#139486

X-original-commit: bd1c46a
Signed-off-by: Arnaud Joset (arj) <arj@odoo.com>
  • Loading branch information
arj-odoo committed Oct 24, 2023
1 parent 560e6ed commit 61eaaae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
5 changes: 3 additions & 2 deletions addons/calendar/models/calendar_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,8 @@ def _update_future_events(self, values, time_values, recurrence_values):
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()
Expand Down Expand Up @@ -1183,7 +1184,7 @@ def _update_future_events(self, values, time_values, recurrence_values):
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)

Expand Down
9 changes: 4 additions & 5 deletions addons/calendar/tests/test_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,14 @@ def _test_one_mail_per_attendee(self, partners):
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
Expand All @@ -351,8 +350,8 @@ def _test_one_mail_per_attendee(self, partners):
'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
Expand Down

0 comments on commit 61eaaae

Please sign in to comment.