From 1e6d6e24ce702f5ff134e7cfe2aeec4f6a6766ff Mon Sep 17 00:00:00 2001 From: zhouzhou <123@qq.com> Date: Thu, 12 Dec 2024 09:44:49 +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 | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/yuthon_hr_employee/models/inherit_hr_job.py b/yuthon_hr_employee/models/inherit_hr_job.py index b2f4bae7c..cb5e46cf5 100644 --- a/yuthon_hr_employee/models/inherit_hr_job.py +++ b/yuthon_hr_employee/models/inherit_hr_job.py @@ -95,13 +95,22 @@ class HrJob(models.Model): if department_id: job.sudo().write({'department_id': department_id.id if len(department_id) == 1 else department_id[0].id}) - @api.onchange('department_id') def onchange_department_id(self): company_mapping = { - '天河投资集团':'thtz' , '天河物管': 'thwg', '天河粮储':'thlc', '集团本部': 'thtjbb' + '天河投资集团': 'thtz', + '天河物管': 'thwg', + '天河粮储': 'thlc', + '集团本部': 'thtjbb' } - yuthon_company = company_mapping.get(self.department_id.parent_id.name) + department = self.department_id + yuthon_company = company_mapping.get(department.name) # 先检查自身 + if not yuthon_company: + while department.parent_id: + department = department.parent_id + yuthon_company = company_mapping.get(department.name) + if yuthon_company: + break self.yuthon_company = yuthon_company class HrJobType(models.Model):