From ded28245e16dc76f2ee2786883c7daa155d6771a Mon Sep 17 00:00:00 2001 From: Dossogne Bertrand Date: Mon, 3 Oct 2022 10:03:40 +0000 Subject: [PATCH] [FIX] hr_recruitment{,_skills} : employee creation fix If an applicant goes through the salary configurator to create his contract, the employee created will not get the associated sign requests nor the skills as it is working now when creating an employee from the "create employee" button on the applicant page. Also fixes: - a traceback obtained on the salary configurator when having hr_contract_salary installed and not hr_work_entry_contract - a traceback obtained while trying to access an applicant form while in debug mode task-3002185 closes odoo/odoo#104320 X-original-commit: 20d5de3490baaab62715fe0f4f2a9a48dc248d55 Related: odoo/enterprise#33332 Signed-off-by: Kevin Baptiste --- addons/hr_recruitment/models/hr_recruitment.py | 6 ++++++ .../hr_recruitment_skills/models/hr_applicant.py | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/addons/hr_recruitment/models/hr_recruitment.py b/addons/hr_recruitment/models/hr_recruitment.py index cef4f905f3c..5b39be9fb28 100644 --- a/addons/hr_recruitment/models/hr_recruitment.py +++ b/addons/hr_recruitment/models/hr_recruitment.py @@ -430,6 +430,8 @@ class Applicant(models.Model): interviewers_to_clean = old_interviewers - self.interviewer_ids interviewers_to_clean._remove_recruitment_interviewers() self.sudo().interviewer_ids._create_recruitment_interviewers() + if vals.get('emp_id'): + self._update_employee_from_applicant() return res def get_empty_list_help(self, help): @@ -675,6 +677,10 @@ class Applicant(models.Model): dict_act_window['context'] = employee_data return dict_act_window + def _update_employee_from_applicant(self): + # This method is to be overriden + return + def archive_applicant(self): return { 'type': 'ir.actions.act_window', diff --git a/addons/hr_recruitment_skills/models/hr_applicant.py b/addons/hr_recruitment_skills/models/hr_applicant.py index 3ab8e6ba08c..8a13610bac2 100644 --- a/addons/hr_recruitment_skills/models/hr_applicant.py +++ b/addons/hr_recruitment_skills/models/hr_applicant.py @@ -32,3 +32,17 @@ class HrApplicant(models.Model): 'skill_type_id': applicant_skill.skill_type_id.id, }) for applicant_skill in self.applicant_skill_ids] return action + + def _update_employee_from_applicant(self): + vals_list = [] + for applicant in self: + existing_skills = applicant.emp_id.employee_skill_ids.skill_id + skills_to_create = applicant.applicant_skill_ids.skill_id - existing_skills + vals_list.extend([{ + 'employee_id': applicant.emp_id.id, + 'skill_id': skill.id, + 'skill_level_id': applicant.applicant_skill_ids.filtered(lambda s: s.skill_id == skill).skill_level_id.id, + 'skill_type_id': skill.skill_type_id.id, + } for skill in skills_to_create]) + self.env['hr.employee.skill'].create(vals_list) + return super()._update_employee_from_applicant()