From 58e2def45525b11a6b5a710d5fead7ba9bcfceed Mon Sep 17 00:00:00 2001 From: zhou <123@> Date: Tue, 8 Apr 2025 17:20:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yuthon_hr_employee/models/inherit_hr_job.py | 27 +++++++++++---------- 1 file changed, 14 insertions(+), 13 deletions(-) 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):