From 36d2643e19ef7868a475751b19305402028fb231 Mon Sep 17 00:00:00 2001
From: Akim Juillerat <akim.juillerat@camptocamp.com>
Date: Tue, 30 Nov 2021 15:13:15 +0000
Subject: [PATCH] account: Fix journal dashboard graph query order

As the query results are set in a list of dicts relying on the
position of the dicts inside the list, the SQL query must ensure
the results returned by postgres are ordered properly so that it
will match the order in which the dicts are defined inside the list.

closes odoo/odoo#81966

X-original-commit: bac93bf56ff67a89f9381137b0c67642a302e6bb
Signed-off-by: Laurent Smet <las@odoo.com>
---
 addons/account/models/account_journal_dashboard.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/addons/account/models/account_journal_dashboard.py b/addons/account/models/account_journal_dashboard.py
index dec1902838ac..2a70413932b4 100644
--- a/addons/account/models/account_journal_dashboard.py
+++ b/addons/account/models/account_journal_dashboard.py
@@ -175,7 +175,8 @@ class account_journal(models.Model):
                 next_date = start_date + timedelta(days=7)
                 query += " UNION ALL ("+select_sql_clause+" and invoice_date_due >= '"+start_date.strftime(DF)+"' and invoice_date_due < '"+next_date.strftime(DF)+"')"
                 start_date = next_date
-
+        # Ensure results returned by postgres match the order of data list
+        query += " ORDER BY aggr_date ASC"
         self.env.cr.execute(query, query_args)
         query_results = self.env.cr.dictfetchall()
         is_sample_data = True
-- 
GitLab