employee_ids = env['hr.employee'].search(cr, 1, [('departure_time', '!=', None)])
if employee_ids:
for employee_id in employee_ids:
record = env['x_data_stoppay'].search(cr, 1, [('x_employee_id', '=', employee_id)])
if record:
continue
else:
employee_obj = env['hr.employee'].browse(cr, 1, employee_id)
values = {
"x_employee_id": employee_id,
"x_employee_number": employee_obj.employee_number,
"x_name": employee_obj.name,
"x_department_id": employee_obj.department_id.id,
"x_location_id": employee_obj.location_id.id,
"x_job_id": employee_obj.job_id.id,
"x_hiredate": employee_obj.hiredate,
"x_departuredate": employee_obj.departure_time
}
env['x_data_stoppay'].create(cr, 1, values)