summaryrefslogtreecommitdiff
path: root/addons/google_calendar
diff options
context:
space:
mode:
authorYannick Tivisse <yti@odoo.com>2020-03-25 14:21:50 +0100
committerLucas Lefèvre <lul@odoo.com>2020-04-09 10:59:34 +0200
commit1a9be3a8699df6422b4e1fe2d91cbbec48fae9de (patch)
treee703f821c33fd33473e65f7c61640f4e2acf52e0 /addons/google_calendar
parentf2b69186499f7288af6d129986ad3d9d92b010c6 (diff)
[REF] calendar: Lint + Clean code
Diffstat (limited to 'addons/google_calendar')
-rw-r--r--addons/google_calendar/README.md52
-rw-r--r--addons/google_calendar/controllers/main.py9
-rw-r--r--addons/google_calendar/models/calendar.py10
-rw-r--r--addons/google_calendar/models/calendar_recurrence_rule.py3
-rw-r--r--addons/google_calendar/models/google_sync.py12
-rw-r--r--addons/google_calendar/models/res_users.py2
-rw-r--r--addons/google_calendar/tests/test_sync_google2odoo.py3
-rw-r--r--addons/google_calendar/tests/test_sync_odoo2google.py1
-rw-r--r--addons/google_calendar/utils/google_calendar.py20
-rw-r--r--addons/google_calendar/utils/google_event.py4
-rw-r--r--addons/google_calendar/wizard/__init__.py3
-rw-r--r--addons/google_calendar/wizard/reset_account.py22
12 files changed, 41 insertions, 100 deletions
diff --git a/addons/google_calendar/README.md b/addons/google_calendar/README.md
deleted file mode 100644
index 2473da7b922..00000000000
--- a/addons/google_calendar/README.md
+++ /dev/null
@@ -1,52 +0,0 @@
-Google Calendar
----------------
-
-Get your meetings, your leaves... Get your calendar anywhere and never
-forget an event, fully synchronized with the Odoo <a href="https://www.odoo.com/page/crm">Open Source CRM</a>.
-
-Keep an eye on your events
---------------------------
-
-See easily the purpose of the meeting, the start time and also the
-attendee(s)... All that without click on anything...
-
-Create so easily an event
--------------------------
-
-In just one click you can create an event... You can drag and drop your event
-if you want moved it to another timing. You can shrink or extend the event if
-you need to change the start's hours or the duration of your meeting.
-
-Create recurrent event
-----------------------
-
-You can also create recurrent events with only one event. You need to create
-an event each monday of the week ? With only one it's possible, you could
-specify the recurrence and if one of this event is moved, or deleted, it's not
-a problem, you can untie your event from the others recurrences.
-
-See all events you wants
-------------------------
-
-See in your calendar, the event from others peoples where your are attendee,
-but also their events by simply adding your favorites coworkers. Every
-coworker will have their own color in your calendar, and every attendee will
-have their avatar in the event...
-
-Get an email
-------------
-
-You will receive an email at creation of an event where you are attendee, but
-also when this event is updated for some fields as date start, ...
-
-Be notified
------------
-
-You can ask to have a alarm of type 'notification' in your Odoo. You will have
-a notification in you Odoo which ever the page you are.
-
-Google Calendar
----------------
-
-With this plugin, you can synchronize your Odoo calendar with Google Calendar.
-
diff --git a/addons/google_calendar/controllers/main.py b/addons/google_calendar/controllers/main.py
index 465b0fa48b0..76326eb9d85 100644
--- a/addons/google_calendar/controllers/main.py
+++ b/addons/google_calendar/controllers/main.py
@@ -10,9 +10,12 @@ class GoogleCalendarController(http.Controller):
@http.route('/google_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 Google Calendar
- Function return a dictionary with the status : need_config_from_admin, need_auth, need_refresh, 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
+ """ This route/function is called when we want to synchronize Odoo
+ calendar with Google Calendar.
+ Function return a dictionary with the status : need_config_from_admin, need_auth,
+ need_refresh, 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':
GoogleCal = GoogleCalendarService(request.env['google.service'])
diff --git a/addons/google_calendar/models/calendar.py b/addons/google_calendar/models/calendar.py
index 943e8efe820..161ca5d352f 100644
--- a/addons/google_calendar/models/calendar.py
+++ b/addons/google_calendar/models/calendar.py
@@ -12,7 +12,8 @@ class Meeting(models.Model):
_name = 'calendar.event'
_inherit = ['calendar.event', 'google.calendar.sync']
- google_id = fields.Char('Google Calendar Event Id', compute='_compute_google_id', store=True, readonly=False)
+ google_id = fields.Char(
+ 'Google Calendar Event Id', compute='_compute_google_id', store=True, readonly=False)
@api.depends('recurrence_id.google_id')
def _compute_google_id(self):
@@ -65,9 +66,6 @@ class Meeting(models.Model):
'recurrency': google_event.is_recurrent()
}
- if google_event.reminders and google_event.reminders.get('useDefault'):
- values
-
if not google_event.is_recurrence():
values['google_id'] = google_event.id
if google_event.start.get('dateTime'):
@@ -91,7 +89,9 @@ class Meeting(models.Model):
emails = [a.get('email') for a in google_event.attendees]
existing_attendees = self.env['calendar.attendee']
if google_event.exists(self.env):
- existing_attendees = self.env['calendar.attendee'].search([('event_id', '=', google_event.odoo_id(self.env)), ('email', 'in', emails)])
+ existing_attendees = self.env['calendar.attendee'].search([
+ ('event_id', '=', google_event.odoo_id(self.env)),
+ ('email', 'in', emails)])
attendees_by_emails = {a.email: a for a in existing_attendees}
for attendee in google_event.attendees:
email = attendee.get('email')
diff --git a/addons/google_calendar/models/calendar_recurrence_rule.py b/addons/google_calendar/models/calendar_recurrence_rule.py
index 0462bb013f8..c09caef4be1 100644
--- a/addons/google_calendar/models/calendar_recurrence_rule.py
+++ b/addons/google_calendar/models/calendar_recurrence_rule.py
@@ -8,7 +8,6 @@ from odoo import api, fields, models
from addons.google_calendar.utils.google_calendar import GoogleCalendarService
-
class RecurrenceRule(models.Model):
_name = 'calendar.recurrence'
_inherit = ['calendar.recurrence', 'google.calendar.sync']
@@ -121,4 +120,4 @@ class RecurrenceRule(models.Model):
'%s_odoo_id' % self.env.cr.dbname: self.id,
},
}
- return values \ No newline at end of file
+ return values
diff --git a/addons/google_calendar/models/google_sync.py b/addons/google_calendar/models/google_sync.py
index bf8ab27e454..377aaac6a61 100644
--- a/addons/google_calendar/models/google_sync.py
+++ b/addons/google_calendar/models/google_sync.py
@@ -1,11 +1,12 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
import logging
+from contextlib import contextmanager
+from functools import wraps
import requests
import pytz
-from functools import wraps
from dateutil.parser import parse
-from contextlib import contextmanager
from odoo import api, fields, models, registry, _
from odoo.tools import ormcache_context
@@ -52,7 +53,7 @@ def google_calendar_token(user):
# Rollback manually first to avoid concurrent access errors/deadlocks.
user.env.cr.rollback()
with user.pool.cursor() as cr:
- env= user.env(cr=cr)
+ env = user.env(cr=cr)
user.with_env(env)._set_auth_tokens(False, False, 0)
raise e
@@ -155,7 +156,7 @@ class GoogleSync(models.AbstractModel):
cancelled_odoo._cancel()
synced_records = new_odoo + cancelled_odoo
- for gevent in existing - cancelled :
+ for gevent in existing - cancelled:
# Last updated wins.
# This could be dangerous if google server time and odoo server time are different
updated = parse(gevent.updated)
@@ -169,7 +170,6 @@ class GoogleSync(models.AbstractModel):
@after_commit
def _google_delete(self, google_service: GoogleCalendarService, google_id, timeout=TIMEOUT):
- print('DELETE', google_id)
with google_calendar_token(self.env.user.sudo()) as token:
if token:
google_service.delete(google_id, token=token, timeout=timeout)
@@ -177,7 +177,6 @@ class GoogleSync(models.AbstractModel):
@after_commit
def _google_patch(self, google_service: GoogleCalendarService, google_id, values, timeout=TIMEOUT):
- print('Patch', google_id)
with google_calendar_token(self.env.user.sudo()) as token:
if token:
google_service.patch(google_id, values, token=token, timeout=timeout)
@@ -185,7 +184,6 @@ class GoogleSync(models.AbstractModel):
@after_commit
def _google_insert(self, google_service: GoogleCalendarService, values, timeout=TIMEOUT):
- print('insert')
if not values:
return
with google_calendar_token(self.env.user.sudo()) as token:
diff --git a/addons/google_calendar/models/res_users.py b/addons/google_calendar/models/res_users.py
index 28a08f69558..70c2079184b 100644
--- a/addons/google_calendar/models/res_users.py
+++ b/addons/google_calendar/models/res_users.py
@@ -62,7 +62,7 @@ class User(models.Model):
}
try:
- dummy, response, dummy = self.env['google.service']._do_request(GOOGLE_TOKEN_ENDPOINT, params=data, headers=headers, type='POST', preuri='')
+ dummy, response, dummy = self.env['google.service']._do_request(GOOGLE_TOKEN_ENDPOINT, params=data, headers=headers, method='POST', preuri='')
ttl = response.get('expires_in')
self.write({
'google_calendar_token': response.get('access_token'),
diff --git a/addons/google_calendar/tests/test_sync_google2odoo.py b/addons/google_calendar/tests/test_sync_google2odoo.py
index 8194584439b..1ada7e88157 100644
--- a/addons/google_calendar/tests/test_sync_google2odoo.py
+++ b/addons/google_calendar/tests/test_sync_google2odoo.py
@@ -262,7 +262,7 @@ class TestSyncGoogle2Odoo(SavepointCase):
'reminders': {'useDefault': True},
'updated': self.now,
},
- { # Third event has been moved
+ { # Third event has been moved
'id': '%s_20200113' % recurrence_id,
'summary': 'Pricing new update',
'start': {'date': '2020-01-18'},
@@ -308,4 +308,3 @@ class TestSyncGoogle2Odoo(SavepointCase):
self.assertEqual(events[1].start_date, date(2020, 1, 15))
self.assertEqual(events[0].google_id, '%s_20200108' % recurrence_id)
self.assertEqual(events[1].google_id, '%s_20200115' % recurrence_id)
-
diff --git a/addons/google_calendar/tests/test_sync_odoo2google.py b/addons/google_calendar/tests/test_sync_odoo2google.py
index 6cc4ff72e71..ae40fe9c57a 100644
--- a/addons/google_calendar/tests/test_sync_odoo2google.py
+++ b/addons/google_calendar/tests/test_sync_odoo2google.py
@@ -184,7 +184,6 @@ class TestSyncOdoo2Google(SavepointCase):
'recurrency': True,
'rrule': 'FREQ=WEEKLY;COUNT=2;BYDAY=WE',
})
- event.recurrence_id
to_delete = self.env['calendar.event'].with_context(active_test=False).search([('google_id', '=', google_id)])
self.assertTrue(to_delete)
self.assertFalse(to_delete.active)
diff --git a/addons/google_calendar/utils/google_calendar.py b/addons/google_calendar/utils/google_calendar.py
index 4532ce1b708..20032241362 100644
--- a/addons/google_calendar/utils/google_calendar.py
+++ b/addons/google_calendar/utils/google_calendar.py
@@ -37,25 +37,20 @@ class GoogleCalendarService():
if sync_token:
params['syncToken'] = sync_token
try:
- status, data, time = self.google_service._do_request(url, params, headers, type='GET', timeout=timeout)
+ status, data, time = self.google_service._do_request(url, params, headers, method='GET', timeout=timeout)
except requests.HTTPError as e:
if e.response.status_code == 410 and 'fullSyncRequired' in str(e.response.content):
raise InvalidSyncToken("Invalid sync token. Full sync required")
raise e
- import pprint
- pprint.pprint(data)
-
events = data.get('items', [])
next_page_token = data.get('nextPageToken')
while next_page_token:
params = {'access_token': token, 'pageToken': next_page_token}
- status, data, time = self.google_service._do_request(url, params, headers, type='GET', timeout=timeout)
+ status, data, time = self.google_service._do_request(url, params, headers, method='GET', timeout=timeout)
next_page_token = data.get('nextPageToken')
events += data.get('items', [])
- pprint.pprint(data)
-
next_sync_token = data.get('nextSyncToken')
default_reminders = data.get('defaultReminders')
@@ -63,31 +58,26 @@ class GoogleCalendarService():
@requires_auth_token
def insert(self, values, token=None, timeout=TIMEOUT):
- print("INSERT")
url = "/calendar/v3/calendars/primary/events"
headers = {'Content-type': 'application/json', 'Authorization': 'Bearer %s' % token}
if not values.get('id'):
values['id'] = uuid4().hex
- import pprint
- pprint.pprint(values)
- self.google_service._do_request(url, json.dumps(values), headers, type='POST', timeout=timeout)
+ self.google_service._do_request(url, json.dumps(values), headers, method='POST', timeout=timeout)
return values['id']
@requires_auth_token
def patch(self, event_id, values, token=None, timeout=TIMEOUT):
- print("PATCH")
url = "/calendar/v3/calendars/primary/events/%s" % event_id
headers = {'Content-type': 'application/json', 'Authorization': 'Bearer %s' % token}
- self.google_service._do_request(url, json.dumps(values), headers, type='PUT', timeout=timeout)
+ self.google_service._do_request(url, json.dumps(values), headers, method='PUT', timeout=timeout)
@requires_auth_token
def delete(self, event_id, token=None, timeout=TIMEOUT):
- print("DELETE")
url = "/calendar/v3/calendars/primary/events/%s" % event_id
headers = {'Content-type': 'application/json'}
params = {'access_token': token}
try:
- self.google_service._do_request(url, params, headers=headers, type='DELETE', timeout=timeout)
+ self.google_service._do_request(url, params, headers=headers, method='DELETE', timeout=timeout)
except requests.HTTPError as e:
# For some unknown reason Google can also return a 403 response when the event is already cancelled.
if e.response.status_code not in (410, 403):
diff --git a/addons/google_calendar/utils/google_event.py b/addons/google_calendar/utils/google_event.py
index a1274049224..fc962a1d073 100644
--- a/addons/google_calendar/utils/google_event.py
+++ b/addons/google_calendar/utils/google_event.py
@@ -169,6 +169,6 @@ class GoogleEvent(abc.Set):
def _get_model(self, env):
if all([e.is_recurrence() for e in self]):
return env['calendar.recurrence']
- elif all([not e.is_recurrence() for e in self]):
+ if all([not e.is_recurrence() for e in self]):
return env['calendar.event']
- raise TypeError("Mixing Google events and Google recurrences") \ No newline at end of file
+ raise TypeError("Mixing Google events and Google recurrences")
diff --git a/addons/google_calendar/wizard/__init__.py b/addons/google_calendar/wizard/__init__.py
index 4c3bcce28a6..6e2f3e5df4e 100644
--- a/addons/google_calendar/wizard/__init__.py
+++ b/addons/google_calendar/wizard/__init__.py
@@ -1 +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
index 8d2b992aa23..e942ecba34c 100644
--- a/addons/google_calendar/wizard/reset_account.py
+++ b/addons/google_calendar/wizard/reset_account.py
@@ -12,13 +12,13 @@ class ResetGoogleAccount(models.TransientModel):
_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")
+ 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"),
@@ -27,13 +27,15 @@ class ResetGoogleAccount(models.TransientModel):
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'):
+ 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'):
+ if self.delete_policy in ('delete_odoo', 'delete_both'):
events.google_id = False
events.unlink()