records = env['hr.employee'].search([])
current_date = datetime.datetime.now().strftime('%Y-%m-%d')
for record in records:
manager_employee_id = False
job_employee = env['hr.employee'].search([('position_id','=',record.position_id.parent_position_id.id)])
if job_employee and len(job_employee) == 1:
manager_employee_id = job_employee.id
parttime_position_emps = env['parttime.position.record'].search([('position_id','=',record.position_id.parent_position_id.id),('start_date','<=',current_date),
'|',('end_date','>=',current_date),('end_date','=',False)])
if parttime_position_emps and len(parttime_position_emps) == 1:
manager_employee_id = parttime_position_emps.id
if len(job_employee) > 1 or len(parttime_position_emps) > 1:
manager_employee_id = False
employee_job1 = env['emp.job'].search([('id','=',record.job_info_id.id)])
if manager_employee_id and record.manager.id != manager_employee_id:
emp = env['hr.employee'].search([('id','=',manager_employee_id)])
log('员工姓名-%s,员工当前汇报上级-%s,员工修改后汇报上级-%s,员工的岗位和上级岗位 %s-%s' % (record.name,record.manager.name,emp.name,record.position_id.name,record.position_id.parent_position_id.name))
employee_job1.update(
{'manager_employee_id':manager_employee_id,
}
)