[IMP] calendar: start showing attendee state in calendar form view

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
This commit is contained in:
Leonardo Pavan Rocha
2023-10-23 20:07:23 +00:00
parent d87d5fe51f
commit 69059db23a
4 changed files with 30 additions and 13 deletions
+4 -4
View File
@@ -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)
+17
View File
@@ -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:
@@ -30,13 +30,13 @@
<i t-attf-class="fa fa-circle o-calendar-attendee-status-icon #{selectedStatusInfo.color}"/> <span class="o-calendar-attendee-status-text" t-esc="selectedStatusInfo.text"></span>
</t>
<DropdownItem onSelected="() => this.changeAttendeeStatus('accepted')">
<i class="fa fa-circle text-success"/> Accept
<i class="fa fa-circle text-success"/> Yes
</DropdownItem>
<DropdownItem onSelected="() => this.changeAttendeeStatus('declined')">
<i class="fa fa-circle text-danger"/> Decline
<i class="fa fa-circle text-danger"/> No
</DropdownItem>
<DropdownItem onSelected="() => this.changeAttendeeStatus('tentative')">
<i class="fa fa-circle text-muted"/> Uncertain
<i class="fa fa-circle text-muted"/> Maybe
</DropdownItem>
</Dropdown>
</div>
+6 -6
View File
@@ -131,9 +131,9 @@
<field name="stop_date" invisible="1" />
<field name="stop" invisible="1" />
<div class="d-flex gap-2" colspan="2">
<div invisible="allday">
<div class="d-flex align-items-start" invisible="allday">
<label for="duration" class="pe-2 fw-bold text-900" invisible="allday"/>
<field name="duration" widget="float_time" string="Duration" class="oe_inline" readonly="(id and recurrency) or not user_can_edit"/>
<field name="duration" widget="float_time" string="Duration" class="oe_inline pe-2" readonly="(id and recurrency) or not user_can_edit"/>
<span> hours</span>
</div>
<div>
@@ -190,7 +190,7 @@
<label for="videocall_location" class="opacity-100"/>
<div col="2">
<field name="videocall_location" string="Videocall URL" widget="CopyClipboardChar" force_save="1" readonly="videocall_source == 'discuss'"/>
<button name="clear_videocall_location" type="object" class="btn btn-link"
<button name="clear_videocall_location" type="object" class="btn btn-link ps-0"
invisible="not videocall_location" context="{'recurrence_update': recurrence_update}">
<span class="fa fa-times"></span><span> Clear meeting</span>
</button>
@@ -211,11 +211,11 @@
<field name="privacy" readonly="not user_can_edit" nolabel="1"/>
</div>
<field name="user_id" widget="many2one_avatar_user" readonly="not user_can_edit"/>
<field name="description" options="{'height': 100}"/>
<field name="description" options="{'height': 100}" placeholder="Add description"/>
</group>
<group>
<field name="should_show_status" invisible="1"/>
<field name="current_status" class="w-auto" required="should_show_status" readonly="not should_show_status" invisible="not should_show_status"/>
<field name="alarm_ids" widget="many2many_tags" options="{'no_quick_create': True}"/>
<div class="o_row" colspan="2">
<div colspan="1">