payslip_run_record_type = payslip_run_record.type
unscheduled_type = ''
unscheduled_info = {}
if payslip_run_record_type == 'unscheduled':
unscheduled_type = payslip_run_record.unscheduled_type
for item in payslip_run_record.unscheduled_employee_ids:
unscheduled_info[item.employee_id.id] =
{
'date_start': item.start_date,
'date_end': item.end_date,
}
is_last_hire_employee_info = False
if unscheduled_type == 'rehired':
is_last_hire_employee_info = True
payslip_start_date =payslip_run_record.payroll_period.date_start
payslip_end_date =payslip_run_record.payroll_period.date_end
if payslip_start_date[5:7] in ('01','02','03'):
begin_date=str(payslip_start_date[0:5])+'01-01'
end_date=str(payslip_start_date[0:5])+'03-31'
elif payslip_start_date[5:7] in ('04','05','06'):
begin_date=str(payslip_start_date[0:5])+'04-01'
end_date=str(payslip_start_date[0:5])+'06-30'
elif payslip_start_date[5:7] in ('07','08','09'):
begin_date=str(payslip_start_date[0:5])+'07-01'
end_date=str(payslip_start_date[0:5])+'09-30'
elif payslip_start_date[5:7] in ('10','11','12'):
begin_date=str(payslip_start_date[0:5])+'10-01'
end_date=str(payslip_start_date[0:5])+'12-31'
hr_payslip_parameters = preFuncParameterDict.get('F_ArchiveValueCal_Qua', [])
value_dict = {}
- 从薪资参数中获取薪资档案实际值折算计算公式的参数
- code:薪资档案编码
if hr_payslip_parameters:
for hr_payslip_parameter in hr_payslip_parameters:
parameters = eval(hr_payslip_parameter['func_args'])
for parameter in parameters:
if isinstance(parameter, tuple):
value_dict.setdefault(tuple([eval(i) for i in parameter]), None)
else:
value_dict.setdefault((eval(parameter),), None)
result = {}
for args in value_dict.keys():
code = args[0]
if len(args) == 3:
qua_type=args[2]
else:
qua_type=1
employee_records = payslip_run_record.employee_ids
date_dict = {}
all_base_currency_amount_map = env['payroll.archive']._get_all_base_currency_amount(employee_ids=employee_records.ids, is_last_hire_employee_info=is_last_hire_employee_info)
all_employee_payroll_archive_records = env['payroll.archive'].get_employee_archives(employee_records.ids, is_last_hire_employee_info=is_last_hire_employee_info,order=['effective_date'])
for employee_record in employee_records:
employee_id = employee_record.id
- if payslip_run_record_type == 'unscheduled':
- payslip_start_date = unscheduled_info.get(employee_id, {}).get('date_start')
- payslip_end_date = unscheduled_info.get(employee_id, {}).get('date_end')
if employee_id not in employee_snapshot_dict:
raise Exception('Lack of Employee Snapshot Data: %s' % employee_record.name)
- payroll_archive_records = employee_record.payroll_archive_ids
payroll_archive_records = all_employee_payroll_archive_records.get(employee_id, {}) or {}
employee_name = payroll_archive_records.pop('employee_name', '')
result_list = []
if payroll_archive_records:
for payroll_archive_code, payroll_archive_record_ls in payroll_archive_records.items():
length = len(payroll_archive_record_ls)
for payroll_archive_record in payroll_archive_record_ls:
effective_date = payroll_archive_record['effective_date']
expired_date = payroll_archive_record['expired_date']
- 如果失效日期不存在,令其等于9999-12-31
if not expired_date:
expired_date = '9999-12-31'
- 判断薪资档案与薪资周期是否有交集
if payroll_archive_record['code'] == code and \
end_date >= effective_date and expired_date >= begin_date:
date_list = [begin_date, end_date, expired_date, effective_date]
date_list.sort()
start_day = date_list[1]
end_day = date_list[2]
amount = all_base_currency_amount_map.get(payroll_archive_record['id']) or payroll_archive_record['amount']
result_list.append(
{'start_day': start_day, 'end_day': end_day, 'amount': amount}
)
result_list = sorted(result_list,key=lambda x:x['start_day'])
if result_list:
if qua_type == 1:
if result_list[0]['start_day'] > begin_date:
result_list[0]['start_day'] = begin_date
if result_list[-1]['end_day'] < end_date:
result_list[-1]['end_day'] = end_date
date_dict.update(
{employee_snapshot_dict[employee_id].employee_id.id: result_list}
)
result.update(
{args: date_dict}
)