diff --git a/addons/hr_holidays/models/hr.py b/addons/hr_holidays/models/hr.py index f2f94ef552c..6f024b5e325 100644 --- a/addons/hr_holidays/models/hr.py +++ b/addons/hr_holidays/models/hr.py @@ -83,6 +83,9 @@ class Employee(models.Model): show_leaves = fields.Boolean('Able to see Remaining Leaves', compute='_compute_show_leaves') is_absent_totay = fields.Boolean('Absent Today', compute='_compute_absent_employee', search='_search_absent_employee') + def _get_date_start_work(self): + return self.create_date + def _get_remaining_leaves(self): """ Helper to compute the remaining leaves for the current employees :returns dict where the key is the employee id, and the value is the remain leaves diff --git a/addons/hr_holidays/models/hr_leave_allocation.py b/addons/hr_holidays/models/hr_leave_allocation.py index c887ab0ee43..b92ca28f856 100644 --- a/addons/hr_holidays/models/hr_leave_allocation.py +++ b/addons/hr_holidays/models/hr_leave_allocation.py @@ -166,16 +166,15 @@ class HolidaysAllocation(models.Model): # We have to check when the employee has been created # in order to not allocate him/her too much leaves - creation_date = fields.Datetime.from_string(holiday.employee_id.create_date) - + start_date = holiday.employee_id._get_date_start_work() # If employee is created after the period, we cancel the computation - if period_end <= creation_date: + if period_end <= start_date: holiday.write(values) continue # If employee created during the period, taking the date at which he has been created - if period_start <= creation_date: - period_start = creation_date + if period_start <= start_date: + period_start = start_date worked = holiday.employee_id.get_work_days_data(period_start, period_end, domain=[('holiday_id.holiday_status_id.unpaid', '=', True), ('time_type', '=', 'leave')])['days'] left = holiday.employee_id.get_leave_days_data(period_start, period_end, domain=[('holiday_id.holiday_status_id.unpaid', '=', True), ('time_type', '=', 'leave')])['days']