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>
51 lines
2.0 KiB
Python
51 lines
2.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import fields, models
|
|
|
|
from odoo.addons.microsoft_calendar.models.microsoft_sync import microsoft_calendar_token
|
|
|
|
|
|
class ResetMicrosoftAccount(models.TransientModel):
|
|
_name = 'microsoft.calendar.account.reset'
|
|
_description = 'Microsoft Calendar Account Reset'
|
|
|
|
user_id = fields.Many2one('res.users', required=True)
|
|
delete_policy = fields.Selection(
|
|
[('dont_delete', "Leave them untouched"),
|
|
('delete_microsoft', "Delete from the current Microsoft Calendar account"),
|
|
('delete_odoo', "Delete from Odoo"),
|
|
('delete_both', "Delete from both"),
|
|
], string="User's Existing Events", required=True, default='dont_delete',
|
|
help="This will only affect events for which the user is the owner")
|
|
sync_policy = fields.Selection([
|
|
('new', "Synchronize only new events"),
|
|
('all', "Synchronize all existing events"),
|
|
], string="Next Synchronization", required=True, default='new')
|
|
|
|
def reset_account(self):
|
|
microsoft = self.env["calendar.event"]._get_microsoft_service()
|
|
|
|
events = self.env['calendar.event'].search([
|
|
('user_id', '=', self.user_id.id),
|
|
('ms_universal_event_id', '!=', False)])
|
|
if self.delete_policy in ('delete_microsoft', 'delete_both'):
|
|
with microsoft_calendar_token(self.user_id) as token:
|
|
for event in events:
|
|
microsoft.delete(event.ms_universal_event_id, token=token)
|
|
|
|
if self.delete_policy in ('delete_odoo', 'delete_both'):
|
|
events.microsoft_id = False
|
|
events.unlink()
|
|
|
|
if self.sync_policy == 'all':
|
|
events.write({
|
|
'microsoft_id': False,
|
|
'need_sync_m': True,
|
|
})
|
|
|
|
self.user_id._set_microsoft_auth_tokens(False, False, 0)
|
|
self.user_id.write({
|
|
'microsoft_calendar_sync_token': False,
|
|
})
|