From 7159f657a009e461ffc16408db40066b901885d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Lef=C3=A8vre?= Date: Tue, 10 Dec 2019 09:38:43 +0100 Subject: [PATCH] [REF] calendar: Refactor calendar attendees management This commit refactors the event attendees and notifications according to the recurring event refactoring. Some (very) basic reminder tests are also added. Task 2126717 PR #42031 PR Enterprise odoo/enterprise#8006 --- addons/calendar/controllers/main.py | 26 +++ addons/calendar/data/mail_data.xml | 28 +++- .../calendar/models/calendar_alarm_manager.py | 24 +-- addons/calendar/models/calendar_attendee.py | 101 +++++++----- addons/calendar/models/calendar_event.py | 137 ++++++---------- addons/calendar/models/calendar_recurrence.py | 30 +++- addons/calendar/models/ir_http.py | 2 +- addons/calendar/tests/__init__.py | 2 + addons/calendar/tests/test_attendees.py | 70 ++++++++ addons/calendar/tests/test_calendar.py | 6 +- .../tests/test_event_notifications.py | 153 ++++++++++++++++++ .../calendar/tests/test_event_recurrence.py | 1 - 12 files changed, 429 insertions(+), 151 deletions(-) create mode 100644 addons/calendar/tests/test_attendees.py create mode 100644 addons/calendar/tests/test_event_notifications.py diff --git a/addons/calendar/controllers/main.py b/addons/calendar/controllers/main.py index cfecfb96345..11ca7675daf 100644 --- a/addons/calendar/controllers/main.py +++ b/addons/calendar/controllers/main.py @@ -24,6 +24,32 @@ class CalendarController(http.Controller): attendee.do_accept() return self.view(db, token, action, id, view='form') + @http.route('/calendar/recurrence/accept', type='http', auth="calendar") + def accept_recurrence(self, db, token, action, id, **kwargs): + # LUL TODO db required? + attendee = request.env['calendar.attendee'].sudo().search([('access_token', '=', token), ('state', '!=', 'accepted')]) + if attendee: + attendees = request.env['calendar.attendee'].sudo().search([ + ('event_id', 'in', attendee.event_id.recurrence_id.calendar_event_ids.ids), + ('partner_id', '=', attendee.partner_id.id), + ('state', '!=', 'accepted'), + ]) + attendees.do_accept() + return self.view(db, token, action, id, view='form') + + @http.route('/calendar/recurrence/decline', type='http', auth="calendar") + def decline_recurrence(self, db, token, action, id, **kwargs): + # LUL TODO db required? + attendee = request.env['calendar.attendee'].sudo().search([('access_token', '=', token), ('state', '!=', 'declined')]) + if attendee: + attendees = request.env['calendar.attendee'].sudo().search([ + ('event_id', 'in', attendee.event_id.recurrence_id.calendar_event_ids.ids), + ('partner_id', '=', attendee.partner_id.id), + ('state', '!=', 'declined'), + ]) + attendees.do_decline() + return self.view(db, token, action, id, view='form') + @http.route('/calendar/meeting/decline', type='http', auth="calendar") def declined(self, db, token, action, id): registry = registry_get(db) diff --git a/addons/calendar/data/mail_data.xml b/addons/calendar/data/mail_data.xml index 70e1e1a5977..5c056eea138 100644 --- a/addons/calendar/data/mail_data.xml +++ b/addons/calendar/data/mail_data.xml @@ -11,23 +11,26 @@ ${object.partner_id.lang}
- % set colors = {'needsAction': 'grey', 'accepted': 'green', 'tentative': '#FFFF00', 'declined': 'red'} + % set colors = ctx.get('colors', {}) + % set recurrent = object.recurrence_id and not ctx['ignore_recurrence']

Hello ${object.common_name},

${object.event_id.user_id.partner_id.name} invited you for the ${object.event_id.name} meeting of ${object.event_id.user_id.company_id.name}.

- Accept - Decline - View
+ % if not recurrent:
${object.event_id.get_interval('dayname', tz=object.partner_id.tz if not object.event_id.allday else None)} @@ -43,6 +46,7 @@
+ % endif

Details of the event