添加功能

This commit is contained in:
李鹏宇
2026-02-04 18:40:09 +08:00
parent 8360237293
commit 58c8b5129f
2 changed files with 47 additions and 54 deletions
@@ -93,11 +93,12 @@ class HrContract(models.Model):
@api.constrains('change_ids') @api.constrains('change_ids')
def _onchange_change_ids(self): def _onchange_change_ids(self):
latest = self.change_ids.sorted('change_end_date', reverse=True)[0] if self.change_ids:
self.department_id = latest.department_id latest = self.change_ids.sorted('change_end_date', reverse=True)[0]
self.job_id = latest.job_id self.department_id = latest.department_id
self.structure_type_id = latest.structure_type_id self.job_id = latest.job_id
self.salary_group_id = latest.salary_group_id self.structure_type_id = latest.structure_type_id
self.salary_group_id = latest.salary_group_id
def update_version(self): def update_version(self):
contract_ids = self.env["hr.contract"].browse( contract_ids = self.env["hr.contract"].browse(
@@ -86,65 +86,57 @@ class YuthonReassignmentApproval(models.Model):
def end_approval(self): def end_approval(self):
current_date = fields.Date.today() current_date = fields.Date.today()
# 筛选已完成审批的记录
# reassignment_approval_ids = self.search([('work_end', '=', True),
# ('is_execution', '=', False),
# ])
for record in self: for record in self:
if record.change_date <= current_date: # if not record.is_execution and record.change_date <= current_date and record.work_end:
employee = record.employee_id employee = record.employee_id
old_contract = employee.contract_id original_contract = employee.contract_id #
update_vals = {} if not original_contract:
continue
emp_update_vals = {}
if record.change_company_id: if record.change_company_id:
update_vals['company_id'] = record.change_company_id.id emp_update_vals['company_id'] = record.change_company_id.id
if record.change_department_id: if record.change_department_id:
update_vals['department_id'] = record.change_department_id.id emp_update_vals['department_id'] = record.change_department_id.id
if record.change_job_id: if record.change_job_id:
update_vals['job_id'] = record.change_job_id.id emp_update_vals['job_id'] = record.change_job_id.id
if record.change_parent_id: if record.change_parent_id:
update_vals['parent_id'] = record.change_parent_id.id emp_update_vals['parent_id'] = record.change_parent_id.id
if update_vals: if emp_update_vals:
employee.write(update_vals) employee.write(emp_update_vals)
if old_contract: if original_contract.version:
version_str = self.version.lstrip('V') version_str = original_contract.version.lstrip('V')
main_version = version_str.split('.')[0] main_version = version_str.split('.')[0] if '.' in version_str else version_str
new_main_version = int(main_version) + 1 try:
new_version = f"V{new_main_version}.0" new_main_version = int(main_version) + 1
new_contract_vals = { except ValueError:
'employee_id': old_contract.employee_id.id, new_main_version = 2
'name': old_contract.name, original_contract.write({
'state': 'open', 'version': f"V{new_main_version}.0"
'party_id': old_contract.party_id.id,
'company_id': record.change_company_id.id,
'is_annual_salary': old_contract.is_annual_salary,
'date_start': record.change_date,
'date_end': False,
'resource_calendar_id': old_contract.resource_calendar_id.id,
# 'structure_type_id': old_contract.structure_type_id.id,
'department_id': old_contract.department_id.id,
'job_id': old_contract.job_id.id,
'termination_date': old_contract.termination_date,
'salary_group_id': old_contract.salary_group_id.id,
'contract_type_id': old_contract.contract_type_id.id,
'version': new_version,
'wage': old_contract.wage,
}
if record.change_job_id:
new_contract_vals['job_id'] = record.change_job_id.id
if record.change_structure_id:
new_contract_vals[ 'structure_type_id'] = record.change_structure_id.type_id.id
if record.change_department_id:
new_contract_vals['department_id'] = record.change_department_id.id
old_contract.write({
'state': 'cancel',
'date_end': record.change_date - timedelta(days=1),
}) })
new_contract = self.env['hr.contract'].create(new_contract_vals)
employee.contract_id = new_contract.id existing_line = self.env['hr.contract.change.line'].search([
('contract_id', '=', original_contract.id),
('change_start_date', '=', record.change_date),
('job_id', '=', record.change_job_id.id or original_contract.job_id.id)
], limit=1)
if not existing_line:
line_vals = {
'contract_id': original_contract.id,
'department_id': record.change_department_id.id or original_contract.department_id.id,
'job_id': record.change_job_id.id or original_contract.job_id.id,
'structure_type_id': record.change_structure_id.type_id.id if record.change_structure_id else original_contract.structure_type_id.id,
'salary_group_id': original_contract.salary_group_id.id if original_contract.salary_group_id else False,
'change_start_date': record.change_date,
'change_end_date': False,
}
self.env['hr.contract.change.line'].create(line_vals)
original_contract._onchange_change_ids()
record.is_execution = True record.is_execution = True
class HrJobType(models.Model): class HrJobType(models.Model):
_name = "hr.job.type" _name = "hr.job.type"