location_mapping = {
'101': '北京',
'201': '西安',
'301': '江苏',
'501': '桂林',
'601': '新疆',
}
# 配置这个前需要先在报表中心查询各个薪资方案的id,参考下面的sql
# select * from hr_payroll_solution_view where status='published' and deleted_at is null
solution_mapping = {
'北京': 6,
'西安': 10,
'江苏': 9,
'桂林': 11,
'新疆': 3
}
# 查询员工
employees = env['hr.employee'].search([('active', '=', True)])
for employee in employees:
payroll_solution = env['hr.payroll.solution'].search([('employee_id', '=', employee.id)])
# 如果已有薪资方案,则跳过
if payroll_solution:
continue
if not employee.job_info_id or employee.job_info_id.status == 'inactive' or not employee.job_info_id.legal_entity_id:
continue
area_code = employee.job_info_id.legal_entity_id.x_area_code or ''
if not area_code:
continue
solution_id = solution_mapping.get(location_mapping.get(area_code, False), False)
if solution_id:
env['solution_id'].create({
'solution_id': solution_id,
'start_date': employee.hire_date
})