Skip to content
Snippets Groups Projects
Commit 2b3cc596 authored by Thomas Lefebvre (thle)'s avatar Thomas Lefebvre (thle)
Browse files

[FIX] hr_holidays: manage refused leave in the report


Steps to reproduce:
-------------------
- add an allocation for an employee;
- add a leave with this allocation;
- validate the leave;
- refuse the leave;
- in action menu, click on "Time off Analysis by Employee and Time Off Type".

Issue:
------
The report does not take into account refused allocations and leaves.

Solution:
---------
Add a condition to take a number of days equal to zero
if the allocation or leave is in a refused state.

Handled the case where no record is found for leave
(with `COALESCE` because `value - NULL = NULL`).

opw-3503617

closes odoo/odoo#135748

Signed-off-by: default avatarSofie Gvaladze (sgv) <sgv@odoo.com>
parent ba8f99c0
No related branches found
No related tags found
No related merge requests found
......@@ -51,7 +51,7 @@ class LeaveReport(models.Model):
allocation.employee_id as employee_id,
CASE
WHEN allocation.id = min_allocation_id.min_id
THEN aggregate_allocation.number_of_days - aggregate_leave.number_of_days
THEN aggregate_allocation.number_of_days - COALESCE(aggregate_leave.number_of_days, 0)
ELSE 0
END as number_of_days,
allocation.department_id as department_id,
......@@ -69,16 +69,21 @@ class LeaveReport(models.Model):
FROM hr_leave_allocation GROUP BY employee_id, holiday_status_id) min_allocation_id
on (allocation.employee_id=min_allocation_id.employee_id and allocation.holiday_status_id=min_allocation_id.holiday_status_id)
/* Obtain the sum of allocations */
/* Obtain the sum of allocations (validated) */
LEFT JOIN
(SELECT employee_id, holiday_status_id, sum(number_of_days) as number_of_days
FROM hr_leave_allocation GROUP BY employee_id, holiday_status_id) aggregate_allocation
(SELECT employee_id, holiday_status_id,
sum(CASE WHEN state = 'validate' and active = True THEN number_of_days ELSE 0 END) as number_of_days
FROM hr_leave_allocation
GROUP BY employee_id, holiday_status_id) aggregate_allocation
on (allocation.employee_id=aggregate_allocation.employee_id and allocation.holiday_status_id=aggregate_allocation.holiday_status_id)
/* Obtain the sum of requested leaves (validated and confirmed) */
/* Obtain the sum of requested leaves (validated) */
LEFT JOIN
(SELECT employee_id, holiday_status_id, sum(number_of_days) as number_of_days
FROM hr_leave GROUP BY employee_id, holiday_status_id) aggregate_leave
(SELECT employee_id, holiday_status_id,
sum(CASE WHEN state IN ('validate', 'validate1') THEN number_of_days ELSE 0 END) as number_of_days
FROM hr_leave
GROUP BY employee_id, holiday_status_id) aggregate_leave
on (allocation.employee_id=aggregate_leave.employee_id and allocation.holiday_status_id = aggregate_leave.holiday_status_id)
UNION ALL SELECT
......@@ -94,7 +99,9 @@ class LeaveReport(models.Model):
WHEN request.state = 'confirm' THEN 'planned'
END as holiday_status,
request.employee_company_id as company_id
FROM hr_leave as request) leaves
FROM hr_leave as request
WHERE request.state IN ('confirm', 'validate', 'validate1')
) leaves
);
""")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment