diff --git a/addons/hr_holidays/models/hr_leave_allocation.py b/addons/hr_holidays/models/hr_leave_allocation.py index 9467d68584f..623e9e18915 100644 --- a/addons/hr_holidays/models/hr_leave_allocation.py +++ b/addons/hr_holidays/models/hr_leave_allocation.py @@ -442,6 +442,8 @@ class HolidaysAllocation(models.Model): gained_days = allocation._process_accrual_plan_level( current_level, period_start, allocation.lastcall, period_end, allocation.nextcall) days_added_per_level[current_level] += gained_days + if current_level.maximum_leave > 0 and sum(days_added_per_level.values()) > current_level.maximum_leave: + days_added_per_level[current_level] -= sum(days_added_per_level.values()) - current_level.maximum_leave # We have to check for end of year actions if it is within our period # since we can create retroactive allocations. if allocation.lastcall.year < allocation.nextcall.year and\ diff --git a/addons/hr_holidays/tests/test_accrual_allocations.py b/addons/hr_holidays/tests/test_accrual_allocations.py index 799270bf5ba..03caaf855c2 100644 --- a/addons/hr_holidays/tests/test_accrual_allocations.py +++ b/addons/hr_holidays/tests/test_accrual_allocations.py @@ -686,7 +686,11 @@ class TestAccrualAllocations(TestHrHolidaysCommon): allocation.action_validate() with freeze_time('2022-7-20'): allocation._update_accrual() - self.assertEqual(allocation.number_of_days, 10) + # The first level gives 3 days + # The second level could give 6 days but since the first level was already giving + # 3 days, the second level gives 3 days to reach the second level's limit. + # The third level gives 1 day since it only counts for one iteration. + self.assertEqual(allocation.number_of_days, 7) def test_accrual_lost_previous_days(self): # Test that when an allocation with two levels is made and that the first level has it's action