employee = env['hr.employee'].search([('id','=',employee_id), ('active','=', True), ('is_probation','=', False)])
hire_date = employee.hire_date
year_now = datetime.datetime.today().year
today = datetime.datetime.today()
date_str = '%s-03-01' %year_now
date_flag = datetime.datetime.strptime(date_str, '%Y-%m-%d')
if today < date_flag:
year_now -= 1
date_str = '%s-03-01' %year_now
date_flag = datetime.datetime.strptime(date_str, '%Y-%m-%d')
diff = relativedelta.relativedelta(date_flag, hire_date)
leave_res = 0
if diff.years<1:
leave_res=0
if 1<= diff.years <= 2:
leave_res = 10
elif 2< diff.years <= 5:
leave_res = 13
if 5 < diff.years <= 7:
leave_res = 15
if 7 < diff.years <= 10:
leave_res = 17
if diff.years >= 11:
leave_res = 20
period = env['hr.holiday.period'].search([('id','=',period_id)])
period_year = period.name
def last_day_of_month(any_day):
next_month = any_day.replace(day=28) + datetime.timedelta(days=4)
return next_month - datetime.timedelta(days=next_month.day)
def first_day_of_month(month_str):
date_str = "%s-%s-01" % (period_year,month_str)
return (datetime.datetime.strptime(date_str, "%Y-%m-%d")).date()
frequency = rule.get('frequency')
if frequency == 'month':
result = [
{'result': 0, 'start_date': first_day_of_month("01"), 'end_date': last_day_of_month(first_day_of_month("12"))},
{'result': 0, 'start_date': first_day_of_month("02"), 'end_date': last_day_of_month(first_day_of_month("12"))},
{'result': leave_res*8, 'start_date': first_day_of_month("03"), 'end_date': last_day_of_month(first_day_of_month("12"))},
{'result': 0, 'start_date': first_day_of_month("04"), 'end_date': last_day_of_month(first_day_of_month("12"))},
{'result': 0, 'start_date': first_day_of_month("05"), 'end_date': last_day_of_month(first_day_of_month("12"))},
{'result': 0, 'start_date': first_day_of_month("06"), 'end_date': last_day_of_month(first_day_of_month("12"))},
{'result': 0, 'start_date': first_day_of_month("07"), 'end_date': last_day_of_month(first_day_of_month("12"))},
{'result': 0, 'start_date': first_day_of_month("08"), 'end_date': last_day_of_month(first_day_of_month("12"))},
{'result': 0, 'start_date': first_day_of_month("09"), 'end_date': last_day_of_month(first_day_of_month("12"))},
{'result': 0, 'start_date': first_day_of_month("10"), 'end_date': last_day_of_month(first_day_of_month("12"))},
{'result': 0, 'start_date': first_day_of_month("11"), 'end_date': last_day_of_month(first_day_of_month("12"))},
{'result': 0, 'start_date': first_day_of_month("12"), 'end_date': last_day_of_month(first_day_of_month("12"))}
]
else:
result = []