From 5b7d766fc3c2e37a8e57f40837f53c3cd874cafd Mon Sep 17 00:00:00 2001 From: Vincent Larcin Date: Wed, 31 May 2023 07:42:07 +0000 Subject: [PATCH] [FIX] hr_timesheet: fix traceback on deleting tasks Steps to reproduce ------------------ 1. Install hr_timesheet. 2. Try deleting a task. You will get a traceback. Explanation ----------- In https://github.com/odoo/odoo/pull/110737, the calls to `_read_group` were adapted to the new API, but a slight mistake was introduced when adapting the code in `_unlink_except_contains_entries`. This commit fixes it. closes odoo/odoo#123597 X-original-commit: 83046fb1fd00ffde7568c35c76697ecf7f4db8fa Signed-off-by: Xavier Bol (xbo) --- addons/hr_timesheet/models/project_task.py | 2 +- addons/hr_timesheet/tests/test_timesheet.py | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/addons/hr_timesheet/models/project_task.py b/addons/hr_timesheet/models/project_task.py index b91dc125052..b112098af99 100644 --- a/addons/hr_timesheet/models/project_task.py +++ b/addons/hr_timesheet/models/project_task.py @@ -224,7 +224,7 @@ class Task(models.Model): [('task_id', 'in', self.ids)], ['task_id'], ) - task_with_timesheets_ids = [task.id for task in timesheet_data] + task_with_timesheets_ids = [task.id for task, in timesheet_data] if task_with_timesheets_ids: if len(task_with_timesheets_ids) > 1: warning_msg = _("These tasks have some timesheet entries referencing them. Before removing these tasks, you have to remove these timesheet entries.") diff --git a/addons/hr_timesheet/tests/test_timesheet.py b/addons/hr_timesheet/tests/test_timesheet.py index 920abffdb0c..023a866bbf7 100644 --- a/addons/hr_timesheet/tests/test_timesheet.py +++ b/addons/hr_timesheet/tests/test_timesheet.py @@ -5,7 +5,7 @@ from lxml import etree from odoo.fields import Command from odoo.tests.common import TransactionCase, Form -from odoo.exceptions import AccessError, UserError, ValidationError +from odoo.exceptions import AccessError, RedirectWarning, UserError, ValidationError class TestCommonTimesheet(TransactionCase): @@ -596,3 +596,15 @@ class TestTimesheet(TestCommonTimesheet): self.env.company.timesheet_encode_uom_id = self.env.ref('uom.product_uom_day') self.assertEqual(project.total_timesheet_time, 8, "Total timesheet time should be 8 hours") self.assertEqual(project.timesheet_encode_uom_id.name, 'Days', "Timesheet encode uom should be 'Days'") + + def test_unlink_task_with_timesheet(self): + self.env['account.analytic.line'].create({ + 'project_id': self.project_customer.id, + 'task_id': self.task1.id, + 'name': 'timesheet', + 'unit_amount': 4, + 'employee_id': self.empl_employee.id, + }) + self.task2.unlink() + with self.assertRaises(RedirectWarning): + self.task1.unlink()