From 4d2cb0ae829067ea17ad3fc26f7b80c7beafd2b9 Mon Sep 17 00:00:00 2001 From: "Victor Piryns (pivi)" Date: Wed, 1 Mar 2023 10:54:19 +0000 Subject: [PATCH] [FIX] hr_timesheet: fix filter of project in overtime Current behaviour: Search filter is not showing correct results for projects that are in overtime. Some projects that are not in overtime are not shown. Expected behaviour: Search filter for projects that are in overtime should work correctly. Steps to reproduce: - Install Project, Timesheets - In one of the projects, create a task in an "In Progress" stage - Add an employee on it, planned hours to 1h, and log in the timesheet 50 hours (so the task is clearly in overtime of 49h) - In that task, add an employee, planned hours to 50h - In the same project, create a task in a folded stage, log in the timesheet 1h (the task is +49h remaining hours in the green) - Fold the stage when done editing the stage. - In the project default view, we can clearly see that the project is in the red (-49h). - Filter based on overtime, the project is not present in the results Reason for the problem: There is a divergence of behaviour between the compute and the search method of the `is_project_overtime` on the project. The compute takes only the overtime of the tasks that are not in a folded stage. While the search is query all the tasks of the project, regardless of stage and summing those to deternine if the project is in overtime. So if you have 2 tasks, one in a folded stage and the other not, that have `remaining_hours` that are cancelling each other, the search result is incorrect for that project Fix: Update the SQL query in the search method for `is_project_overtime`, to reflect the domain conditions from the compute about the stages. Affected versions: - saas-15.2 - 16.0 - saas-16.1 - master opw-3182077 closes odoo/odoo#116992 X-original-commit: 69f1441133e30b8dc0cc331afcec933d694665e0 Signed-off-by: Xavier Bol (xbo) Signed-off-by: Piryns Victor (pivi) --- addons/hr_timesheet/models/project_project.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/addons/hr_timesheet/models/project_project.py b/addons/hr_timesheet/models/project_project.py index 6e0a54c96e6..c5b200f3396 100644 --- a/addons/hr_timesheet/models/project_project.py +++ b/addons/hr_timesheet/models/project_project.py @@ -96,12 +96,16 @@ class Project(models.Model): raise ValueError(_('Invalid operator: %s') % operator) query = """ - SELECT P.id - FROM project_project P - LEFT JOIN project_task T ON P.id = T.project_id - WHERE p.allocated_hours != 0 AND p.allow_timesheets - GROUP BY P.id - HAVING P.allocated_hours - SUM(T.effective_hours) < 0 + SELECT Project.id + FROM project_project AS Project + JOIN project_task AS Task + ON Project.id = Task.project_id + WHERE Project.allocated_hours > 0 + AND Project.allow_timesheets = TRUE + AND Task.parent_id IS NULL + AND Task.is_closed IS FALSE + GROUP BY Project.id + HAVING Project.allocated_hours - SUM(Task.effective_hours) < 0 """ if (operator == '=' and value is True) or (operator == '!=' and value is False): operator_new = 'inselect'