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 @@ + +