From 90731ad170c503cdfe89a9998fa1d1e2a5035c86 Mon Sep 17 00:00:00 2001 From: Fanny He Date: Mon, 18 Mar 2019 18:45:35 +0000 Subject: [PATCH] [FIX] hr: put accrual leave allocation start in a function When an accrual leave is allocated to an employee, it starts from the employee creation date. However, companies want to create employees before they start working. Therefore, they want to be able to change the accrual leave allocation start to when the employee starts working. For instance, when hr_contract is installed, we can change the accrual leave allocation start to the date when the first contract starts. We create the function _get_date_start_work(), that can be overriden to allow those changes. OPW-1939378 closes odoo/odoo#31930 Signed-off-by: Nans Lefebvre (len) --- addons/hr_holidays/models/hr.py | 3 +++ addons/hr_holidays/models/hr_leave_allocation.py | 9 ++++----- 2 files changed, 7 insertions(+), 5 deletions(-) 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']