diff --git a/addons/microsoft_calendar/controllers/main.py b/addons/microsoft_calendar/controllers/main.py index 5a4d218091b..400324de722 100644 --- a/addons/microsoft_calendar/controllers/main.py +++ b/addons/microsoft_calendar/controllers/main.py @@ -53,6 +53,7 @@ class MicrosoftCalendarController(CalendarController): }) # If App authorized, and user access accepted, We launch the synchronization + sync_context.update({'dont_notify': True}) need_refresh = request.env.user.sudo().with_context(sync_context)._sync_microsoft_calendar() # If synchronization has been stopped or paused diff --git a/addons/microsoft_calendar/models/calendar.py b/addons/microsoft_calendar/models/calendar.py index b46705888dd..b7c5b2adeee 100644 --- a/addons/microsoft_calendar/models/calendar.py +++ b/addons/microsoft_calendar/models/calendar.py @@ -61,7 +61,7 @@ class Meeting(models.Model): time_offset = timedelta(minutes=5) domain = expression.AND([domain, [('write_date', '>=', self.env.user.microsoft_last_sync_date - time_offset)]]) - self.env['calendar.event'].search(domain).write({ + self.env['calendar.event'].with_context(dont_notify=True).search(domain).write({ 'need_sync_m': True, }) diff --git a/addons/microsoft_calendar/tests/test_update_events.py b/addons/microsoft_calendar/tests/test_update_events.py index b87ba70e899..72bf1af2548 100644 --- a/addons/microsoft_calendar/tests/test_update_events.py +++ b/addons/microsoft_calendar/tests/test_update_events.py @@ -4,6 +4,7 @@ from dateutil.parser import parse import logging import pytz from unittest.mock import patch, ANY +from freezegun import freeze_time from odoo import Command @@ -1393,3 +1394,14 @@ class TestUpdateEvents(TestCommon): "The event organizer must be user B (self.attendee_user) after the event organizer update.") self.assertTrue(self.attendee_user.partner_id.id in new_event.partner_ids.ids, "User B (self.attendee_user) should be listed as attendee after the event organizer update.") + + @freeze_time('2021-09-22') + @patch.object(MicrosoftCalendarService, 'patch') + def test_restart_sync_with_synced_recurrence(self, mock_patch): + """ Ensure that sync restart is not blocked when there are recurrence outliers in Odoo database. """ + # Stop synchronization, set recurrent events as outliers and restart sync with Outlook. + self.organizer_user.stop_microsoft_synchronization() + self.recurrent_events.with_user(self.organizer_user).write({'microsoft_id': False, 'follow_recurrence': False}) + self.attendee_user.with_user(self.attendee_user).restart_microsoft_synchronization() + self.organizer_user.with_user(self.organizer_user).restart_microsoft_synchronization() + self.assertTrue(all(ev.need_sync_m for ev in self.recurrent_events))