diff --git a/addons/microsoft_calendar/static/src/js/microsoft_calendar.js b/addons/microsoft_calendar/static/src/js/microsoft_calendar.js index 35fcac650be..4a1c8c22687 100644 --- a/addons/microsoft_calendar/static/src/js/microsoft_calendar.js +++ b/addons/microsoft_calendar/static/src/js/microsoft_calendar.js @@ -19,6 +19,7 @@ const MicrosoftCalendarModel = CalendarModel.include({ init: function () { this._super.apply(this, arguments); this.microsoft_is_sync = true; + this.microsoft_pending_sync = false; }, /** @@ -36,6 +37,10 @@ const MicrosoftCalendarModel = CalendarModel.include({ */ async _loadCalendar() { const _super = this._super.bind(this); + // When the calendar synchronization takes some time, prevents retriggering the sync while navigating the calendar. + if (this.microsoft_pending_sync) { + return _super(...arguments); + } try { await Promise.race([ new Promise(resolve => setTimeout(resolve, 1000)), @@ -46,12 +51,14 @@ const MicrosoftCalendarModel = CalendarModel.include({ error.event.preventDefault(); } console.error("Could not synchronize Outlook events now.", error); + this.microsoft_pending_sync = false; } return _super(...arguments); }, _syncMicrosoftCalendar(shadow = false) { var self = this; + this.microsoft_pending_sync = true; return this._rpc({ route: '/microsoft_calendar/sync_data', params: { @@ -64,6 +71,7 @@ const MicrosoftCalendarModel = CalendarModel.include({ } else if (result.status === "no_new_event_from_microsoft" || result.status === "need_refresh") { self.microsoft_is_sync = true; } + self.microsoft_pending_sync = false; return result }); },