From 27f5ac1d7dce8b862cac84f991c619b0d9d18bda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=AE=87?= <9664676+pengyuthon@user.noreply.gitee.com> Date: Tue, 30 Jun 2026 11:48:23 +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_contract/models/inherit_hr_contract.py | 36 +++++++++++++++---- .../views/inherit_hr_contract_views.xml | 1 + yuthon_issue/views/issue_library_views.xml | 2 +- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/yuthon_contract/models/inherit_hr_contract.py b/yuthon_contract/models/inherit_hr_contract.py index 43b8ef15d..d107bfa85 100644 --- a/yuthon_contract/models/inherit_hr_contract.py +++ b/yuthon_contract/models/inherit_hr_contract.py @@ -124,12 +124,36 @@ class HrContract(models.Model): @api.constrains('change_ids') def _onchange_change_ids(self): - if self.change_ids: - latest = self.change_ids.sorted('change_end_date', reverse=True)[0] - self.department_id = latest.department_id - self.job_id = latest.job_id - self.structure_type_id = latest.structure_type_id - self.salary_group_id = latest.salary_group_id + today = fields.Date.today() + for contract in self: + active_line = False + for line in contract.change_ids.sorted('change_start_date', reverse=True): + # change_end_date 为空视为无限大 + if line.change_start_date <= today and (not line.change_end_date or line.change_end_date >= today): + active_line = line + break + if active_line: + contract.department_id = active_line.department_id + contract.job_id = active_line.job_id + contract.structure_type_id = active_line.structure_type_id + contract.salary_group_id = active_line.salary_group_id + + def init_change_lines(self): + """为选中的合同补初始异动行""" + contract_ids = self.env["hr.contract"].browse( + self._context.get("active_ids", self._context.get("active_id")) + ) + for contract in contract_ids: + if not contract.change_ids: + self.env['hr.contract.change.line'].create({ + 'contract_id': contract.id, + 'department_id': contract.department_id.id, + 'job_id': contract.job_id.id, + 'structure_type_id': contract.structure_type_id.id, + 'salary_group_id': contract.salary_group_id.id, + 'change_start_date': contract.date_start, + 'change_end_date': contract.date_end, + }) def update_version(self): contract_ids = self.env["hr.contract"].browse( diff --git a/yuthon_contract/views/inherit_hr_contract_views.xml b/yuthon_contract/views/inherit_hr_contract_views.xml index ea4a83aaa..e4094d7db 100644 --- a/yuthon_contract/views/inherit_hr_contract_views.xml +++ b/yuthon_contract/views/inherit_hr_contract_views.xml @@ -10,6 +10,7 @@