diff --git a/addons/microsoft_calendar/models/calendar.py b/addons/microsoft_calendar/models/calendar.py index 6fca702932e..09fae1be09d 100644 --- a/addons/microsoft_calendar/models/calendar.py +++ b/addons/microsoft_calendar/models/calendar.py @@ -131,13 +131,14 @@ class Meeting(models.Model): day_range = int(ICP.get_param('microsoft_calendar.sync.range_days', default=365)) lower_bound = fields.Datetime.subtract(fields.Datetime.now(), days=day_range) upper_bound = fields.Datetime.add(fields.Datetime.now(), days=day_range) - return [ + domain = [ ('partner_ids.user_ids', 'in', self.env.user.id), ('stop', '>', lower_bound), ('start', '<', upper_bound), # Do not sync events that follow the recurrence, they are already synced at recurrence creation '!', '&', '&', ('recurrency', '=', True), ('recurrence_id', '!=', False), ('follow_recurrence', '=', True) ] + return self._extend_microsoft_domain(domain) @api.model diff --git a/addons/microsoft_calendar/models/calendar_recurrence_rule.py b/addons/microsoft_calendar/models/calendar_recurrence_rule.py index 57195abed1a..fc1aa66f77c 100644 --- a/addons/microsoft_calendar/models/calendar_recurrence_rule.py +++ b/addons/microsoft_calendar/models/calendar_recurrence_rule.py @@ -138,7 +138,8 @@ class RecurrenceRule(models.Model): # older versions of the module. When synced, these recurrence may come back from Microsoft after database cleaning # and trigger errors as the records are not properly populated. # We also prevent sync of other user recurrent events. - return [('calendar_event_ids.user_id', '=', self.env.user.id), ('rrule', '!=', False)] + domain = [('calendar_event_ids.user_id', '=', self.env.user.id), ('rrule', '!=', False)] + return self._extend_microsoft_domain(domain) def _cancel_microsoft(self): self.calendar_event_ids._cancel_microsoft() diff --git a/addons/microsoft_calendar/models/microsoft_sync.py b/addons/microsoft_calendar/models/microsoft_sync.py index 68eed99017d..49b169154fa 100644 --- a/addons/microsoft_calendar/models/microsoft_sync.py +++ b/addons/microsoft_calendar/models/microsoft_sync.py @@ -461,14 +461,7 @@ class MicrosoftSync(models.AbstractModel): :param full_sync: If True, all events attended by the user are returned :return: events """ - domain = self._get_microsoft_sync_domain() - if not full_sync: - is_active_clause = (self._active_name, '=', True) if self._active_name else expression.TRUE_LEAF - domain = expression.AND([domain, [ - '|', - '&', ('ms_universal_event_id', '=', False), is_active_clause, - ('need_sync_m', '=', True), - ]]) + domain = self.with_context(full_sync_m=full_sync)._get_microsoft_sync_domain() return self.with_context(active_test=False).search(domain) @api.model @@ -513,3 +506,18 @@ class MicrosoftSync(models.AbstractModel): a given user. """ raise NotImplementedError() + + def _extend_microsoft_domain(self, domain): + """ Extends the sync domain based on the full_sync_m context parameter. + In case of full sync it shouldn't include already synced events. + """ + if self._context.get('full_sync_m', True): + domain = expression.AND([domain, [('ms_universal_event_id', '=', False)]]) + else: + is_active_clause = (self._active_name, '=', True) if self._active_name else expression.TRUE_LEAF + domain = expression.AND([domain, [ + '|', + '&', ('ms_universal_event_id', '=', False), is_active_clause, + ('need_sync_m', '=', True), + ]]) + return domain