代码如下:
holiday_type_id_ann = env['hr.holiday.type'].search([('code', '=', 'L004')]).id
holiday_type_id_com = env['hr.holiday.type'].search([('code', '=', 'L005')]).id
leg_holiday_records = env['hr.holiday.inquiry'].search([('employee_id', '=', employee.id),('holiday_period_id','=',previous_period.id), ('holiday_type_id','=',holiday_type_id_ann)])
comp_holiday_records = env['hr.holiday.inquiry'].search([('employee_id', '=', employee.id),('holiday_period_id','=',previous_period.id), ('holiday_type_id','=',holiday_type_id_com)])
leg_num=0
for leg_rec in leg_holiday_records:
leg_num += leg_rec.invalid_num
com_num = 0
for com_rec in comp_holiday_records:
com_num += com_rec.invalid_num
if leg_num >= 5:
max_leg_num = 5
else:
max_leg_num = leg_num
max_com_num = 5 - max_leg_num
result=[
{
'employee_id': employee.id,
'holiday_type_id': env.ref('hr_holiday_management.legal_annual_leave_type').id,
'max_num': max_leg_num,
'product_uom_id': env.ref('hr_holiday_management.legal_annual_allot_rule_default').product_uom_id.id,
}
,
{
'employee_id': employee.id,
'holiday_type_id': holiday_type_id_com,
'max_num': max_com_num,
'product_uom_id': env.ref('hr_holiday_management.legal_annual_allot_rule_default').product_uom_id.id,
}
]