Files
odoo_source/addons/microsoft_calendar/controllers/main.py
T
Gabriel de Paula Felix (gdpf) 3a4f7eaf35 [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>
2023-12-05 21:15:24 +00:00

72 lines
3.1 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import http
from odoo.http import request
from odoo.addons.calendar.controllers.main import CalendarController
from dateutil.parser import parse
class MicrosoftCalendarController(CalendarController):
@http.route('/microsoft_calendar/sync_data', type='json', auth='user')
def microsoft_calendar_sync_data(self, model, **kw):
""" This route/function is called when we want to synchronize Odoo
calendar with Microsoft Calendar.
Function return a dictionary with the status : need_config_from_admin, need_auth,
need_refresh, sync_stopped, success if not calendar_event
The dictionary may contains an url, to allow Odoo Client to redirect user on
this URL for authorization for example
"""
if model == 'calendar.event':
MicrosoftCal = request.env["calendar.event"]._get_microsoft_service()
# Checking that admin have already configured Microsoft API for microsoft synchronization !
client_id = request.env['ir.config_parameter'].sudo().get_param('microsoft_calendar_client_id')
if not client_id or client_id == '':
action_id = ''
if MicrosoftCal._can_authorize_microsoft(request.env.user):
action_id = request.env.ref('base_setup.action_general_configuration').id
return {
"status": "need_config_from_admin",
"url": '',
"action": action_id
}
# Checking that user have already accepted Odoo to access his calendar !
if not MicrosoftCal.is_authorized(request.env.user):
url = MicrosoftCal._microsoft_authentication_url(from_url=kw.get('fromurl'))
return {
"status": "need_auth",
"url": url
}
# Get synchronization time window form calendar view if received through parameters.
sync_context = {}
range_start_date = kw.get('rangeStart')
range_end_date = kw.get('rangeEnd')
if range_start_date and range_end_date:
sync_context.update({
'range_start_date': parse(range_start_date),
'range_end_date': parse(range_end_date),
})
# 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
sync_status = request.env.user._get_microsoft_sync_status()
if not need_refresh and sync_status != "sync_active":
return {
"status": sync_status,
"url": ''
}
return {
"status": "need_refresh" if need_refresh else "no_new_event_from_microsoft",
"url": ''
}
return {"status": "success"}