[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 <kba@odoo.com>
This commit is contained in:
Philippe Wauthy
2022-09-09 11:12:18 +02:00
parent fac9302974
commit 65f6b2fb8e
+10 -7
View File
@@ -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(