From 65f6b2fb8e7e29c4123133e97630ca40ecc4722a Mon Sep 17 00:00:00 2001 From: Philippe Wauthy Date: Mon, 5 Sep 2022 13:34:29 +0000 Subject: [PATCH] [FIX] hr_recruitment: fix employee department access When hr_recruitment is installed and a user doesn't have any recruitment access, an access error is raised. This commit fixes the access error, allowing the user to access the hr departments view when hr_recruitment is installed and the user has no hr_recruitment access. task-2971553 closes odoo/odoo#99591 Signed-off-by: Kevin Baptiste --- addons/hr_recruitment/models/hr_department.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/addons/hr_recruitment/models/hr_department.py b/addons/hr_recruitment/models/hr_department.py index e365ac8d4b7..2114b12d696 100644 --- a/addons/hr_recruitment/models/hr_department.py +++ b/addons/hr_recruitment/models/hr_department.py @@ -7,19 +7,22 @@ class HrDepartment(models.Model): _inherit = 'hr.department' new_applicant_count = fields.Integer( - compute='_compute_new_applicant_count', string='New Applicant') + compute='_compute_new_applicant_count', string='New Applicant', compute_sudo=True) new_hired_employee = fields.Integer( compute='_compute_recruitment_stats', string='New Hired Employee') expected_employee = fields.Integer( compute='_compute_recruitment_stats', string='Expected Employee') def _compute_new_applicant_count(self): - applicant_data = self.env['hr.applicant']._read_group( - [('department_id', 'in', self.ids), ('stage_id.sequence', '<=', '1')], - ['department_id'], ['department_id']) - result = dict((data['department_id'][0], data['department_id_count']) for data in applicant_data) - for department in self: - department.new_applicant_count = result.get(department.id, 0) + if self.env.user.has_group('hr_recruitment.group_hr_recruitment_interviewer'): + applicant_data = self.env['hr.applicant']._read_group( + [('department_id', 'in', self.ids), ('stage_id.sequence', '<=', '1')], + ['department_id'], ['department_id']) + result = dict((data['department_id'][0], data['department_id_count']) for data in applicant_data) + for department in self: + department.new_applicant_count = result.get(department.id, 0) + else: + self.new_applicant_count = 0 def _compute_recruitment_stats(self): job_data = self.env['hr.job']._read_group(