[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) <tde@openerp.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user