Files
odoo_source/addons/calendar/models/res_users.py
T
Kartik Chavda efac5707d1 [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
2023-08-16 16:04:26 +02:00

60 lines
2.2 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import datetime
from odoo import api, fields, models, modules, _
from pytz import timezone, UTC
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:
start_date = timezone(tz).localize(start_dt).astimezone(UTC).date()
else:
start_date = datetime.date.today()
end_dt = datetime.datetime.combine(start_date, datetime.time.max)
if tz:
end_dt = timezone(tz).localize(end_dt).astimezone(UTC)
return ['&', '|',
'&',
'|',
['start', '>=', fields.Datetime.to_string(start_dt)],
['stop', '>=', fields.Datetime.to_string(start_dt)],
['start', '<=', fields.Datetime.to_string(end_dt)],
'&',
['allday', '=', True],
['start_date', '=', fields.Date.to_string(start_date)],
('attendee_ids', 'in', current_user_non_declined_attendee_ids)]
@api.model
def systray_get_activities(self):
res = super(Users, self).systray_get_activities()
meetings_lines = self.env['calendar.event'].search_read(
self._systray_get_calendar_event_domain(),
['id', 'start', 'name', 'allday'],
order='start')
if meetings_lines:
meeting_label = _("Today's Meetings")
meetings_systray = {
'id': self.env['ir.model']._get('calendar.event').id,
'type': 'meeting',
'name': meeting_label,
'model': 'calendar.event',
'icon': modules.module.get_module_icon(self.env['calendar.event']._original_module),
'meetings': meetings_lines,
}
res.insert(0, meetings_systray)
return res