[FIX] microsoft_calendar: recurrence outliers blocking sync restart and account reset

Before this commit, when restarting the synchronization, recurrence outliers were blocking the synchronization restarting because they were being considered as complete recurrences, although they must be treated as single events. Additionaly, when resetting the Outlook account, choosing to delete events in Odoo should not be allowed since recurrence outliers must be treated as single events.

After this commit, this issue is now solved by adding the 'dont_notify' param in the context to skip the validation of single events when restarting the sync. Additionaly, when resetting the Outlook account, the forbiddance of deleting events in Odoo is not a blocking point anymore.

closes odoo/odoo#144928

Task-id: 3617978
X-original-commit: c0e1bbe
Signed-off-by: Arnaud Joset (arj) <arj@odoo.com>
Signed-off-by: Gabriel de Paula Felix (gdpf) <gdpf@odoo.com>
This commit is contained in:
Gabriel de Paula Felix (gdpf)
2023-12-05 21:15:24 +00:00
parent 009c4c6a78
commit 3a4f7eaf35
3 changed files with 14 additions and 1 deletions
@@ -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
+1 -1
View File
@@ -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,
})
@@ -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))