summaryrefslogtreecommitdiff
path: root/addons/google_calendar
diff options
context:
space:
mode:
authorAurélien (avd) <avd@odoo.com>2020-10-09 13:56:17 +0000
committerYannick Tivisse <yti@odoo.com>2020-12-10 13:42:53 +0000
commit04aa586a53c2b78cf6646d96d29cbd1e8969de3f (patch)
treece9898a39cd55e21e855f16bdeb580d8d57db97c /addons/google_calendar
parent528adfb313ab3c8d4aeb3309aa7371301ab8085e (diff)
[Fix] google_calendar: fix owner attendee being deleted
Currently when creating a calendar.event with google sync switched on and without adding another attendee, the event is immediatly removed from the calendar view. This is because the user_id is filtered out of the attendee_ids before sending the values to google calendar. Then, at the next sync, google response attendees list does not contain the user_id so Odoo turns that into a [(3, id)] command. Thus, the corresponding event disappear from the current calendar view even though it is still in the DB. This fix is essentially the same as the one implemented in the microsoft_calendar addons available from 14.0 onwards. It adds the calendar owner if the event organizer is not null. This way, even though the owner is not sent as an attendee, it is not removed after google's response. closes odoo/odoo#63167 Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Diffstat (limited to 'addons/google_calendar')
-rw-r--r--addons/google_calendar/models/calendar.py7
-rw-r--r--addons/google_calendar/tests/test_sync_google2odoo.py12
2 files changed, 14 insertions, 5 deletions
diff --git a/addons/google_calendar/models/calendar.py b/addons/google_calendar/models/calendar.py
index 765473509ba..16996b6cebb 100644
--- a/addons/google_calendar/models/calendar.py
+++ b/addons/google_calendar/models/calendar.py
@@ -88,6 +88,12 @@ 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):
+ user = google_event.owner(self.env)
+ google_attendees += [{
+ 'email': user.partner_id.email,
+ 'status': {'response': 'accepted'},
+ }]
emails = [a.get('email') for a in google_attendees]
existing_attendees = self.env['calendar.attendee']
if google_event.exists(self.env):
@@ -167,6 +173,7 @@ class Meeting(models.Model):
'method': "email" if alarm.alarm_type == "email" else "popup",
'minutes': alarm.duration_minutes
} for alarm in self.alarm_ids]
+ attendee_ids = self.attendee_ids.filtered(lambda a: a.partner_id not in self.user_id.partner_id)
values = {
'id': self.google_id,
'start': start,
diff --git a/addons/google_calendar/tests/test_sync_google2odoo.py b/addons/google_calendar/tests/test_sync_google2odoo.py
index bb69331ee46..92abf9a66b0 100644
--- a/addons/google_calendar/tests/test_sync_google2odoo.py
+++ b/addons/google_calendar/tests/test_sync_google2odoo.py
@@ -48,10 +48,11 @@ class TestSyncGoogle2Odoo(SavepointCase):
self.assertEqual(event.description, values.get('description'))
self.assertEqual(event.start, datetime(2020, 1, 13, 15, 55))
self.assertEqual(event.stop, datetime(2020, 1, 13, 18, 55))
- self.assertEqual('admin@yourcompany.example.com', event.attendee_ids.email)
- self.assertEqual('Mitchell Admin', event.attendee_ids.partner_id.name)
+ admin_attendee = event.attendee_ids.filtered(lambda e: e.email == 'admin@yourcompany.example.com')
+ self.assertEqual('admin@yourcompany.example.com', admin_attendee.email)
+ self.assertEqual('Mitchell Admin', admin_attendee.partner_id.name)
self.assertEqual(event.partner_ids, event.attendee_ids.partner_id)
- self.assertEqual('needsAction', event.attendee_ids.state)
+ self.assertEqual('needsAction', admin_attendee.state)
def test_cancelled(self):
google_id = 'oj44nep1ldf8a3ll02uip0c9aa'
@@ -122,8 +123,9 @@ class TestSyncGoogle2Odoo(SavepointCase):
self.assertEqual(event.partner_ids, user.partner_id)
self.assertEqual(event.attendee_ids.partner_id, user.partner_id)
self.sync(gevent)
- self.assertFalse(event.attendee_ids, "The attendee should have been removed")
- self.assertFalse(event.partner_ids, "The partner should have been removed")
+ # User attendee removed but gevent owner might be added after synch.
+ self.assertNotEqual(event.attendee_ids.partner_id, user.partner_id)
+ self.assertNotEqual(event.partner_ids, user.partner_id)
def test_recurrence(self):
recurrence_id = 'oj44nep1ldf8a3ll02uip0c9aa'