Skip to content

Commit

Permalink
[FIX] calendar: Select correct base event when current is archived
Browse files Browse the repository at this point in the history
When the base event is archived, it continues being the base event
of the recurrence, and when trying to change the recurrence of all
the events of the recurrence, an error is thrown or some inconsistencies
occur.

To test the problem, you can follow these steps:

1. Create a recurrence of events from a non included day on the
   recurrence (example: recurrence on tuesday and friday and the start
   of the recurrence on monday). The first event will be archived
   automatically.
2. Open other event of the recurrence.
3. Modify the recurrence for all events (example: change the weekdays,
   set just tuesday instead of tuesday and friday)

An error will be thrown.

By making these changes, the base event will be updated, as
indicated in the _select_new_base_event method, so these
inconsistencies will not occur when making the changes.

closes #149349

Signed-off-by: Arnaud Joset (arj) <arj@odoo.com>
  • Loading branch information
CarlosRoca13 committed May 15, 2024
1 parent b834b68 commit 7b30c78
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
8 changes: 8 additions & 0 deletions addons/calendar/models/calendar_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,14 @@ def write(self, values):
self.env.ref('calendar.calendar_template_meeting_changedate', raise_if_not_found=False)
)

# Change base event when the main base event is archived. If it isn't done when trying to modify
# all events of the recurrence an error can be thrown or all the recurrence can be deleted.
if values.get("active") is False:
recurrences = self.env["calendar.recurrence"].search([
('base_event_id', 'in', self.ids)
])
recurrences._select_new_base_event()

return True

def _check_private_event_conditions(self):
Expand Down
42 changes: 42 additions & 0 deletions addons/calendar/tests/test_event_recurrence.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,48 @@ def test_unlink_recurrence_future(self):
self.assertTrue(self.recurrence)
self.assertEqual(self.events.exists(), self.events[0])

def test_recurrence_update_all_first_archived(self):
"""Test to check the flow when a calendar event is
created from a day that does not belong to the recurrence.
"""
event = self.env['calendar.event'].create({
'name': 'Recurrent Event',
'start': datetime(2019, 10, 22, 1, 0),
'stop': datetime(2019, 10, 22, 2, 0),
'recurrency': True,
'rrule_type': 'weekly',
'tue': False,
'wed': True,
'fri': True,
'interval': 1,
'count': 3,
'event_tz': 'Etc/GMT-4',
})
# Tuesday datetime(2019, 10, 22, 1, 0) - Archived
# Wednesday datetime(2019, 10, 23, 1, 0)
# Friday datetime(2019, 10, 25, 1, 0)
# Wednesday datetime(2019, 10, 30, 1, 0)
recurrence = self.env['calendar.recurrence'].search([('id', '!=', self.recurrence.id)])
events = recurrence.calendar_event_ids.sorted('start')
# Check first event is archived
self.assertFalse(event.active)
# Check base_event is different than archived and it is first active event
self.assertNotEqual(recurrence.base_event_id, event)
self.assertEqual(recurrence.base_event_id, events[0])
# Update all events to check that error is not thrown
events[0].write({
'recurrence_update': 'all_events',
'fri': False,
})
events = self.env['calendar.recurrence'].search(
[('id', '!=', self.recurrence.id)]
).calendar_event_ids.sorted('start')
self.assertEventDates(events, [
(datetime(2019, 10, 23, 1, 0), datetime(2019, 10, 23, 2, 0)),
(datetime(2019, 10, 30, 1, 0), datetime(2019, 10, 30, 2, 0)),
(datetime(2019, 11, 6, 1, 0), datetime(2019, 11, 6, 2, 0)),
])


class TestUpdateMultiDayWeeklyRecurrentEvents(TestRecurrentEvents):

Expand Down

0 comments on commit 7b30c78

Please sign in to comment.