From 0f2e567ff33676d57667ced4983bb98ad1a3b08c Mon Sep 17 00:00:00 2001 From: Kevin Baptiste Date: Tue, 28 Feb 2023 14:12:12 +0000 Subject: [PATCH] [FIX] hr_holidays: show sum of closest allocations In the time off dashboard, only the number of available days of the first closest allocation to expire was shown, which is not correct. If you have many allocations expiring on the same day, their sum should be shown. task-3203519 closes odoo/odoo#114010 X-original-commit: ff35654ae8c44014aab99ec07493f035e9a2d80d Signed-off-by: Kevin Baptiste --- addons/hr_holidays/models/hr_leave_type.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/addons/hr_holidays/models/hr_leave_type.py b/addons/hr_holidays/models/hr_leave_type.py index 437df216546..32b31f335fa 100644 --- a/addons/hr_holidays/models/hr_leave_type.py +++ b/addons/hr_holidays/models/hr_leave_type.py @@ -432,7 +432,15 @@ class HolidaysType(models.Model): def _get_days_request(self): self.ensure_one() result = self._get_employees_days_per_allocation(self.closest_allocation_to_expire.employee_id.ids) - closest_allocation_remaining = result[self.closest_allocation_to_expire.employee_id.id][self][self.closest_allocation_to_expire]['virtual_remaining_leaves'] + closest_allocation_remaining = 0 + if self.closest_allocation_to_expire: + # Shows the sum of allocation expiring on the same day as the closest to expire + employee_allocations = result[self.closest_allocation_to_expire.employee_id.id][self].items() + closest_allocation_remaining = sum( + res['virtual_remaining_leaves'] + for alloc, res in employee_allocations + if alloc and alloc.date_to == self.closest_allocation_to_expire.date_to + ) return (self.name, { 'remaining_leaves': ('%.2f' % self.remaining_leaves).rstrip('0').rstrip('.'), 'virtual_remaining_leaves': ('%.2f' % self.virtual_remaining_leaves).rstrip('0').rstrip('.'),