Before this commit, errors were introduced when optimizing the synchronization by limiting it to the calendar's view range. For users different than the first to synchronize its calendar, when trying to create events in Odoo before or after the synchronized view range (e.g. 1 month), these events were being auto-archived in Odoo right after their creation in Outlook. This happens because the first range to be sent to Microsoft Outlook is currently defining how much time in the past and in the future the events will be synchronized. After this commit, the previous approach of defining a range of two years for the delta synchronization (events that were last updated) in the future is back temporarily, now with one year in the past. This behavior must be improved considering the calendar view range and must be flexible with the first synchronized view range. Issue from: 3525764 closes odoo/odoo#147366 X-original-commit: 2a503c1b08bd31c9ac0098e774eea8dd5b5c2c1e Signed-off-by: Arnaud Joset (arj) <arj@odoo.com> Signed-off-by: Gabriel de Paula Felix (gdpf) <gdpf@odoo.com>
60 lines
2.6 KiB
Python
60 lines
2.6 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
|
|
|
|
|
|
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
|
|
}
|
|
|
|
# If App authorized, and user access accepted, We launch the synchronization
|
|
need_refresh = request.env.user.sudo().with_context(dont_notify=True)._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"}
|