From e00622efee3a4909adb020ee30fd95711a8f9e62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Baranx=20=28bar=29?= Date: Wed, 30 Mar 2022 09:29:01 +0000 Subject: [PATCH] [FIX] microsoft_calendar: cancelled event without Odoo organizer When an event is created in Outlook by an Outlook user (user A) who does not exist in Odoo but who invites an Odoo user (user B) who syncs his calendar with his Outlook calendar, the event will appear in the user B Odoo calendar. If user A cancels this event in Outlook, then when user B syncs his Odoo calendar, the event must be removed. closes odoo/odoo#87844 Task-id: 2746046 X-original-commit: f54a56a91e75e3de8b54a7c6c76164929a11a431 Signed-off-by: Arnaud Joset --- addons/microsoft_calendar/models/calendar.py | 13 +++++++++---- .../tests/test_sync_microsoft2odoo.py | 6 ++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/addons/microsoft_calendar/models/calendar.py b/addons/microsoft_calendar/models/calendar.py index 0e877b21862..6fca702932e 100644 --- a/addons/microsoft_calendar/models/calendar.py +++ b/addons/microsoft_calendar/models/calendar.py @@ -485,9 +485,14 @@ class Meeting(models.Model): return values def _cancel_microsoft(self): - # only owner can delete => others refuse the event + """ + Cancel an Microsoft event. + There are 2 cases: + 1) the organizer is an Odoo user: he's the only one able to delete the Odoo event. Attendees can just decline. + 2) the organizer is NOT an Odoo user: any attendee should remove the Odoo event. + """ user = self.env.user - my_cancelled_records = self.filtered(lambda e: e.user_id == user) - super(Meeting, my_cancelled_records)._cancel_microsoft() - attendees = (self - my_cancelled_records).attendee_ids.filtered(lambda a: a.partner_id == user.partner_id) + records = self.filtered(lambda e: not e.user_id or e.user_id == user) + super(Meeting, records)._cancel_microsoft() + attendees = (self - records).attendee_ids.filtered(lambda a: a.partner_id == user.partner_id) attendees.do_decline() diff --git a/addons/microsoft_calendar/tests/test_sync_microsoft2odoo.py b/addons/microsoft_calendar/tests/test_sync_microsoft2odoo.py index 524864043c5..90b941e6418 100644 --- a/addons/microsoft_calendar/tests/test_sync_microsoft2odoo.py +++ b/addons/microsoft_calendar/tests/test_sync_microsoft2odoo.py @@ -295,6 +295,12 @@ class TestSyncMicrosoft2Odoo(TransactionCase): self.assertEqual(recurrent_event.calendar_event_ids[1].start, datetime(2021, 7, 17, 15, 00)) self.assertEqual(recurrent_event.calendar_event_ids[1].stop, datetime(2021, 7, 17, 15, 30)) + events = recurrent_event.calendar_event_ids.sorted(key=lambda e: e.start) + self.assertEqual(events[0].start, datetime(2021, 7, 15, 15, 00)) + self.assertEqual(events[0].stop, datetime(2021, 7, 15, 15, 30)) + self.assertEqual(events[1].start, datetime(2021, 7, 17, 15, 00)) + self.assertEqual(events[1].stop, datetime(2021, 7, 17, 15, 30)) + def test_use_classic_location(self): ms_event = self.single_event