hr_applicant.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import fields, models, api
  4. class HrApplicant(models.Model):
  5. _inherit = 'hr.applicant'
  6. applicant_skill_ids = fields.One2many('hr.applicant.skill', 'applicant_id', string="Skills")
  7. skill_ids = fields.Many2many('hr.skill', compute='_compute_skill_ids', store=True)
  8. is_interviewer = fields.Boolean(compute='_compute_is_interviewer')
  9. @api.depends_context('uid')
  10. @api.depends('interviewer_ids', 'job_id.interviewer_ids')
  11. def _compute_is_interviewer(self):
  12. is_recruiter = self.user_has_groups('hr_recruitment.group_hr_recruitment_user')
  13. for applicant in self:
  14. applicant.is_interviewer = not is_recruiter and self.env.user in (applicant.interviewer_ids | applicant.job_id.interviewer_ids)
  15. @api.depends('applicant_skill_ids.skill_id')
  16. def _compute_skill_ids(self):
  17. for applicant in self:
  18. applicant.skill_ids = applicant.applicant_skill_ids.skill_id
  19. def create_employee_from_applicant(self):
  20. self.ensure_one()
  21. action = super().create_employee_from_applicant()
  22. action['context']['default_employee_skill_ids'] = [(0, 0, {
  23. 'skill_id': applicant_skill.skill_id.id,
  24. 'skill_level_id': applicant_skill.skill_level_id.id,
  25. 'skill_type_id': applicant_skill.skill_type_id.id,
  26. }) for applicant_skill in self.applicant_skill_ids]
  27. return action
  28. def _update_employee_from_applicant(self):
  29. vals_list = []
  30. for applicant in self:
  31. existing_skills = applicant.emp_id.employee_skill_ids.skill_id
  32. skills_to_create = applicant.applicant_skill_ids.skill_id - existing_skills
  33. vals_list.extend([{
  34. 'employee_id': applicant.emp_id.id,
  35. 'skill_id': skill.id,
  36. 'skill_level_id': applicant.applicant_skill_ids.filtered(lambda s: s.skill_id == skill).skill_level_id.id,
  37. 'skill_type_id': skill.skill_type_id.id,
  38. } for skill in skills_to_create])
  39. self.env['hr.employee.skill'].create(vals_list)
  40. return super()._update_employee_from_applicant()