From 2829ffde9f0f7132a72a75e6676e2907ca54b867 Mon Sep 17 00:00:00 2001 From: Adrien Widart Date: Thu, 28 Jan 2021 12:26:02 +0000 Subject: [PATCH] [FIX] google_calendar: prevent useless partners creation When syncing with a Google account, if user's email is different from Google account, the server creates a new partner. Moreover, the synced event are not linked to the current partner. To reproduce the error: 1. Have two Google accounts GA01 and GA02 2. With GA01, add an event to Google Calendar and add GA02 to guests 3. In Odoo, sync with Google Calendar using GA02 - The partner linked to the current Odoo user must have an email different from GA02's email Error: The calendar is synced, but the user needs to check "Everybody's calendars" to see the synced events. A new partner has been created using GA02's email. The synced events are linked to this new partner instead of current user's partner (`self.env.user.partner_id`). Moreover, Google event's organizer is always added to attendees but, if it this is indeed the case (so if the organizer is also an attendee), `google_event.attendees` already contains this organizer. OPW-2440033 closes odoo/odoo#65630 X-original-commit: 12cb76bdfe7a5affb7580485473be71cfa37658a Signed-off-by: Adrien Widart --- addons/google_calendar/models/calendar.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/google_calendar/models/calendar.py b/addons/google_calendar/models/calendar.py index 61df4646718..11364eee474 100644 --- a/addons/google_calendar/models/calendar.py +++ b/addons/google_calendar/models/calendar.py @@ -94,7 +94,7 @@ class Meeting(models.Model): attendee_commands = [] partner_commands = [] google_attendees = google_event.attendees or [] - if google_event.organizer and google_event.organizer.get('self', False): + if len(google_attendees) == 0 and google_event.organizer and google_event.organizer.get('self', False): user = google_event.owner(self.env) google_attendees += [{ 'email': user.partner_id.email, @@ -113,7 +113,7 @@ class Meeting(models.Model): attendee_commands += [(1, attendees_by_emails[email].id, {'state': attendee.get('responseStatus')})] else: # Create new attendees - partner = self.env['res.partner'].find_or_create(attendee.get('email')) + partner = self.env.user.partner_id if attendee.get('self') else self.env['res.partner'].find_or_create(attendee.get('email')) attendee_commands += [(0, 0, {'state': attendee.get('responseStatus'), 'partner_id': partner.id})] partner_commands += [(4, partner.id)] if attendee.get('displayName') and not partner.name: