[FIX] hr_holidays: reset allocation to 0 on date change
Issue:
- when creating an accrual plan based on attendance,
the duration is not computed accurately when allocating.
- the computation is not correct if you select a different
start date in the allocation without emptying the field "Allocation"
Steps To Reproduce:
- In the time-off app create an accrual plan: where employee
accrue 1h for every hour worked based on attendance.
- In the attendance app create a new attendance for 8 hours.
- add a new allocation to Mitchell Admin with the plan you created.
- Change the date on the validity period, new allocation is 8h.
- change the date again and notice the Allocation not computed correctly.
Solution:
- In `_onchange_date_from` when simulating how many days an
accrual plan would give from a certian `date_from` we don't reset
`number_of_days` to 0. reseting it to 0 fixes the issue.
opw-3793961
closes odoo/odoo#160696
Signed-off-by: Sofie Gvaladze (sgv) <sgv@odoo.com>
This commit is contained in:
@@ -837,6 +837,8 @@ class HolidaysAllocation(models.Model):
|
||||
self.lastcall = self.date_from
|
||||
self.nextcall = False
|
||||
self.number_of_days_display = 0.0
|
||||
self.number_of_hours_display = 0.0
|
||||
self.number_of_days = 0.0
|
||||
date_to = min(self.date_to, date.today()) if self.date_to else False
|
||||
self._process_accrual_plans(date_to)
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import datetime
|
||||
from freezegun import freeze_time
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
from odoo.tests import tagged
|
||||
from odoo.tests import Form, tagged
|
||||
|
||||
from odoo.addons.hr_holidays.tests.common import TestHrHolidaysCommon
|
||||
|
||||
@@ -67,3 +67,37 @@ class TestAccrualAllocationsAttendance(TestHrHolidaysCommon):
|
||||
self.assertEqual(allocation.nextcall, nextcall, 'The next call date of the cron should be in 2 days.')
|
||||
allocation._update_accrual()
|
||||
self.assertAlmostEqual(allocation.number_of_days, 4.37, places=2)
|
||||
|
||||
def test_accrual_allocation_based_on_attendance(self):
|
||||
accrual_plan = self.env['hr.leave.accrual.plan'].create({
|
||||
'name': 'Accrual Plan For Test',
|
||||
'is_based_on_worked_time': False,
|
||||
'accrued_gain_time': 'end',
|
||||
'carryover_date': 'year_start',
|
||||
'level_ids': [(0, 0, {
|
||||
'start_count': 1,
|
||||
'added_value': 1,
|
||||
'added_value_type': 'hour',
|
||||
'frequency': 'hourly',
|
||||
'cap_accrued_time': True,
|
||||
'maximum_leave': 100,
|
||||
'frequency_hourly_source': 'attendance'
|
||||
})],
|
||||
})
|
||||
self.env['hr.attendance'].create({
|
||||
'employee_id': self.employee_emp.id,
|
||||
'check_in': datetime.datetime(2024, 4, 1, 8, 0, 0),
|
||||
'check_out': datetime.datetime(2024, 4, 1, 17, 0, 0),
|
||||
})
|
||||
with Form(self.env['hr.leave.allocation']) as allocation_form:
|
||||
allocation_form.allocation_type = 'accrual'
|
||||
allocation_form.employee_ids = self.employee_emp
|
||||
allocation_form.accrual_plan_id = accrual_plan
|
||||
allocation_form.holiday_status_id = self.leave_type
|
||||
allocation_form.holiday_type = 'employee'
|
||||
allocation_form.date_from = datetime.date(2024, 3, 20)
|
||||
allocation_form.name = 'Accrual allocation for employee'
|
||||
self.assertEqual(allocation_form.number_of_hours_display, 8.0)
|
||||
allocation_form.date_from = datetime.date(2024, 3, 25)
|
||||
allocation_form.name = 'Accrual allocation for employee'
|
||||
self.assertEqual(allocation_form.number_of_hours_display, 8.0)
|
||||
|
||||
Reference in New Issue
Block a user