From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- addons/microsoft_calendar/wizard/__init__.py | 4 ++ addons/microsoft_calendar/wizard/reset_account.py | 51 ++++++++++++++++++++++ .../wizard/reset_account_views.xml | 29 ++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 addons/microsoft_calendar/wizard/__init__.py create mode 100644 addons/microsoft_calendar/wizard/reset_account.py create mode 100644 addons/microsoft_calendar/wizard/reset_account_views.xml (limited to 'addons/microsoft_calendar/wizard') diff --git a/addons/microsoft_calendar/wizard/__init__.py b/addons/microsoft_calendar/wizard/__init__.py new file mode 100644 index 00000000..6e2f3e5d --- /dev/null +++ b/addons/microsoft_calendar/wizard/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import reset_account diff --git a/addons/microsoft_calendar/wizard/reset_account.py b/addons/microsoft_calendar/wizard/reset_account.py new file mode 100644 index 00000000..1a21a292 --- /dev/null +++ b/addons/microsoft_calendar/wizard/reset_account.py @@ -0,0 +1,51 @@ +# -*- 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 +from odoo.addons.microsoft_calendar.utils.microsoft_calendar import MicrosoftCalendarService + + +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 = MicrosoftCalendarService(self.env['microsoft.service']) + + events = self.env['calendar.event'].search([ + ('user_id', '=', self.user_id.id), + ('microsoft_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.microsoft_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, + }) diff --git a/addons/microsoft_calendar/wizard/reset_account_views.xml b/addons/microsoft_calendar/wizard/reset_account_views.xml new file mode 100644 index 00000000..1646c6e9 --- /dev/null +++ b/addons/microsoft_calendar/wizard/reset_account_views.xml @@ -0,0 +1,29 @@ + + + + microsoft.calendar.account.reset.form + microsoft.calendar.account.reset + +
+

Reset Outlook Calendar Account

+ + + + + +
+
+
+
+
+ + + + ir.actions.act_window + microsoft.calendar.account.reset + form + new + +
-- cgit v1.2.3