From 4d8dee24df24d141db76e1ea8ff607a6318f12dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20-=20Le=20Filament?= <remi@le-filament.com> Date: Wed, 27 Apr 2022 12:02:58 +0200 Subject: [PATCH] [IMP] use function to retrieve calendar uid --- models/calendar_event.py | 2 +- models/res_users.py | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/models/calendar_event.py b/models/calendar_event.py index 1091964..65e21ae 100644 --- a/models/calendar_event.py +++ b/models/calendar_event.py @@ -44,7 +44,7 @@ PRIVACY_CONVERTER_O2B = { } -# TODO: manage attendee_ids, organizer, alarm_ids, priority, status, categories ? +# TODO: manage attendee_ids, organizer, alarm_ids, priority, status, categories, attachments ? # TODO: check if recurrency properly working without exceptions # TODO: manage exceptions in recurrencies class CalendarEvent(models.Model): diff --git a/models/res_users.py b/models/res_users.py index b6cc78e..681d5f2 100644 --- a/models/res_users.py +++ b/models/res_users.py @@ -3,6 +3,7 @@ import logging +from netbluemind.calendar.api.ICalendarUids import ICalendarUids from netbluemind.python.client import BMClient, ServerFault from odoo import _, api, fields, models @@ -80,7 +81,12 @@ class ResUser(models.Model): # TODO : add notification that it works or not return self.bluemind_auth(force=True) - @api.depends("company_id.bluemind_domain", "bluemind_login", "bluemind_password", "is_bm_connection_ok") + @api.depends( + "company_id.bluemind_domain", + "bluemind_login", + "bluemind_password", + "is_bm_connection_ok", + ) def _compute_bluemind_user_id(self): """ This method retrieves the user id from Bluemind client object @@ -95,8 +101,7 @@ class ResUser(models.Model): client = user.bluemind_auth() if client: user.bluemind_user_id = ( - client - .directory(user.company_id.bluemind_domain) + client.directory(user.company_id.bluemind_domain) .getByEmail(user.bluemind_login) .entryUid ) @@ -104,12 +109,14 @@ class ResUser(models.Model): @api.depends("bluemind_user_id") def _compute_bluemind_calendar_uid(self): """ - This method computes default Bluemind calendar_id for the current user - by concatenating calendar:Default: and Bluemind user_id + This method retrieves default calendar uid from Bluemind for the user """ for user in self: - if user.bluemind_user_id: - user.bluemind_calendar_id = "calendar:Default:" + user.bluemind_user_id + client_bm = user.bluemind_auth() + if client_bm and user.bluemind_user_id: + user.bluemind_calendar_id = ICalendarUids( + client_bm.apiKey, client_bm.baseUrl + ).getDefaultUserCalendar(user.bluemind_user_id) def sync_bluemind_calendar(self): """ @@ -191,7 +198,7 @@ class ResUser(models.Model): odoo_events_no_bm = Calendar.search( [("user_id", "=", self.id), ("bluemind_id", "=", False)] ) - odoo_event_no_bm.create_odoo_events_in_bm() + odoo_events_no_bm.create_odoo_events_in_bm() @api.model def _sync_all_bm_calendar(self): -- GitLab