From ccb987dada8d376335d2f17bc36cb8b176345fb7 Mon Sep 17 00:00:00 2001 From: Xavier ALT Date: Tue, 2 Aug 2022 08:59:43 +0000 Subject: [PATCH] [FIX] rating: ensure `rating_last_value` computation is deterministic Running tests for `project` module only fails with the following error: ``` 2022-08-02 08:19:41,777 5669 ERROR testdb odoo.addons.project.tests.test_project_report: FAIL: TestProjectReport.test_avg_rating_measure Traceback (most recent call last): File "/build/odoo/saas-15.3/addons/project/tests/test_project_report.py", line 22, in test_avg_rating_measure self.assertEqual(self.task_1.rating_last_value, 5.0) AssertionError: 4.0 != 5.0 ``` With the ORM flush mechanisms when multiple ratings are created at once they all have the same `create_date` and/or `write_date`, this commit ensure the order is deterministic. closes odoo/odoo#97691 X-original-commit: 567d27cc600bdbb39d62e7aa75b37d48b33d27a5 Signed-off-by: Thibault Delavallee (tde) --- addons/project/tests/test_project_report.py | 2 +- addons/rating/models/rating.py | 2 +- addons/rating/models/rating_mixin.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/project/tests/test_project_report.py b/addons/project/tests/test_project_report.py index 2e6f3fe594e..b85e509452b 100644 --- a/addons/project/tests/test_project_report.py +++ b/addons/project/tests/test_project_report.py @@ -19,7 +19,7 @@ class TestProjectReport(TestProjectCommon): {**rating_vals, 'rating': 4.25, 'res_id': self.task_2.id}, ]) self.assertEqual(self.task_1.rating_avg, 4.5) - self.assertEqual(self.task_1.rating_last_value, 5.0) + self.assertEqual(self.task_1.rating_last_value, 4.0) self.assertEqual(self.task_2.rating_avg, 4.25) self.assertEqual(self.task_2.rating_last_value, 4.25) diff --git a/addons/rating/models/rating.py b/addons/rating/models/rating.py index de9689ae9fa..a91149cae92 100644 --- a/addons/rating/models/rating.py +++ b/addons/rating/models/rating.py @@ -11,7 +11,7 @@ from odoo.modules.module import get_resource_path class Rating(models.Model): _name = "rating.rating" _description = "Rating" - _order = 'write_date desc' + _order = 'write_date desc, id desc' _rec_name = 'res_name' @api.model diff --git a/addons/rating/models/rating_mixin.py b/addons/rating/models/rating_mixin.py index 4cd9e384911..37716eaf860 100644 --- a/addons/rating/models/rating_mixin.py +++ b/addons/rating/models/rating_mixin.py @@ -35,7 +35,7 @@ class RatingMixin(models.AbstractModel): return self.env.cr.execute(""" SELECT - array_agg(rating ORDER BY write_date DESC) AS "ratings", + array_agg(rating ORDER BY write_date DESC, id DESC) AS "ratings", res_id as res_id FROM "rating_rating" WHERE