[FIX] hr_holidays: prevent misplacement of allocations without end date
First issue (functional) ------------------------ Steps to reproduce: - create a type of leave - create an allocation for X days for month A without end date - create an allocation for Y days for month B without end date - create a leave of X + Y days for month A Remark: Months A and B do not have to be consecutive. Issue: If allocations have not end date, it is possible to use allocation in an other interval. Second issue (display) ---------------------- On the dashboard we see the total number of allocations even if we cannot place them for allocations without an end date. This behavior contradicts that of allocations with an end date. Solution: --------- Make an additional check on the start date of an allocation. This verification is very restrictive. It stipulates that if the end date of a leave is before the start date of an allocation, the allocation in question must not be taken into account in the dynamic calculation to link the allocations to the leaves. In addition, this verification will make sure to trigger the hack of the commit 02695aa095428b4ef5045f9c90d1b508ec9d896c. Therefore a Validation Error will be raised. From a display point of view, it will be fixed on the dashboard and in the modal window to make a leave request. opw-3230286 closes odoo/odoo#117024 X-original-commit: 745221b478e0a587ac51fd3f0fca8e067b473b12 Signed-off-by: Kevin Baptiste <kba@odoo.com> Signed-off-by: Lefebvre Thomas (thle) <thle@odoo.com>
This commit is contained in:
@@ -313,7 +313,8 @@ class HolidaysType(models.Model):
|
||||
leave_unit = 'hours'
|
||||
if holiday_status_id.requires_allocation != 'no':
|
||||
for available_allocation in sorted_available_allocations:
|
||||
if available_allocation.date_to and available_allocation.date_to < leave.date_from.date():
|
||||
if (available_allocation.date_to and available_allocation.date_to < leave.date_from.date()) \
|
||||
or (available_allocation.date_from > leave.date_to.date()):
|
||||
continue
|
||||
virtual_remaining_leaves = (available_allocation.number_of_days if leave_unit == 'days' else available_allocation.number_of_hours_display) - allocations_days_consumed[employee_id][holiday_status_id][available_allocation]['virtual_leaves_taken']
|
||||
max_leaves = min(virtual_remaining_leaves, leave_duration)
|
||||
@@ -352,7 +353,7 @@ class HolidaysType(models.Model):
|
||||
if future_allocation_interval[0].date() > search_date:
|
||||
continue
|
||||
for allocation in future_allocation_interval[2]:
|
||||
if not allocation.active:
|
||||
if not allocation.active or allocation.date_from > search_date:
|
||||
continue
|
||||
days_consumed = allocations_days_consumed[employee_id][holiday_status_id][allocation]
|
||||
if future_allocation_interval[1] != fields.datetime.combine(date, time.max) + timedelta(days=5*365):
|
||||
|
||||
@@ -1012,3 +1012,49 @@ class TestLeaveRequests(TestHrHolidaysCommon):
|
||||
'number_of_days': 1,
|
||||
'supported_attachment_ids': [(6, 0, [])], # Sent by webclient
|
||||
})
|
||||
|
||||
def test_prevent_misplacement_of_allocations_without_end_date(self):
|
||||
"""
|
||||
The objective is to check that it is not possible to place leaves
|
||||
for which the interval does not correspond to the interval of allocations.
|
||||
"""
|
||||
holiday_type_A = self.env['hr.leave.type'].with_user(self.user_hrmanager_id).with_context(tracking_disable=True).create({
|
||||
'name': 'Type A',
|
||||
'requires_allocation': 'yes',
|
||||
'employee_requests': 'yes',
|
||||
'leave_validation_type': 'hr',
|
||||
})
|
||||
|
||||
# Create allocations with no end date
|
||||
allocations = self.env['hr.leave.allocation'].create([
|
||||
{
|
||||
'name': 'Type A march 1 day without date to',
|
||||
'employee_id': self.employee_emp_id,
|
||||
'holiday_status_id': holiday_type_A.id,
|
||||
'number_of_days': 1,
|
||||
'state': 'confirm',
|
||||
'date_from': '2023-01-03',
|
||||
},
|
||||
{
|
||||
'name': 'Type A april 5 day without date to',
|
||||
'employee_id': self.employee_emp_id,
|
||||
'holiday_status_id': holiday_type_A.id,
|
||||
'number_of_days': 5,
|
||||
'state': 'confirm',
|
||||
'date_from': '2023-04-01',
|
||||
},
|
||||
])
|
||||
|
||||
allocations.action_validate()
|
||||
|
||||
trigger_error_leave = {
|
||||
'name': 'Holiday Request',
|
||||
'employee_id': self.employee_emp_id,
|
||||
'holiday_status_id': holiday_type_A.id,
|
||||
'date_from': '2023-03-14',
|
||||
'date_to': '2023-03-16',
|
||||
'number_of_days': 3,
|
||||
}
|
||||
|
||||
with self.assertRaises(ValidationError):
|
||||
self.env['hr.leave'].with_user(self.user_employee_id).create(trigger_error_leave)
|
||||
|
||||
Reference in New Issue
Block a user