[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) <nim@odoo.com>
This commit is contained in:
Andrea Grazioso (agr-odoo)
2019-11-12 07:11:57 +00:00
parent 7f01db75b4
commit 0f17a0ea7d
@@ -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: