def is_month_end(the_date):
is_end = the_date.month != (the_date+datetime.timedelta(days=1)).month
return is_end
def is_month_begin(the_date):
is_begin = the_date.day == 1
return is_begin
def zhesuan_month(period_start_date, period_end_date, employee_hire_date, leave_date, the_num):
small_date = employee_hire_date if employee_hire_date>period_start_date and employee_hire_date<period_end_date else period_start_date
if leave_date:
big_date = leave_date if leave_date>period_start_date and leave_date<period_end_date else period_end_date
else:
big_date = period_end_date
if (period_end_date+relativedelta.relativedelta(days=1)).year!=period_start_date.year:
total_months = 12+(period_end_date+relativedelta.relativedelta(days=1)).month-period_start_date.month
else:
total_months = (period_end_date + relativedelta.relativedelta(days=1)).month - period_start_date.month
if (big_date+relativedelta.relativedelta(days=1)).year!=small_date.year:
sub_month = 12+(big_date+relativedelta.relativedelta(days=1)).month-small_date.month
else:
sub_month = (big_date + relativedelta.relativedelta(days=1)).month - small_date.month
return the_num*sub_month/total_months
employee_info = self.data['employees_info'][employee_id]
period_info = self.data['periods_info'][period_id]
package_info = self.data['packages_info'][package_rule_info['holiday_package_id']]
rule_obj = env['hr.holiday.rule.function']
precision_round = rule_obj.precision_round
period = env['hr.holiday.period'].search([('id','=',period_id)])
init_num = rule['init_num']
precision = rule['graininess'] if rule['graininess'] != "0" else "0.01" # 颗粒度
round_rule = rule['carry_rule'] # 进位规则
employee_hire_date = employee_info['employee_hire_date']
is_entry_convert_enable = rule['is_entry_convert_enable'] # 启用入职折算
is_resignation_convert_enable = rule['is_resignation_convert_enable'] # 启用离职折算
period_start_date = period_info['start_date']
period_end_date = period_info['end_date']
if is_month_begin(employee_hire_date):
employee_hire_date = employee_hire_date
else:
employee_hire_date = employee_hire_date+relativedelta.relativedelta(months=1)
employee_hire_date = employee_hire_date+relativedelta.relativedelta(days=-employee_hire_date.day+1)
if leave_date:
if is_month_end(leave_date):
leave_date=leave_date
else:
leave_date=leave_date+relativedelta.relativedelta(days=-leave_date.day+1)
the_num = zhesuan_month(period_start_date, period_end_date, employee_hire_date, leave_date, init_num)
result = precision_round(the_num, precision, round_rule)