diff --git a/yuthon_hr_employee/models/inherit_hr_job.py b/yuthon_hr_employee/models/inherit_hr_job.py index eb576ff56..b5468f1c4 100644 --- a/yuthon_hr_employee/models/inherit_hr_job.py +++ b/yuthon_hr_employee/models/inherit_hr_job.py @@ -113,19 +113,20 @@ class HrJob(models.Model): job.sudo().write( {'company_id': company_id}) - # def write(self, vals): - # res = super(HrJob, self).write(vals) - # if 'job_personnel_ids' in vals: - # for job in self: - # for employee in job.job_personnel_ids: - # other_jobs = self.env['hr.job'].search([ - # ('job_personnel_ids', 'in', employee.id), - # ('id', '!=', job.id) - # ]) - # if other_jobs: - # other_jobs.write({'job_personnel_ids': [(3, employee.id)]}) - # employee.write({'job_id': job.id}) - # return res + @api.onchange('job_personnel_ids') + def _onchange_job_personnel_ids(self): + for job in self: + for employee in job.job_personnel_ids: + other_jobs = self.env['hr.job'].search([ + ('job_personnel_ids', 'in', [employee.id]), + ('id', '!=', job.id) + ]) + if other_jobs: + for other_job in other_jobs: + if employee.id in other_job.job_personnel_ids.ids: + other_job.job_personnel_ids = [(3, employee.id)] + if hasattr(employee, 'job_id'): + employee.job_id = job.id @api.depends('employee_ids.job_id', 'employee_ids.active') def _compute_job_personnel_ids(self):