[FIX] hr_holidays: past date_to preventing number_of_days compute
Steps:
- Create an accrual plan to give 1 day per month
- Create an allocation with this plan
- Update date_from and/or accrual_plan_id
- number_of_days is updated
- Set date_to in the past (1)
- Update date_from and/or accrual_plan_id (1)
- Set date_to in the future (1)
- Update date_from and/or accrual plan
- number_of_days is updated
Actual results:
- (1) number_of_days is not updated
Expected results:
- number_of_days updated on date_from/accrual_plan_id/date_to change
opw-3764865
closes odoo/odoo#157030
Signed-off-by: Bertrand Dossogne (bedo) <bedo@odoo.com>
This commit is contained in:
@@ -806,16 +806,16 @@ class HolidaysAllocation(models.Model):
|
||||
# before every run, as if it was run from date_from, after an optional change in the allocation value
|
||||
# the user can simply confirm and validate the allocation. The record is in correct state for the next
|
||||
# call of the cron job.
|
||||
@api.onchange('date_from', 'accrual_plan_id')
|
||||
@api.onchange('date_from', 'accrual_plan_id', 'date_to')
|
||||
def _onchange_date_from(self):
|
||||
now = date.today()
|
||||
if self.allocation_type != 'accrual' or self.state == 'validate' or not self.accrual_plan_id\
|
||||
or not self.employee_id or not (not self.date_to or self.date_to > now):
|
||||
or not self.employee_id:
|
||||
return
|
||||
self.lastcall = self.date_from
|
||||
self.nextcall = False
|
||||
self.number_of_days_display = 0.0
|
||||
self._process_accrual_plans()
|
||||
date_to = min(self.date_to, date.today()) if self.date_to else False
|
||||
self._process_accrual_plans(date_to)
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Activity methods
|
||||
|
||||
@@ -1542,3 +1542,82 @@ class TestAccrualAllocations(TestHrHolidaysCommon):
|
||||
accrual_allocation._update_accrual()
|
||||
self.assertEqual(accrual_allocation.number_of_days, 31.0,
|
||||
"the amount shouldn't have changed after running the cron")
|
||||
|
||||
def test_accrual_creation_for_history(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': 'end',
|
||||
'level_ids': [(0, 0, {
|
||||
'added_value_type': 'day',
|
||||
'start_count': 0,
|
||||
'start_type': 'day',
|
||||
'added_value': 1,
|
||||
'frequency': 'monthly',
|
||||
'first_day_display': 'last',
|
||||
'cap_accrued_time': False,
|
||||
'action_with_unused_accruals': 'lost',
|
||||
})],
|
||||
})
|
||||
with freeze_time('2024-03-02'):
|
||||
accrual_allocation = self.env['hr.leave.allocation'].new({
|
||||
'name': 'History allocation',
|
||||
'holiday_status_id': self.leave_type.id,
|
||||
'date_from': '2024-03-01',
|
||||
'employee_id': self.employee_emp.id,
|
||||
'allocation_type': 'accrual',
|
||||
'accrual_plan_id': accrual_plan.id,
|
||||
})
|
||||
# As the duration is set to an onchange, we need to force that onchange to run
|
||||
accrual_allocation._onchange_date_from()
|
||||
self.assertAlmostEqual(accrual_allocation.number_of_days, 0, places=0)
|
||||
|
||||
# Yearly Report lost
|
||||
accrual_allocation.write({'date_from': '2022-01-01'})
|
||||
accrual_allocation._onchange_date_from()
|
||||
self.assertAlmostEqual(accrual_allocation.number_of_days, 2, places=0)
|
||||
|
||||
# Update date_to
|
||||
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_with_report_creation_for_history(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': 'end',
|
||||
'level_ids': [(0, 0, {
|
||||
'added_value_type': 'day',
|
||||
'start_count': 0,
|
||||
'start_type': 'day',
|
||||
'added_value': 1,
|
||||
'frequency': 'monthly',
|
||||
'first_day_display': 'last',
|
||||
'cap_accrued_time': False,
|
||||
'action_with_unused_accruals': 'maximum',
|
||||
'postpone_max_days': 5
|
||||
})],
|
||||
})
|
||||
with freeze_time('2024-03-02'):
|
||||
accrual_allocation = self.env['hr.leave.allocation'].new({
|
||||
'name': 'History allocation',
|
||||
'holiday_status_id': self.leave_type.id,
|
||||
'date_from': '2024-03-01',
|
||||
'employee_id': self.employee_emp.id,
|
||||
'allocation_type': 'accrual',
|
||||
'accrual_plan_id': accrual_plan.id,
|
||||
})
|
||||
# As the duration is set to an onchange, we need to force that onchange to run
|
||||
accrual_allocation._onchange_date_from()
|
||||
self.assertAlmostEqual(accrual_allocation.number_of_days, 0, places=0)
|
||||
|
||||
# Yearly Report capped to 5 after 2022 and after 2023
|
||||
accrual_allocation.write({'date_from': '2022-01-01'})
|
||||
accrual_allocation._onchange_date_from()
|
||||
self.assertAlmostEqual(accrual_allocation.number_of_days, 7, places=0)
|
||||
|
||||
# Update date_to
|
||||
accrual_allocation.write({'date_to': '2022-12-31'})
|
||||
accrual_allocation._onchange_date_from()
|
||||
self.assertAlmostEqual(accrual_allocation.number_of_days, 12, places=0)
|
||||
|
||||
Reference in New Issue
Block a user