diff --git a/addons/microsoft_calendar/utils/microsoft_calendar.py b/addons/microsoft_calendar/utils/microsoft_calendar.py index b22cb2866cd..db91998a451 100644 --- a/addons/microsoft_calendar/utils/microsoft_calendar.py +++ b/addons/microsoft_calendar/utils/microsoft_calendar.py @@ -61,7 +61,7 @@ class MicrosoftCalendarService(): end_date = self.microsoft_service._context.get('range_end_date') if start_date and end_date: start_date = start_date.strftime("%Y-%m-%dT00:00:00Z") - end_date = end_date.strftime("%Y-%m-%dT00:00:00Z") + end_date = fields.Datetime.add(end_date, days=1).strftime("%Y-%m-%dT00:00:00Z") else: ICP = self.microsoft_service.env['ir.config_parameter'].sudo() day_range = int(ICP.get_param('microsoft_calendar.sync.range_days', default=365)) @@ -110,6 +110,20 @@ class MicrosoftCalendarService(): return self._get_events_delta(token=token, timeout=timeout) raise e + # update sync min and max date range after retrieving occurrences, they must be entirely created once + # otherwise we would have to retrieve everytime all occurrences from all recurrences in _get_occurrence_details + min_start_dt = self.microsoft_service._context.get('range_start_date') + max_stop_dt = self.microsoft_service._context.get('range_end_date') + for event in events: + if event.get('type') == 'occurrence' and event.get('start') and event.get('stop'): + # get time values and update min start and max stop from sync context range + time_values = self.microsoft_service.env['calendar.event']._microsoft_to_odoo_recurrence_values(MicrosoftEvent([event])) + if not min_start_dt or time_values['start'] < min_start_dt: + min_start_dt = time_values['start'] + if not max_stop_dt or time_values['stop'] > max_stop_dt: + max_stop_dt = time_values['stop'] + self.microsoft_service = self.microsoft_service.with_context(range_start_date=min_start_dt, range_end_date=max_stop_dt) + # event occurrences (from a recurrence) are retrieved separately to get all their info, # # and mainly the iCalUId attribute which is not provided by the 'get_delta' api end point events = [e for e in events if e.get('type') != 'occurrence']