From fb36e02de5244e2d485c5c5c654f4d99cc6f5791 Mon Sep 17 00:00:00 2001 From: pedrambiria Date: Tue, 7 Jun 2022 09:56:16 +0000 Subject: [PATCH] [FIX] google_calendar: not sending emails to existing event attendees Before this commit: syncing with google led to sending emails to attendees of existing future events on Odoo. Steps to reproduce the first issue: - Install 'google_calendar' module - Integrate with Google Calendar in setting - Add an event to the Odoo calendar for future date - Add one external attendee to the event - Sync with Google Invitation emails would be sent to the attendees of the events. Solution It's possible to not send emails to the attendees in api calls. So the solution is to not send emails to the attendees for the syncing time. opw-2819046 closes odoo/odoo#95781 X-original-commit: ac78ad6bf806ae3233ad38399771745edc8dc00d Signed-off-by: Yannick Tivisse (yti) Signed-off-by: Arnaud Joset Signed-off-by: Pedram Bi Ria (pebr) --- addons/google_calendar/models/google_sync.py | 3 ++- addons/google_calendar/models/res_users.py | 5 +++-- addons/google_calendar/utils/google_calendar.py | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/addons/google_calendar/models/google_sync.py b/addons/google_calendar/models/google_sync.py index 63ad22e689b..9480288c427 100644 --- a/addons/google_calendar/models/google_sync.py +++ b/addons/google_calendar/models/google_sync.py @@ -246,7 +246,8 @@ class GoogleSync(models.AbstractModel): with google_calendar_token(self.env.user.sudo()) as token: if token: try: - google_id = google_service.insert(values, token=token, timeout=timeout) + send_updates = self._context.get('send_updates', True) + google_id = google_service.with_context(send_updates=send_updates).insert(values, token=token, timeout=timeout) # Everything went smoothly self.with_context(dont_notify=True).write({ 'google_id': google_id, diff --git a/addons/google_calendar/models/res_users.py b/addons/google_calendar/models/res_users.py index b420dc05f6a..3c54b3f6a20 100644 --- a/addons/google_calendar/models/res_users.py +++ b/addons/google_calendar/models/res_users.py @@ -69,13 +69,14 @@ class User(models.Model): synced_events = self.env['calendar.event']._sync_google2odoo(events - recurrences, default_reminders=default_reminders) # Odoo -> Google + send_updates = not full_sync recurrences = self.env['calendar.recurrence']._get_records_to_sync(full_sync=full_sync) recurrences -= synced_recurrences - recurrences._sync_odoo2google(calendar_service) + recurrences.with_context(send_updates=send_updates)._sync_odoo2google(calendar_service) synced_events |= recurrences.calendar_event_ids - recurrences._get_outliers() synced_events |= synced_recurrences.calendar_event_ids - synced_recurrences._get_outliers() events = self.env['calendar.event']._get_records_to_sync(full_sync=full_sync) - (events - synced_events)._sync_odoo2google(calendar_service) + (events - synced_events).with_context(send_updates=send_updates)._sync_odoo2google(calendar_service) return bool(events | synced_events) or bool(recurrences | synced_recurrences) diff --git a/addons/google_calendar/utils/google_calendar.py b/addons/google_calendar/utils/google_calendar.py index 8e81fb532e0..ae761e19f3d 100644 --- a/addons/google_calendar/utils/google_calendar.py +++ b/addons/google_calendar/utils/google_calendar.py @@ -67,7 +67,8 @@ class GoogleCalendarService(): @requires_auth_token def insert(self, values, token=None, timeout=TIMEOUT): - url = "/calendar/v3/calendars/primary/events?sendUpdates=all" + send_updates = self._context.get('send_updates', True) + url = "/calendar/v3/calendars/primary/events?sendUpdates=%s" % ("all" if send_updates else "none") headers = {'Content-type': 'application/json', 'Authorization': 'Bearer %s' % token} if not values.get('id'): values['id'] = uuid4().hex