[FIX] hr_holidays: fix accrual leaves display

Before this commit, leaves linked to accrual allocations
taken in the future would still be takin into account in the display,
resulting in a warning if the leave excessed the amount that the
employee currently had allocated.
This leave removes any future leave to be taken into account if
the leave type has any accrual allocation set for the employee.

closes odoo/odoo#140888

Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
This commit is contained in:
Dossogne Bertrand
2023-11-04 03:25:44 +00:00
parent 0a9e83dfd8
commit 4edba45a51
+3 -1
View File
@@ -494,6 +494,7 @@ class HrEmployee(models.Model):
leave_type_data = allocations_leaves_consumed[employee][leave_type]
for leave in leaves_per_employee_type[employee][leave_type].sorted('date_from'):
leave_duration = leave[leave_duration_field]
skip_excess = False
if leave_type.requires_allocation == 'yes':
for allocation in sorted_leave_allocations:
# We don't want to include future leaves linked to accruals into the total count of available leaves.
@@ -501,6 +502,7 @@ class HrEmployee(models.Model):
# to give a warning if the total exceeds what will be accrued.
if allocation.allocation_type == 'accrual' and leave.date_from.date() > target_date:
to_recheck_leaves_per_leave_type[employee][leave_type]['to_recheck_leaves'] |= leave
skip_excess = True
continue
interval_start = max(
leave.date_from,
@@ -530,7 +532,7 @@ class HrEmployee(models.Model):
leave_duration -= allocated_time
if not leave_duration:
break
if round(leave_duration, 2) > 0:
if round(leave_duration, 2) > 0 and not skip_excess:
to_recheck_leaves_per_leave_type[employee][leave_type]['excess_days'][leave.date_to.date()] = {
'amount': leave_duration,
'is_virtual': leave.state != 'validate',