From 702c5c2261fb0b0f6c5eda9357a4c87a40060182 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 15:56:09 +0200 Subject: [PATCH] [ADD] alarm handling Bluemind --> Odoo --- models/calendar_event.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/models/calendar_event.py b/models/calendar_event.py index f249802..341181c 100644 --- a/models/calendar_event.py +++ b/models/calendar_event.py @@ -35,6 +35,8 @@ from netbluemind.icalendar.api.ICalendarElementRRuleWeekDay import ( ICalendarElementRRuleWeekDay, ) from netbluemind.icalendar.api.ICalendarElementStatus import ICalendarElementStatus +from netbluemind.icalendar.api.ICalendarElementVAlarm import ICalendarElementVAlarm +from netbluemind.icalendar.api.ICalendarElementVAlarmAction import ICalendarElementVAlarmAction from netbluemind.python.client import ServerFault from pytz import timezone @@ -69,7 +71,7 @@ PARTSTATUS_CONVERTER_O2B = { } -# TODO: manage alarm_ids, categories, attachments ? +# TODO: manage categories, attachments ? # TODO: check if recurrency properly working without exceptions # TODO: manage exceptions in recurrencies class CalendarEvent(models.Model): @@ -158,7 +160,8 @@ class CalendarEvent(models.Model): } ) - # TODO: Add attendees handling + # TODO: Add attendees handling - how to manage already existing ids ? + # TODO: Add alarms handling - how to manage already existing ids ? # Returns data dictionary return data @@ -200,6 +203,7 @@ class CalendarEvent(models.Model): # These fields are required (although not marked as such in doc / code) # Otherwise you get a NullPointerException + # Manage attendees bm_event.main.attendees = [] for attendee in self.attendee_ids: att = ICalendarElementAttendee() @@ -232,6 +236,16 @@ class CalendarEvent(models.Model): att.internal = False att.mailto = attendee.partner_id.email or "" bm_event.main.attendees.append(att) + # Manage alarms + bm_event.main.alarm = [] + for alarm in self.alarm_ids: + al = ICalendarElementVAlarm() + if alarm.alarm_type = "notification": + al.action = ICalendarElementVAlarmAction("Display") + else: + al.action = ICalendarElementVAlarmAction("Email") + al.trigger = alarm.duration_minutes * -60 + bm_event.main.alarm.append(al) # The following fields are not computed (yet ?) bm_event.main.categories = [] bm_event.main.attachments = [] @@ -359,7 +373,7 @@ class CalendarEvent(models.Model): # AFAICT Bluemind needs all the fields to be provided, # you cannot send only the updated ones - if result and not from_bluemind: + if result and not from_bluemind and self.user_id.is_bm_connection_ok: # Create a list of Bluemind events to be updated bm_events = VEventChanges() bm_events.modify = [] @@ -400,7 +414,8 @@ class CalendarEvent(models.Model): """ # Calls base create() function first odoo_events = super().create(vals_list) - self.create_odoo_events_in_bm() + if self.user_id.is_bm_connection_ok: + self.create_odoo_events_in_bm() return odoo_events def unlink(self, from_bluemind=False): @@ -410,7 +425,7 @@ class CalendarEvent(models.Model): A parameter is added "from_bluemind" to avoid deleting a Bluemind event when deletion is already coming from Bluemind """ - if not from_bluemind: + if not from_bluemind and self.user_id.is_bm_connection_ok: for event in self: # If Odoo event is linked to a Bluemind event if event.bluemind_id: -- GitLab