From ac8c6736fc721085e58f5be25bfa8ccb3dc58788 Mon Sep 17 00:00:00 2001 From: "Thomas Carlier(thc)" Date: Thu, 29 Dec 2022 09:13:19 +0000 Subject: [PATCH] [FIX] project_timesheet_holidays: Fix traceback when no timesheet_task_id is found. -steps to reproduce: do a search in project.task on is_timeoff_task when no timesheet_task_id is defined on any hr.leave_type. This will trigger the _search_is_timeoff_task method -before this commit: crash when no leave_type with timesheet_task_id is found -after this commit: creation of an empty list as expected opw-3086486 closes odoo/odoo#110091 X-original-commit: b98949b1cb85514ee5a56ff1a5860591c10b0994 Signed-off-by: Xavier Bol (xbo) --- addons/project_timesheet_holidays/models/project_task.py | 2 +- .../tests/test_timesheet_global_time_off.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/addons/project_timesheet_holidays/models/project_task.py b/addons/project_timesheet_holidays/models/project_task.py index fac32a30904..660ad45e52a 100644 --- a/addons/project_timesheet_holidays/models/project_task.py +++ b/addons/project_timesheet_holidays/models/project_task.py @@ -32,7 +32,7 @@ class Task(models.Model): ['timesheet_task_ids:array_agg(timesheet_task_id)'], [], ) - timeoff_task_ids = leave_type_read_group[0]['timesheet_task_ids'] if leave_type_read_group else [] + timeoff_task_ids = leave_type_read_group[0]['timesheet_task_ids'] if leave_type_read_group[0]['timesheet_task_ids'] else [] if self.env.company.leave_timesheet_task_id: timeoff_task_ids.append(self.env.company.leave_timesheet_task_id.id) if operator == '!=': diff --git a/addons/project_timesheet_holidays/tests/test_timesheet_global_time_off.py b/addons/project_timesheet_holidays/tests/test_timesheet_global_time_off.py index 0112b111992..814f35d9903 100644 --- a/addons/project_timesheet_holidays/tests/test_timesheet_global_time_off.py +++ b/addons/project_timesheet_holidays/tests/test_timesheet_global_time_off.py @@ -175,3 +175,12 @@ class TestTimesheetGlobalTimeOff(common.TransactionCase): # The standard calendar is for 8 hours/day from 8 to 12 and from 13 to 17. # So we need to check that the timesheets don't have more than 8 hours per day. self.assertEqual(leave_task.effective_hours, 80) + + def test_search_is_timeoff_task(self): + """ Test the search method on is_timeoff_task + with and without any hr.leave.type with timesheet_task_id defined""" + leaves_types_with_task_id = self.env['hr.leave.type'].search([('timesheet_task_id', '!=', False)]) + self.env['project.task'].search([('is_timeoff_task', '!=', False)]) + + leaves_types_with_task_id.write({'timesheet_task_id': False}) + self.env['project.task'].search([('is_timeoff_task', '!=', False)])