From 0f17a0ea7ddae73a631e0f07a0597037ee88bd5e Mon Sep 17 00:00:00 2001 From: "Andrea Grazioso (agr-odoo)" Date: Wed, 30 Oct 2019 12:21:58 +0000 Subject: [PATCH] [FIX] google_calendar: exclusions not propagating (from OE) Activate Google Synchronization, create on OE a recurrent event, synchronize the calendar, then delete an event of the recursion on GC, sync again on OE. The event will be deleted from GC but not from OE after sync. This appens because of this "rewrite" rule https://github.com/odoo/odoo/blob/12.0/addons/calendar/models/calendar.py#L918 that occur on event creation from OE, altering the event parameters when is marked "allday". When an "allday" event is deleted from GC the unlink is triggered in OE with the default time "00:00:00". During the creation of the exclusion ' _inverse_dates' will be called altering start and stop datetime but not recurrent_id_date, so the new record will not match the event generating the recursion and the exclusion will not occur. The problem require particular carefulness because when a recurrent event is fetched from google the '_inverse_dates' is not called, so in that case the default time is fine. opw-2060526 closes odoo/odoo#39662 Signed-off-by: Nicolas Martinelli (nim) --- addons/google_calendar/models/google_calendar.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/addons/google_calendar/models/google_calendar.py b/addons/google_calendar/models/google_calendar.py index 487c1f1f148..2183a9142a3 100644 --- a/addons/google_calendar/models/google_calendar.py +++ b/addons/google_calendar/models/google_calendar.py @@ -830,10 +830,15 @@ class GoogleCalendar(models.AbstractModel): recs.delete_an_event(current_event[0]) elif actSrc == 'GG': new_google_event_id = event.GG.event['id'].rsplit('_', 1)[1] + parent_oe = event_to_synchronize[base_event][0][1].OE.event if 'T' in new_google_event_id: new_google_event_id = new_google_event_id.replace('T', '')[:-1] else: - new_google_event_id = new_google_event_id + "000000" + #allday event, need to match the changes that will be applied with _inverse_dates otherwise the exclusion will not occur + if parent_oe: + new_google_event_id = new_google_event_id + parent_oe.start.strftime("%H%M%S") + else: + new_google_event_id = new_google_event_id + "000000" if event.GG.status: parent_event = {} @@ -847,9 +852,8 @@ class GoogleCalendar(models.AbstractModel): else: recs.create_from_google(event, my_partner_id) else: - parent_oe_id = event_to_synchronize[base_event][0][1].OE.event_id - if parent_oe_id: - CalendarEvent.browse("%s-%s" % (parent_oe_id, new_google_event_id)).with_context(curr_attendee=event.OE.attendee_id).unlink(can_be_deleted=True) + if parent_oe: + CalendarEvent.browse("%s-%s" % (parent_oe.id, new_google_event_id)).with_context(curr_attendee=event.OE.attendee_id).unlink(can_be_deleted=True) else: main_att = CalendarAttendee.with_context(context_novirtual).search([('partner_id', '=', my_partner_id), ('google_internal_event_id', '=', event.GG.event['id'].rsplit('_', 1)[0])], limit=1) if main_att: