[FIX] hr_recruitment: Improve extended_interviewer_ids computation
From 450 to 1.5 ms closes odoo/odoo#90609 X-original-commit: 045d80187c10c74747a3fd35b931cfe0c9862c08 Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import ast
|
||||
from collections import defaultdict
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo import api, fields, models, SUPERUSER_ID, _
|
||||
|
||||
|
||||
class Job(models.Model):
|
||||
@@ -84,8 +84,16 @@ class Job(models.Model):
|
||||
|
||||
@api.depends('application_ids.interviewer_id')
|
||||
def _compute_extended_interviewer_ids(self):
|
||||
# Use SUPERUSER_ID as the search_read is protected in hr_referral
|
||||
results_raw = self.env['hr.applicant'].with_user(SUPERUSER_ID).search_read([
|
||||
('job_id', 'in', self.ids),
|
||||
('interviewer_id', '!=', False)
|
||||
], ['interviewer_id', 'job_id'])
|
||||
interviewers_by_job = defaultdict(set)
|
||||
for result_raw in results_raw:
|
||||
interviewers_by_job[result_raw['job_id'][0]].add(result_raw['interviewer_id'][0])
|
||||
for job in self:
|
||||
job.extended_interviewer_ids = job.application_ids.interviewer_id
|
||||
job.extended_interviewer_ids = [(6, 0, list(interviewers_by_job[job.id]))]
|
||||
|
||||
def _compute_is_favorite(self):
|
||||
for job in self:
|
||||
|
||||
@@ -189,7 +189,9 @@ class Applicant(models.Model):
|
||||
campaign_id = fields.Many2one(ondelete='set null')
|
||||
medium_id = fields.Many2one(ondelete='set null')
|
||||
source_id = fields.Many2one(ondelete='set null')
|
||||
interviewer_id = fields.Many2one('res.users', string='Interviewer', domain="[('share', '=', False), ('company_ids', 'in', company_id)]")
|
||||
interviewer_id = fields.Many2one(
|
||||
'res.users', string='Interviewer', index=True,
|
||||
domain="[('share', '=', False), ('company_ids', 'in', company_id)]")
|
||||
|
||||
@api.onchange('job_id')
|
||||
def _onchange_job_id(self):
|
||||
|
||||
Reference in New Issue
Block a user