[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) <bedo@odoo.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -83,6 +83,8 @@
|
||||
<group>
|
||||
<field name="type_request_unit" invisible="1"/>
|
||||
<field name="has_accrual_plan" invisible="1"/>
|
||||
<!-- Save already_accrued when creating record to avoid double allocation when cron runs -->
|
||||
<field name="already_accrued" invisible="1"/>
|
||||
<field name="holiday_status_id"
|
||||
context="{'employee_id':employee_id, 'default_date_from':current_date, 'request_type':'allocation'}"
|
||||
readonly="state == 'validate'"/>
|
||||
|
||||
Reference in New Issue
Block a user