Files
odoo_source/addons/microsoft_calendar/controllers/main.py
T
Rémy Baranx (bar) 2fbfbf0dce [FIX] calendar, microsoft_calendar: backport bugfixes from master
As several customers complained about lot of bugs in microsoft_calendar in 14.0,
It has been decided to backport bug fixes of the model layer from master to 14.0,
without the need of an upgrade script (no new field, ...).

In master, we use 2 ids (organizer event id + universal id) instead of only one,
to handle Odoo <-> Outlook sync correctly when several attendees sync their Outlook
calendar with their Odoo calendar. For that, we have added a new field.
To report this bug fix in 14.0, the existing field which stores the organizer event id,
is now a string storing both ids separated by a ':' as follow: 'organizer_event_id:universal_id'.

2 new compute fields have been added to be able to use these 2 ids more easily.

(all commits from the original PR have been squashed to ease forward-port)

closes odoo/odoo#95736

X-original-commit: 5e83318a7240585371efd31e407829793f3e732f
Signed-off-by: Arnaud Joset <arj@odoo.com>
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
2022-07-12 13:21:27 +02:00

50 lines
2.2 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
class MicrosoftCalendarController(http.Controller):
@http.route('/microsoft_calendar/sync_data', type='json', auth='user')
def 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()._sync_microsoft_calendar()
return {
"status": "need_refresh" if need_refresh else "no_new_event_from_microsoft",
"url": ''
}
return {"status": "success"}