[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) <len@odoo.com>
This commit is contained in:
Fanny He
2019-03-18 18:45:35 +00:00
parent 88348f8ff9
commit 90731ad170
2 changed files with 7 additions and 5 deletions
+3
View File
@@ -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
@@ -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']