新增一个预计算公式一个引用公式:
预计算公式:
employeeIds = employee_snapshot_dict.keys()
payroll_period_id = payslip_run_record.payroll_period.id
payroll_period_rec = env['payroll.period'].search([('id', '=',payroll_period_id)])
payroll_period_name = payroll_period_rec.name
result = {}
for employeeid in employeeIds:
employee = env['hr.employee'].search([('id','=',employeeid)])
if employee.payroll_archive_ids:
perform_quarterly_list = [[],[]]
perform_semi_annual_list = [[],[]]
for payroll_archive in employee.payroll_archive_ids:
if payroll_archive.code=='perform_quarterly':
perform_quarterly_list[0].append(payroll_archive.amount)
perform_quarterly_list[1].append(payroll_archive.expired_date)
if payroll_archive.code=='perform_semi_annual':
perform_semi_annual_list[0].append(payroll_archive.amount)
perform_semi_annual_list[1].append(payroll_archive.expired_date)
result[employeeid] =
{
'perform_quarterly_list': perform_quarterly_list,
'perform_semi_annual_list': perform_semi_annual_list
}
引用公式:
def F_SeasonHalfyearAdjustConvert(cal_type):
data_dic = global_dict.get('F_season_halfyear_adjust_convert', {})
period_name = global_dict.get('ref_payroll_period_name')
employee_id = individual_dict['ref_employee_id']
data_dic = data_dic.get(employee_id,{})
result_list = [0, 0]
the_month = period_name%100
the_year = period_name//100
if the_month in [3,6,9,12]:
if cal_type=='perform_quarterly':
the_list = data_dic.get('perform_quarterly_list',[[],[]])
month_begin = the_month - 2
elif cal_type=='perform_semi_annual':
the_list = data_dic.get('perform_semi_annual_list',[[],[]])
month_begin = the_month - 5
end_day = 31 if the_month in [3,12] else 30
date_begin = datetime.date(year=the_year,month=month_begin,day=1).strftime('%Y-%m-%d')
date_end = datetime.date(year=the_year,month=the_month,day=end_day).strftime('%Y-%m-%d')
amount_list = the_list[0]
date_list = the_list[1]
count_date_list = []
for index,a_date in enumerate(date_list):
if a_date and index==0:
continue
if a_date and index > 0:
if date_begin <= a_date <= date_end:
count_date_list.append(a_date)
if count_date_list:
count_day = count_date_list[0]
before_days = F_GetDaysof(date_begin, count_day, 2)
af_begin_date = (datetime.datetime.strptime(count_day,'%Y-%m-%d') + relativedelta.relativedelta(days=1)).strftime('%Y-%m-%d')
af_days = F_GetDaysof(af_begin_date, date_end, 2)
count_day_index = date_list.index(count_day)
before_amount = amount_list[count_day_index]
after_amount = 0 if count_day_index==0 else amount_list[count_day_index-1]
total = (float(before_amount)*float(before_days) + float(after_amount)*float(af_days))/(before_days+af_days)
result_list[0] = total
result_list[1] = after_amount - before_amount
return result_list