diff --git a/addons/hr_holidays/models/hr_leave_allocation.py b/addons/hr_holidays/models/hr_leave_allocation.py index 262b6f746e9..39ffced65b9 100644 --- a/addons/hr_holidays/models/hr_leave_allocation.py +++ b/addons/hr_holidays/models/hr_leave_allocation.py @@ -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'] diff --git a/addons/hr_holidays/models/hr_leave_type.py b/addons/hr_holidays/models/hr_leave_type.py index 77461e1bbba..846cd0f6589 100644 --- a/addons/hr_holidays/models/hr_leave_type.py +++ b/addons/hr_holidays/models/hr_leave_type.py @@ -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: