From c83b7e80a4c64988bcda8999aaa842b2a7786351 Mon Sep 17 00:00:00 2001 From: "Gauthier Wala (gawa)" Date: Fri, 28 Jul 2023 15:42:55 +0000 Subject: [PATCH] [FIX] account: frequent tax undeterministic result - Create a db with account installed (and a random loca) - Run the test "test_quick_edit_total_amount" => The test may fail (undeterministically), especially the first time The reason is that we don't have an order in "_get_frequent_account_and_taxes" So, if we have the same number of lines with the same account and with a tax or without one, we can not guarantee which tax is considered the most frequent. We now define the order by saying that we should take the taxes into account, so lines with taxes take precedence on lines without Linked to runbot error 23385 closes odoo/odoo#130326 X-original-commit: bdb21983371fb62b01275471e8ca7099219e1053 Signed-off-by: Brice Bartoletti (bib) --- addons/account/models/account_move.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 48ad6b2c7ca..7a5ee11f69f 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -2793,7 +2793,7 @@ class AccountMove(models.Model): SELECT account_move_line__account_id.id AS account_id, account_move_line__account_id.code, account_move_line.id, - ARRAY_AGG(tax_rel.account_tax_id) AS taxes + ARRAY_AGG(tax_rel.account_tax_id) FILTER (WHERE tax_rel.account_tax_id IS NOT NULL) AS taxes FROM {from_clause} LEFT JOIN account_move_line_account_tax_rel tax_rel ON account_move_line.id = tax_rel.account_move_line_id WHERE {where_clause} @@ -2801,7 +2801,7 @@ class AccountMove(models.Model): account_move_line.id ) AS foo GROUP BY foo.account_id, foo.code, foo.taxes - ORDER BY COUNT(foo.id) DESC, foo.code + ORDER BY COUNT(foo.id) DESC, foo.code, taxes ASC NULLS LAST LIMIT 1 """, params) return self._cr.fetchone() or (0, False, False)