[IMP] hr_holidays: ignore future leaves in accrual computation
Current behavior: An accrual uses all planned leaves to calculate how many days it can give, even if the leaves are planned in the future and could be cancelled. Desired behavior: An accrual should only take into account leaves that have already been taken or already started, and ignore future leaves. After this commit: New context key 'ignore_future' for method _get_employees_days_per_allocation decides if future leaves should be taken into account or not. Some use cases need to take into account future leaves, others don't. task 3207843 closes odoo/odoo#120456 X-original-commit: d917a406fc7933af852ad5338533b93fc3fd2218 Related: odoo/enterprise#40678 Signed-off-by: Kevin Baptiste <kba@odoo.com>
This commit is contained in:
@@ -199,7 +199,7 @@ class HolidaysAllocation(models.Model):
|
||||
|
||||
@api.depends('employee_id', 'holiday_status_id', 'taken_leave_ids.number_of_days', 'taken_leave_ids.state')
|
||||
def _compute_leaves(self):
|
||||
employee_days_per_allocation = self.holiday_status_id._get_employees_days_per_allocation(self.employee_id.ids)
|
||||
employee_days_per_allocation = self.holiday_status_id.with_context(ignore_future=True)._get_employees_days_per_allocation(self.employee_id.ids)
|
||||
for allocation in self:
|
||||
allocation.max_leaves = allocation.number_of_hours_display if allocation.type_request_unit == 'hour' else allocation.number_of_days
|
||||
allocation.leaves_taken = employee_days_per_allocation[allocation.employee_id.id][allocation.holiday_status_id][allocation]['leaves_taken']
|
||||
|
||||
@@ -208,11 +208,17 @@ class HolidaysType(models.Model):
|
||||
return [('id', 'in', valid_leave_types.ids)]
|
||||
|
||||
def _get_employees_days_per_allocation(self, employee_ids, date=None):
|
||||
leaves = self.env['hr.leave'].search([
|
||||
if not date:
|
||||
date = fields.Date.to_date(self.env.context.get('default_date_from')) or fields.Date.context_today(self)
|
||||
|
||||
leaves_domain = [
|
||||
('employee_id', 'in', employee_ids),
|
||||
('state', 'in', ['confirm', 'validate1', 'validate']),
|
||||
('holiday_status_id', 'in', self.ids)
|
||||
])
|
||||
]
|
||||
if self.env.context.get("ignore_future"):
|
||||
leaves_domain.append(('date_from', '<=', date))
|
||||
leaves = self.env['hr.leave'].search(leaves_domain)
|
||||
|
||||
allocations = self.env['hr.leave.allocation'].with_context(active_test=False).search([
|
||||
('employee_id', 'in', employee_ids),
|
||||
@@ -220,9 +226,6 @@ class HolidaysType(models.Model):
|
||||
('holiday_status_id', 'in', self.ids),
|
||||
])
|
||||
|
||||
if not date:
|
||||
date = fields.Date.to_date(self.env.context.get('default_date_from')) or fields.Date.context_today(self)
|
||||
|
||||
# The allocation_employees dictionary groups the allocations based on the employee and the holiday type
|
||||
# The structure is the following:
|
||||
# - KEYS:
|
||||
|
||||
Reference in New Issue
Block a user