Files
odoo_source/addons/hr_recruitment/models/calendar.py
T
Victor FeyensandThibault Delavallee 2457e7f6f4 [IMP] hr_recruitment: use read_group instead of computing len of one2many fields
PURPOSE

Several counter fields are performed inefficiently. They use compute methods
using length of 2many fields instead of making use of more efficient ORM
methods like read_group.

SPECIFICATIONS

No functional change, only technical performance improvements. Purpose is to
improve meeting count performances.

An index on applicant is also added to speedup queries.

LINKS

Task ID 2196182
PR #44662

Co-Authored-By: Victor Feyens <vfe@odoo.com>
Co-Authored-By: Thibault Delavallee <tde@odoo.com>
2020-04-21 12:28:52 +00:00

37 lines
1.6 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
class CalendarEvent(models.Model):
""" Model for Calendar Event """
_inherit = 'calendar.event'
@api.model
def default_get(self, fields):
if self.env.context.get('default_applicant_id'):
self = self.with_context(
default_res_model_id=self.env.ref('hr_recruitment.model_hr_applicant').id,
default_res_id=self.env.context['default_applicant_id']
)
defaults = super(CalendarEvent, self).default_get(fields)
# sync res_model / res_id to opportunity id (aka creating meeting from lead chatter)
if 'applicant_id' not in defaults and defaults.get('res_id') and (defaults.get('res_model') or defaults.get('res_model_id')):
if (defaults.get('res_model') and defaults['res_model'] == 'hr.applicant') or (defaults.get('res_model_id') and self.env['ir.model'].sudo().browse(defaults['res_model_id']).model == 'hr.applicant'):
defaults['applicant_id'] = defaults['res_id']
return defaults
def _compute_is_highlighted(self):
super(CalendarEvent, self)._compute_is_highlighted()
applicant_id = self.env.context.get('active_id')
if self.env.context.get('active_model') == 'hr.applicant' and applicant_id:
for event in self:
if event.applicant_id.id == applicant_id:
event.is_highlighted = True
applicant_id = fields.Many2one('hr.applicant', string="Applicant", index=True, ondelete='set null')