summaryrefslogtreecommitdiff
path: root/addons/google_calendar/wizard
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/google_calendar/wizard
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/google_calendar/wizard')
-rw-r--r--addons/google_calendar/wizard/__init__.py4
-rw-r--r--addons/google_calendar/wizard/reset_account.py52
-rw-r--r--addons/google_calendar/wizard/reset_account_views.xml29
3 files changed, 85 insertions, 0 deletions
diff --git a/addons/google_calendar/wizard/__init__.py b/addons/google_calendar/wizard/__init__.py
new file mode 100644
index 00000000..6e2f3e5d
--- /dev/null
+++ b/addons/google_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/google_calendar/wizard/reset_account.py b/addons/google_calendar/wizard/reset_account.py
new file mode 100644
index 00000000..4a724212
--- /dev/null
+++ b/addons/google_calendar/wizard/reset_account.py
@@ -0,0 +1,52 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import fields, models
+
+from odoo.addons.google_calendar.models.google_sync import google_calendar_token
+from odoo.addons.google_calendar.utils.google_calendar import GoogleCalendarService
+
+
+class ResetGoogleAccount(models.TransientModel):
+ _name = 'google.calendar.account.reset'
+ _description = 'Google Calendar Account Reset'
+
+ user_id = fields.Many2one('res.users', required=True)
+ delete_policy = fields.Selection(
+ [('dont_delete', "Leave them untouched"),
+ ('delete_google', "Delete from the current Google 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):
+ google = GoogleCalendarService(self.env['google.service'])
+
+ events = self.env['calendar.event'].search([
+ ('user_id', '=', self.user_id.id),
+ ('google_id', '!=', False)])
+ if self.delete_policy in ('delete_google', 'delete_both'):
+ with google_calendar_token(self.user_id) as token:
+ for event in events:
+ google.delete(event.google_id, token=token)
+
+ if self.delete_policy in ('delete_odoo', 'delete_both'):
+ events.google_id = False
+ events.unlink()
+
+ if self.sync_policy == 'all':
+ events.write({
+ 'google_id': False,
+ 'need_sync': True,
+ })
+
+ self.user_id._set_auth_tokens(False, False, 0)
+ self.user_id.write({
+ 'google_calendar_sync_token': False,
+ 'google_calendar_cal_id': False,
+ })
diff --git a/addons/google_calendar/wizard/reset_account_views.xml b/addons/google_calendar/wizard/reset_account_views.xml
new file mode 100644
index 00000000..e3cbb243
--- /dev/null
+++ b/addons/google_calendar/wizard/reset_account_views.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<odoo>
+ <record id="google_calendar_reset_account_view_form" model="ir.ui.view">
+ <field name="name">google.calendar.account.reset.form</field>
+ <field name="model">google.calendar.account.reset</field>
+ <field name="arch" type="xml">
+ <form>
+ <h1>Reset Google Calendar Account</h1>
+ <group>
+ <field name="delete_policy" widget="radio"/>
+ <field name="sync_policy" widget="radio"/>
+ </group>
+
+ <footer>
+ <button name="reset_account" string="Confirm" type="object" class="btn-primary"/>
+ <button string="Cancel" class="btn-secondary" special="cancel" />
+ </footer>
+ </form>
+ </field>
+ </record>
+
+ <record id="google_calendar_reset_account_action" model="ir.actions.act_window">
+ <field name="name"></field>
+ <field name="type">ir.actions.act_window</field>
+ <field name="res_model">google.calendar.account.reset</field>
+ <field name="view_mode">form</field>
+ <field name="target">new</field>
+ </record>
+</odoo>