diff --git a/yuthon_contract/models/inherit_hr_contract.py b/yuthon_contract/models/inherit_hr_contract.py index a38ba5082..c842310f1 100644 --- a/yuthon_contract/models/inherit_hr_contract.py +++ b/yuthon_contract/models/inherit_hr_contract.py @@ -57,38 +57,58 @@ class HrContract(models.Model): update_state = True if 'date_end' in vals: update_state = True + if 'termination_date' in vals: + update_state = True if update_state: for contract in self: + # 获取最新的开始日期 start_date = fields.Date.to_date(vals.get('date_start', contract.date_start)) - # 获取新的结束日期(如果有更新),空值视为无限大 + + # 获取最新的结束日期(空值视为无限大) end_date = vals.get('date_end', contract.date_end) end_date = fields.Date.to_date(end_date) if end_date else None - if start_date > today: + + # 获取最新的中止时间(空值视为未中止) + termination_date = vals.get('termination_date', contract.termination_date) + termination_date = fields.Date.to_date(termination_date) if termination_date else None + + # 判断合同状态 + if termination_date and termination_date < today: # 新增:优先判断是否已中止 + new_state = 'cancel' + elif start_date > today: new_state = 'draft' elif end_date and end_date < today: new_state = 'close' else: new_state = 'open' + # 更新当前合同的状态 if 'state' not in vals: vals['state'] = new_state + return super(HrContract, self).write(vals) @api.model def create(self, vals): """在创建时自动更新合同状态""" today = fields.Date.today() - # 获取开始日期和结束日期 + start_date = fields.Date.to_date(vals.get('date_start')) end_date = vals.get('date_end') end_date = fields.Date.to_date(end_date) if end_date else None + termination_date = vals.get('termination_date') + termination_date = fields.Date.to_date(termination_date) if termination_date else None + # 根据日期判断状态 - if start_date > today: + if termination_date and termination_date < today: + vals['state'] = 'cancel' + elif start_date > today: vals['state'] = 'draft' elif end_date and end_date < today: vals['state'] = 'close' else: vals['state'] = 'open' + return super(HrContract, self).create(vals) def update_contract_states(self): diff --git a/yuthon_contract/views/inherit_hr_contract_views.xml b/yuthon_contract/views/inherit_hr_contract_views.xml index 92d5a0b42..689048128 100644 --- a/yuthon_contract/views/inherit_hr_contract_views.xml +++ b/yuthon_contract/views/inherit_hr_contract_views.xml @@ -16,7 +16,8 @@ - 结束日期 + 结束日期 + 0 1 diff --git a/yuthon_salary/models/yuthon_payroll_project.py b/yuthon_salary/models/yuthon_payroll_project.py index 62d3f29b1..c4117b48f 100644 --- a/yuthon_salary/models/yuthon_payroll_project.py +++ b/yuthon_salary/models/yuthon_payroll_project.py @@ -77,7 +77,7 @@ class YuthonPayrollCommon(models.Model): formula_salary = "result = round(((employee.all_overtime_hours - 40) * (payslip.base_salary /21.75 / 8) * 1.5), 0) if employee.all_overtime_hours > 40 else 0" if ins.name == '安全生产管理补贴': formula_salary = "result = employee.security_amount " - if ins.name == '工龄补贴': + if ins.name == '工龄补贴' and ins.company_id.name == '天河物管': formula_salary = "result = min(400, max(0, ((employee.entry_date - employee.open_start_time).days // 30.4375 - employee.interrupt_work_month) // 12) * 10 + employee.salary_year * 20) if employee.department_id.name != '领导班子' else 0" if ins.name == '岗位绩效': formula_salary = "result = 0"