From 33755f18826b1322283ed95dc045eb009be774ef Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Thu, 11 Feb 2016 11:09:10 +0100 Subject: [PATCH] [IMP] calendar: enable change recurrence start/stop When editing a recurring event clicking `Update only this instance` allow us to detach this event from the recurring sequence, but without clicking it there are instances where the event will still be detached maybe unexpectedly. Clicking on it will create an event which shadow the recurring one that being done thanks to: - recurring_id: the id of the recurring event creating this event - recurring_id_date: start of the virtual event this new event shadows Before this commit: when the start or end date of an recurring event is changed, all modification are not applied on the recurring events but only the current virtual event occurrence is detached and modified. After this commit: - when the end date of a recurring event is modified, it is modified for all the instance (not detached) of the recurring event, - when the start date of a recurring event is modified, it is modified all the instance (not detached) of the reccuring event and if: * one occurrence of the recurring event is still on a (not-moved) detached event of this recurrence, this virtual event will be shadowed. * a detached event has now no occurrence of the recurring event on its day, it will still be left untouched but will now not shadow an event anymore. eg. we start with recurring event A on 4, 5, 6 => we see [4: A, 5: A, 6: A] -> detach event on 5 calling it B => we see [4: A, 5: B, 6: C] -> change start of recurrence to 5 => we see [5:B, 6:A, 7: A] -> change start of recurrence to 7 => we see [5:B, 7:A, 8: A, 9:A] -> delete detached event B on 5 => we see [7:A, 8: A, 9:A] -> change start of recurrence to 3 => we see [3:A, 4: A] closes #10873 fixes #10278 opw-665700 --- addons/calendar/calendar.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/addons/calendar/calendar.py b/addons/calendar/calendar.py index e4d0a99c9ec..a8e8147f80f 100644 --- a/addons/calendar/calendar.py +++ b/addons/calendar/calendar.py @@ -1564,12 +1564,16 @@ class calendar_event(osv.Model): else: real_event_id = calendar_id2real_id(event_id) - # if we are setting the recurrency flag to False or if we are only changing fields that - # should be only updated on the real ID and not on the virtual (like message_follower_ids): - # then set real ids to be updated. - blacklisted = any(key in values for key in ('start', 'stop', 'active')) - if not values.get('recurrency', True) or not blacklisted: + # update the real id unless it is a deletion of a virtual still to be recurrent + if 'active' not in values or not values.get('recurrency', True): real_ids = [real_event_id] + # if start change, update recurrent_id_date time of detached events + if 'start' in values: + _, _, new_time = values['start'].partition(' ') + detached_ids = self.search(cr, uid, [('recurrent_id', '=', real_event_id)], context=context) + for event in self.browse(cr, uid, detached_ids, context=context): + detached_date, _, _ = event.recurrent_id_date.partition(' ') + event.recurrent_id_date = detached_date + ' ' + new_time else: data = self.read(cr, uid, event_id, ['start', 'stop', 'rrule', 'duration']) if data.get('rrule'):