From 69059db23a7a9d1ad152d5a1a2b8166b3c6ed11f Mon Sep 17 00:00:00 2001 From: Leonardo Pavan Rocha Date: Wed, 6 Sep 2023 13:07:26 +0200 Subject: [PATCH] [IMP] calendar: start showing attendee state in calendar form view MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds the attendee state in the form view of a calendar event. To accomplish this, a computed field was added that would get the response status for the attendee related to the current user that’s accessing the event form view. If this computed field is falsy, the field is not shown in the form view. task-3455051 task-3389317 Part-of: odoo/odoo#138670 --- addons/calendar/models/calendar_attendee.py | 8 ++++---- addons/calendar/models/calendar_event.py | 17 +++++++++++++++++ .../common/attendee_calendar_common_popover.xml | 6 +++--- addons/calendar/views/calendar_views.xml | 12 ++++++------ 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/addons/calendar/models/calendar_attendee.py b/addons/calendar/models/calendar_attendee.py index 986e8c01ce4..fb93a39aa49 100644 --- a/addons/calendar/models/calendar_attendee.py +++ b/addons/calendar/models/calendar_attendee.py @@ -24,9 +24,9 @@ class Attendee(models.Model): STATE_SELECTION = [ ('needsAction', 'Needs Action'), - ('tentative', 'Uncertain'), - ('declined', 'Declined'), - ('accepted', 'Accepted'), + ('tentative', 'Maybe'), + ('declined', 'No'), + ('accepted', 'Yes'), ] # event @@ -40,7 +40,7 @@ class Attendee(models.Model): access_token = fields.Char('Invitation Token', default=_default_access_token) mail_tz = fields.Selection(_tz_get, compute='_compute_mail_tz', help='Timezone used for displaying time in the mail template') # state - state = fields.Selection(STATE_SELECTION, string='Status', readonly=True, default='needsAction') + state = fields.Selection(STATE_SELECTION, string='Status', default='needsAction') availability = fields.Selection( [('free', 'Available'), ('busy', 'Busy')], 'Available/Busy', readonly=True) diff --git a/addons/calendar/models/calendar_event.py b/addons/calendar/models/calendar_event.py index c753ef2e8d7..6e46121c572 100644 --- a/addons/calendar/models/calendar_event.py +++ b/addons/calendar/models/calendar_event.py @@ -183,6 +183,9 @@ class Meeting(models.Model): # attendees attendee_ids = fields.One2many( 'calendar.attendee', 'event_id', 'Participant') + current_attendee = fields.Many2one("calendar.attendee", compute="_compute_current_attendee", search="_search_current_attendee") + current_status = fields.Selection(string="Attending?", related="current_attendee.state", readonly=False) + should_show_status = fields.Boolean(compute="_compute_should_show_status") partner_ids = fields.Many2many( 'res.partner', 'calendar_event_res_partner_rel', string='Attendees', default=_default_partners) @@ -248,6 +251,20 @@ class Meeting(models.Model): awaiting_count = fields.Integer(compute="_compute_attendees_count") user_can_edit = fields.Boolean(compute='_compute_user_can_edit') + @api.depends("attendee_ids") + def _compute_should_show_status(self): + for event in self: + event.should_show_status = event.current_attendee and any(attendee.partner_id != self.env.user.partner_id for attendee in event.attendee_ids) + + @api.depends('attendee_ids', 'attendee_ids.state') + def _compute_current_attendee(self): + for event in self: + current_attendee = event.attendee_ids.filtered(lambda attendee: attendee.partner_id == self.env.user.partner_id) + event.current_attendee = current_attendee and current_attendee[0] + + def _search_current_attendee(self, operator, value): + return [("id", operator, value)] + @api.depends('attendee_ids', 'attendee_ids.state', 'partner_ids') def _compute_attendees_count(self): for event in self: diff --git a/addons/calendar/static/src/views/attendee_calendar/common/attendee_calendar_common_popover.xml b/addons/calendar/static/src/views/attendee_calendar/common/attendee_calendar_common_popover.xml index f069e13da56..c2b3745e240 100644 --- a/addons/calendar/static/src/views/attendee_calendar/common/attendee_calendar_common_popover.xml +++ b/addons/calendar/static/src/views/attendee_calendar/common/attendee_calendar_common_popover.xml @@ -30,13 +30,13 @@ - Accept + Yes - Decline + No - Uncertain + Maybe diff --git a/addons/calendar/views/calendar_views.xml b/addons/calendar/views/calendar_views.xml index d0b474f1734..08c6adff3e0 100644 --- a/addons/calendar/views/calendar_views.xml +++ b/addons/calendar/views/calendar_views.xml @@ -131,9 +131,9 @@
-
+
@@ -190,7 +190,7 @@