[FIX] hr_holidays: fix accrual level maximum leaves
A test introduced with https://github.com/odoo/odoo/pull/96432 revealed an issue with the level limits for the accrual plans. The only applied limit was the one of the current level at the end of the run, however if for whatever reason multiple levels had to be processed at once (if the database was shut down for a long period of time for example), the individual levels would not apply any limit logic to their behaviour which meant that you could have a different behaviour between running the cron each day and running it after a long period. This commit aims to fix that issue by applying the said limit. OPW-2868297 closes odoo/odoo#97540 X-original-commit: 09fa1020f42d641fc0011d482cdd08aea4f4085a Signed-off-by: William Braeckman (wbr) <wbr@odoo.com> Signed-off-by: Kevin Baptiste <kba@odoo.com>
This commit is contained in:
@@ -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\
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user