From 51f8d2a7e865d4d2a4b0519943189bc4de661d47 Mon Sep 17 00:00:00 2001 From: dise Date: Tue, 13 Jun 2023 12:52:51 +0000 Subject: [PATCH] [FIX] project: fix traceback when opening customer rating view If a project had a single rating associated to its tasks, opening the customer rating view would create a traceback. This happened because both the mail.thread model and the rating.parent.mixin model have a rating_ids field, and project inherits from both of them (mail.thread on its own doesn't have it, but the rating mixin adds it). In the action_view_all_rating method, we try to access the first element of the rating_ids recordset, if the rating_count field is equal to 1. But since the rating_ids field belonged to the mail.thread mixin, and not to the rating.parent.mixin, there could be occurences where rating_count was equal to 1 while the recordset was actually empty ; accessing the first element of the recordset would then create a traceback. To fix this, the rating.parent.mixin model was put before the mail.thread model in the _inherit list, this way the rating_ids field from rating.parent.mixin has the priority. A test was also added to check if the rating_ids is working correctly. task-3360029 closes odoo/odoo#127243 X-original-commit: 1039c80a8ff5e219e9c2679505015288c8d8dd35 Signed-off-by: Xavier Bol (xbo) --- addons/project/models/project_project.py | 2 +- addons/project/tests/test_project_base.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/addons/project/models/project_project.py b/addons/project/models/project_project.py index 4f1f6cb0854..dd6556f341f 100644 --- a/addons/project/models/project_project.py +++ b/addons/project/models/project_project.py @@ -16,7 +16,7 @@ from .project_task import CLOSED_STATES class Project(models.Model): _name = "project.project" _description = "Project" - _inherit = ['portal.mixin', 'mail.alias.mixin', 'mail.thread', 'mail.activity.mixin', 'rating.parent.mixin'] + _inherit = ['portal.mixin', 'mail.alias.mixin', 'rating.parent.mixin', 'mail.thread', 'mail.activity.mixin'] _order = "sequence, name, id" _rating_satisfaction_days = 30 # takes 30 days by default _check_company_auto = True diff --git a/addons/project/tests/test_project_base.py b/addons/project/tests/test_project_base.py index 1807f83fcb0..b1f417db3bb 100644 --- a/addons/project/tests/test_project_base.py +++ b/addons/project/tests/test_project_base.py @@ -226,3 +226,19 @@ class TestProjectBase(TestProjectCommon): self.assertEqual(ProjectTask.search([('project_root_id', '=?', project.id)]), tasks) self.assertEqual(ProjectTask.search([('project_root_id', 'not in', other_projects.ids), ('id', 'in', tasks.ids)]), tasks) self.assertEqual(ProjectTask.search([('project_root_id', '!=', self.project_pigs.id), ('id', 'in', tasks.ids)]), tasks) + + def test_add_customer_rating_project(self): + """ Tests that the rating_ids field contains a rating once created + """ + rate = self.env['rating.rating'].create({ + 'res_id': self.task_1.id, + 'parent_res_id': self.project_pigs.id, + 'res_model_id': self.env['ir.model']._get('project.task').id, + 'parent_res_model_id': self.env['ir.model']._get('project.project').id, + }) + rating = 5 + + self.task_1.rating_apply(rating, token=rate.access_token) + + self.project_pigs.rating_ids.invalidate_recordset() + self.assertEqual(len(self.project_pigs.rating_ids), 1, "There should be 1 rating linked to the project")