[REM] calendar: remove attendee_status field

Purpose of this commit to remove `attendee_status` field
which was only usefull in one place where it can be easily
replacable and also this field contains some heavy
computation and added in calendar view which might be
cause some perfomance issues.

So, in this commit remove `attendee_status` field and its
related code and replace it be alternative which gives
desire output as before.

task-3390334

Part-of: odoo/odoo#126768
This commit is contained in:
Kartik Chavda
2023-08-16 16:04:26 +02:00
parent 1ebc6c0044
commit efac5707d1
7 changed files with 26 additions and 52 deletions
+4 -41
View File
@@ -3,7 +3,6 @@
import logging
import math
from collections import defaultdict
from datetime import timedelta
from itertools import repeat
from werkzeug.urls import url_parse
@@ -66,6 +65,10 @@ class Meeting(models.Model):
DISCUSS_ROUTE = 'calendar/join_videocall'
@api.model
def get_state_selections(self):
return Attendee.STATE_SELECTION
@api.model
def default_get(self, fields):
# super default_model='crm.lead' for easier use in addons
@@ -160,8 +163,6 @@ class Meeting(models.Model):
# attendees
attendee_ids = fields.One2many(
'calendar.attendee', 'event_id', 'Participant')
attendee_status = fields.Selection(
Attendee.STATE_SELECTION, string='Attendee Status', compute='_compute_attendee')
partner_ids = fields.Many2many(
'res.partner', 'calendar_event_res_partner_rel',
string='Attendees', default=_default_partners)
@@ -349,12 +350,6 @@ class Meeting(models.Model):
'stop': enddate.replace(tzinfo=None)
})
def _compute_attendee(self):
mapped_attendees = self._find_attendee_batch()
for meeting in self:
attendee = mapped_attendees[meeting.id]
meeting.attendee_status = attendee.state if attendee else 'needsAction'
@api.constrains('start', 'stop', 'start_date', 'stop_date')
def _check_closing_date(self):
for meeting in self:
@@ -1119,38 +1114,6 @@ class Meeting(models.Model):
# TOOLS
# ------------------------------------------------------------
def _find_attendee_batch(self):
""" Return the first attendee where the user connected has been invited
or the attendee selected in the filter that is the owner
from all the meeting_ids in parameters.
"""
result = defaultdict(lambda: self.env['calendar.attendee'])
self_attendees = self.attendee_ids.filtered(lambda a: a.partner_id == self.env.user.partner_id)
for attendee in self_attendees:
result[attendee.event_id.id] = attendee
remaining_events = self - self_attendees.event_id
events_checked_partners = self.env['calendar.filters'].search([
('user_id', '=', self.env.user.id),
('partner_id', 'in', remaining_events.attendee_ids.partner_id.ids),
('partner_checked', '=', True)
]).partner_id
filter_events = self.env['calendar.event']
for event in remaining_events:
event_partners = event.attendee_ids.partner_id
event_checked_partners = events_checked_partners & event_partners
if event.partner_id in event_checked_partners and event.partner_id in event_partners:
filter_events |= event
result[event.id] = event.attendee_ids.filtered(lambda attendee: attendee.partner_id == event.partner_id)[:1]
remaining_events -= filter_events
for event in remaining_events:
event_checked_partners = events_checked_partners & event_partners
attendee = event.attendee_ids.filtered(
lambda a: a.partner_id in event_checked_partners and a.state != "needsAction")
result[event.id] = attendee[:1]
return result
# YTI TODO MASTER: Remove deprecated method
def _find_attendee(self):
""" Return the first attendee where the user connected has been invited
+6 -3
View File
@@ -11,6 +11,10 @@ class Users(models.Model):
_inherit = 'res.users'
def _systray_get_calendar_event_domain(self):
current_user_non_declined_attendee_ids = self.env['calendar.attendee']._search([
('partner_id', '=', self.env.user.partner_id.id),
('state', '!=', 'declined'),
])
tz = self.env.user.tz
start_dt = datetime.datetime.utcnow()
if tz:
@@ -30,7 +34,7 @@ class Users(models.Model):
'&',
['allday', '=', True],
['start_date', '=', fields.Date.to_string(start_date)],
('attendee_ids.partner_id', '=', self.env.user.partner_id.id)]
('attendee_ids', 'in', current_user_non_declined_attendee_ids)]
@api.model
def systray_get_activities(self):
@@ -38,9 +42,8 @@ class Users(models.Model):
meetings_lines = self.env['calendar.event'].search_read(
self._systray_get_calendar_event_domain(),
['id', 'start', 'name', 'allday', 'attendee_status'],
['id', 'start', 'name', 'allday'],
order='start')
meetings_lines = [line for line in meetings_lines if line['attendee_status'] != 'declined']
if meetings_lines:
meeting_label = _("Today's Meetings")
meetings_systray = {
@@ -1,5 +1,6 @@
/** @odoo-module **/
import { onWillStart } from "@odoo/owl";
import { CalendarCommonPopover } from "@web/views/calendar/calendar_common/calendar_common_popover";
import { useService } from "@web/core/utils/hooks";
import { useAskRecurrenceUpdatePolicy } from "@calendar/views/ask_recurrence_update_policy_hook";
@@ -12,8 +13,17 @@ export class AttendeeCalendarCommonPopover extends CalendarCommonPopover {
this.user = useService("user");
this.orm = useService("orm");
this.askRecurrenceUpdatePolicy = useAskRecurrenceUpdatePolicy();
onWillStart(this.onWillStart);
}
async onWillStart() {
// Show status dropdown if user is in attendees list
if (this.isCurrentUserAttendee) {
const stateSelections = await this.env.services.orm.call(
this.props.model.resModel,
"get_state_selections",
);
this.statusColors = {
accepted: "text-success",
declined: "text-danger",
@@ -21,7 +31,7 @@ export class AttendeeCalendarCommonPopover extends CalendarCommonPopover {
needsAction: "text-dark",
};
this.statusInfo = {};
for (const selection of this.props.model.fields.attendee_status.selection) {
for (const selection of stateSelections) {
this.statusInfo[selection[0]] = {
text: selection[1],
color: this.statusColors[selection[0]],
@@ -19,7 +19,7 @@ patch(MockServer.prototype, {
startDate.setUTCHours(0, 0, 0, 0);
const endDate = new Date();
endDate.setUTCHours(23, 59, 59, 999);
const currentPartnerAttendeeIds = this.pyEnv['calendar.attendee'].search([['partner_id', '=', this.pyEnv.currentPartnerId]]);
const currentPartnerAttendeeIds = this.pyEnv['calendar.attendee'].search([['partner_id', '=', this.pyEnv.currentPartnerId], ['state', '!=', 'declined']]);
return [
'&',
'|',
@@ -45,10 +45,10 @@ patch(MockServer.prototype, {
const meetingsLines = this.pyEnv['calendar.event'].searchRead(
this._mockResUsers_SystrayGetCalendarEventDomain(),
{
fields: ['id', 'start', 'name', 'allday', 'attendee_status'],
fields: ['id', 'start', 'name', 'allday'],
order: 'start',
}
).filter(meetingLine => meetingLine['attendee_status'] !== 'declined');
)
if (meetingsLines.length) {
activities.unshift({
id: 'calendar.event', // for simplicity
-2
View File
@@ -112,7 +112,6 @@
<widget name="web_ribbon" title="Archived" bg_color="text-bg-danger" attrs="{'invisible': [('active', '=', True)]}"/>
<field name="res_model" invisible="1" />
<field name="res_id" invisible="1" />
<field name="attendee_status" invisible="1"/>
<field name="active" invisible="1"/>
<field name="user_can_edit" invisible="1"/>
<div class="oe_title mb-3">
@@ -355,7 +354,6 @@
quick_add="%(calendar.view_calendar_event_form_quick_create)d"
color="partner_ids">
<field name="location" attrs="{'invisible': [('location', '=', False)]}" options="{'icon': 'fa fa-map-marker'}"/>
<field name="attendee_status" invisible="1"/>
<field name="attendees_count" invisible="1"/>
<field name="accepted_count" invisible="1"/>
<field name="declined_count" invisible="1"/>
@@ -5,7 +5,7 @@
<field name="model">calendar.event</field>
<field name="inherit_id" ref="calendar.view_calendar_event_calendar"/>
<field name="arch" type="xml">
<field name="attendee_status" position="after">
<field name="location" position="after">
<field name="google_id" invisible="1"/>
</field>
</field>
@@ -5,7 +5,7 @@
<field name="model">calendar.event</field>
<field name="inherit_id" ref="calendar.view_calendar_event_calendar"/>
<field name="arch" type="xml">
<field name="attendee_status" position="after">
<field name="location" position="after">
<field name="microsoft_id" invisible="1"/>
</field>
</field>