From 1c533b193feb7629d87ab1ff740b0cbc7615812e Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Tue, 1 Sep 2015 17:03:47 +0200 Subject: [PATCH] [FIX] google_calendar: events disappearing This rev. is related to a9e3d74713b6882c64617345696ad326d75a4745 This new revision is about the same use case than above, except that both Google users login doesn't match the Odoo login email. e.g. User A: A@agrolait.com in Odoo, A@gmail.com in Google User B: B@agrolait.com in Odoo, B@gmail.com in Google. When A creates an event, with B in the attendees, and syncs his calendar to Google, B is not automatically invited Google side, as his attendee email is B@agrolait.com, which doesn't match any existing Google User (doesn't match B@gmail.com) While the revision mentioned above, a9e3d74713b6882c64617345696ad326d75a4745, expected the attendee to be automatically invited Google side, and therefore expected the event to already exists in B's calendar. Therefore, when B syncs his calendar in Odoo, as the event was there in his Odoo calendar, but not in his Google Calendar, the code actually think it's no - longer - there, and take the assumption the event has been deleted Google side. So, it deletes the event in Odoo side as well, for both users A & B. To overcome this new issue, when the Google & Odoo users emails do not match, while keeping the compatibility when the Google & Odoo emails do match (and therefore the invitation is automatically sent Google side, as the email matches an existing Google account, and the event is automatically created in B's calendar without needing the sync in Odoo), we now force the Google internal id to be the same for all attendees of an event, event by Google side. opw-645745 --- addons/google_calendar/google_calendar.py | 34 ++++++++++++++--------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/addons/google_calendar/google_calendar.py b/addons/google_calendar/google_calendar.py index c60eea29cc4..72325e39c76 100644 --- a/addons/google_calendar/google_calendar.py +++ b/addons/google_calendar/google_calendar.py @@ -259,6 +259,9 @@ class google_calendar(osv.AbstractModel): if not self.get_need_synchro_attendee(cr, uid, context=context): data.pop("attendees") + other_google_ids = [other_att.google_internal_event_id for other_att in event.attendee_ids if other_att.google_internal_event_id] + if other_google_ids: + data["id"] = other_google_ids[0] return data def create_an_event(self, cr, uid, event, context=None): @@ -428,7 +431,7 @@ class google_calendar(osv.AbstractModel): if type == "write": for oe_attendee in event['attendee_ids']: if oe_attendee.email == partner_email: - calendar_attendee_obj.write(cr, uid, [oe_attendee.id], {'state': google_attendee['responseStatus'], 'google_internal_event_id': single_event_dict.get('id')}, context=context) + calendar_attendee_obj.write(cr, uid, [oe_attendee.id], {'state': google_attendee['responseStatus']}, context=context) google_attendee['found'] = True continue @@ -447,7 +450,6 @@ class google_calendar(osv.AbstractModel): partner_record.append((4, attendee.get('id'))) attendee['partner_id'] = attendee.pop('id') attendee['state'] = google_attendee['responseStatus'] - attendee['google_internal_event_id'] = single_event_dict.get('id') attendee_record.append((0, 0, attendee)) for google_alarm in single_event_dict.get('reminders', {}).get('overrides', []): alarm_id = calendar_alarm_obj.search( @@ -626,17 +628,23 @@ class google_calendar(osv.AbstractModel): ('event_id.final_date', '>', self.get_minTime(cr, uid, context=context).strftime(DEFAULT_SERVER_DATETIME_FORMAT)), ], context=context_norecurrent) for att in att_obj.browse(cr, uid, my_att_ids, context=context): - if not att.event_id.recurrent_id or att.event_id.recurrent_id == 0: - st, response, ask_time = self.create_an_event(cr, uid, att.event_id, context=context) - if status_response(st): - update_date = datetime.strptime(response['updated'], "%Y-%m-%dT%H:%M:%S.%fz") - ev_obj.write(cr, uid, att.event_id.id, {'oe_update_date': update_date}) - new_ids.append(response['id']) - att_obj.write(cr, uid, [att.id for att in att.event_id.attendee_ids], {'google_internal_event_id': response['id'], 'oe_synchro_date': update_date}) - cr.commit() - else: - _logger.warning("Impossible to create event %s. [%s]" % (att.event_id.id, st)) - _logger.warning("Response : %s" % response) + other_google_ids = [other_att.google_internal_event_id for other_att in att.event_id.attendee_ids if other_att.google_internal_event_id and other_att.id != att.id] + for other_google_id in other_google_ids: + if self.get_one_event_synchro(cr, uid, other_google_id, context=context): + att_obj.write(cr, uid, [att.id], {'google_internal_event_id': other_google_id}) + break + else: + if not att.event_id.recurrent_id or att.event_id.recurrent_id == 0: + st, response, ask_time = self.create_an_event(cr, uid, att.event_id, context=context) + if status_response(st): + update_date = datetime.strptime(response['updated'], "%Y-%m-%dT%H:%M:%S.%fz") + ev_obj.write(cr, uid, att.event_id.id, {'oe_update_date': update_date}) + new_ids.append(response['id']) + att_obj.write(cr, uid, [att.id], {'google_internal_event_id': response['id'], 'oe_synchro_date': update_date}) + cr.commit() + else: + _logger.warning("Impossible to create event %s. [%s]" % (att.event_id.id, st)) + _logger.warning("Response : %s" % response) return new_ids def get_context_no_virtual(self, context):