diff --git a/models/calendar_event.py b/models/calendar_event.py index 347537acd2ba337a19f85e155b919cd30fa33e13..f2498026dedf8df4fffba486f07511ce5bd2776f 100644 --- a/models/calendar_event.py +++ b/models/calendar_event.py @@ -15,12 +15,18 @@ from netbluemind.calendar.api.VEventSeries import VEventSeries from netbluemind.calendar.api.VEventTransparency import VEventTransparency from netbluemind.core.api.date.BmDateTime import BmDateTime from netbluemind.core.api.date.BmDateTimePrecision import BmDateTimePrecision +from netbluemind.icalendar.api.ICalendarElementAttendee import ICalendarElementAttendee from netbluemind.icalendar.api.ICalendarElementClassification import ( ICalendarElementClassification, ) +from netbluemind.icalendar.api.ICalendarElementCUType import ICalendarElementCUType from netbluemind.icalendar.api.ICalendarElementOrganizer import ( ICalendarElementOrganizer, ) +from netbluemind.icalendar.api.ICalendarElementParticipationStatus import ( + ICalendarElementParticipationStatus, +) +from netbluemind.icalendar.api.ICalendarElementRole import ICalendarElementRole from netbluemind.icalendar.api.ICalendarElementRRule import ICalendarElementRRule from netbluemind.icalendar.api.ICalendarElementRRuleFrequency import ( ICalendarElementRRuleFrequency, @@ -47,9 +53,23 @@ PRIVACY_CONVERTER_O2B = { "private": "Private", "confidential": "Confidential", } +PARTSTATUS_CONVERTER_B20 = { + "NeedsAction": "needsAction", + "Accepted": "accepted", + "Declined": "declined", + "Tentative": "tentative", + "Delegated": "tentative", + "Completed": "accepted", +} +PARTSTATUS_CONVERTER_O2B = { + "needsAction": "NeedsAction", + "accepted": "Accepted", + "declined": "Declined", + "tentative": "Tentative", +} -# TODO: manage attendee_ids, alarm_ids, categories, attachments ? +# TODO: manage alarm_ids, categories, attachments ? # TODO: check if recurrency properly working without exceptions # TODO: manage exceptions in recurrencies class CalendarEvent(models.Model): @@ -137,6 +157,9 @@ class CalendarEvent(models.Model): rrule.byDay[0].day.lower(): True, } ) + + # TODO: Add attendees handling + # Returns data dictionary return data @@ -178,6 +201,38 @@ class CalendarEvent(models.Model): # These fields are required (although not marked as such in doc / code) # Otherwise you get a NullPointerException bm_event.main.attendees = [] + for attendee in self.attendee_ids: + att = ICalendarElementAttendee() + att.cutype = ICalendarElementCUType("Individual") + att.role = ICalendarElementRole("RequiredParticipant") + att.partStatus = ICalendarElementParticipationStatus( + PARTSTATUS_CONVERTER_O2B.get(attendee.state) + ) + att.rsvp = False + att.commonName = attendee.common_name or "" + attendee_user = ( + self.env["res.users"] + .sudo() + .search( + [ + ("partner_id", "=", attendee.partner_id.id), + ("bluemind_user_id", "!=", False), + ] + ) + ) + if attendee_user: + att.dir = ( + "bm://" + + attendee_user.company_id.bluemind_domain + + "/users/" + + attendee_user.bluemind_user_id + ) + att.internal = True + else: + att.internal = False + att.mailto = attendee.partner_id.email or "" + bm_event.main.attendees.append(att) + # The following fields are not computed (yet ?) bm_event.main.categories = [] bm_event.main.attachments = []