From 5d0c50da3f5694e24c2717b18200a1c1ae486452 Mon Sep 17 00:00:00 2001 From: "Simon Goffaux (sigo)" Date: Thu, 11 Apr 2024 15:23:10 +0200 Subject: [PATCH] [FIX] hr_holidays: save already_accrued from allocation form views Currently, when we have an accrual plan where the accrued time is allocated at the start of the accrual period and we set the allocation start time in the past, the plan will be processed but already_accrued will not be saved. Example: - We have an accrual plan that allocates 1 day per month at the start of the accrual period. Milestone reached 0 days after allocation start. - We set the start date of the allocation to 2024-01-01, the current date is 2024-03-15. The number of days are calculated to 3.00 (jan, feb, mar). - We save the record, already_accrued is not saved (defaults to false) - When the scheduled action runs (2024-04-01), it will allocate 2 days instead of 1 This commit fixes this behavior by adding the already_accrued field to the form view so that it is saved when the record is created. opw-3851320 closes odoo/odoo#161508 Signed-off-by: Bertrand Dossogne (bedo) --- .../tests/test_accrual_allocations.py | 34 ++++++++++++++++++- .../views/hr_leave_allocation_views.xml | 2 ++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/addons/hr_holidays/tests/test_accrual_allocations.py b/addons/hr_holidays/tests/test_accrual_allocations.py index 6b89c5c4856..47fe1472466 100644 --- a/addons/hr_holidays/tests/test_accrual_allocations.py +++ b/addons/hr_holidays/tests/test_accrual_allocations.py @@ -6,7 +6,7 @@ from dateutil.relativedelta import relativedelta from odoo import Command from odoo.exceptions import UserError -from odoo.tests import tagged +from odoo.tests import tagged, Form from odoo.addons.hr_holidays.tests.common import TestHrHolidaysCommon @@ -1645,3 +1645,35 @@ class TestAccrualAllocations(TestHrHolidaysCommon): accrual_allocation.write({'date_to': '2022-12-31'}) accrual_allocation._onchange_date_from() self.assertAlmostEqual(accrual_allocation.number_of_days, 12, places=0) + + def test_accrual_period_start_past_start_date(self): + accrual_plan = self.env['hr.leave.accrual.plan'].with_context(tracking_disable=True).create({ + 'name': 'Monthly accrual', + 'carryover_date': 'year_start', + 'accrued_gain_time': 'start', + 'level_ids': [(0, 0, { + 'added_value_type': 'day', + 'start_count': 0, + 'start_type': 'day', + 'added_value': 1, + 'frequency': 'monthly', + 'first_day_display': '1', + 'cap_accrued_time': False, + })], + }) + with freeze_time('2024-03-01'): + with Form(self.env['hr.leave.allocation']) as f: + f.allocation_type = "accrual" + f.accrual_plan_id = accrual_plan + f.employee_ids.add(self.employee_emp) + f.holiday_status_id = self.leave_type + f.date_from = '2024-01-01' + f.name = "Employee Allocation" + + accrual_allocation = f.record + accrual_allocation.action_validate() + self.assertAlmostEqual(accrual_allocation.number_of_days, 3.0, places=0) + + with freeze_time('2024-04-01'): + accrual_allocation._update_accrual() + self.assertAlmostEqual(accrual_allocation.number_of_days, 4.0, places=0) diff --git a/addons/hr_holidays/views/hr_leave_allocation_views.xml b/addons/hr_holidays/views/hr_leave_allocation_views.xml index ad67ba8c7ee..5cdbd9aaf99 100644 --- a/addons/hr_holidays/views/hr_leave_allocation_views.xml +++ b/addons/hr_holidays/views/hr_leave_allocation_views.xml @@ -83,6 +83,8 @@ + +