From 48ccbe67c66755d14ab537d04ac9ff407efe6335 Mon Sep 17 00:00:00 2001 From: SEINLET Nicolas Date: Thu, 20 Aug 2020 09:28:58 +0000 Subject: [PATCH] [IMP] account: make sequence indexable the search for sequence include a criteria `date_trunc('year', date) = date_trunc('year', '2017-10-01'::date)` Which is translated by query planner in `date_trunc('year'::text, date::timestamp with time zone)`. As it's mutable thanks to the time zone, it's not indexable. Enforcing the `without timezone` makes the query planner use an immutable `date_trunc('year'::text, date::timestamp without time zone)`. As it's immutable, it's indexable. closes odoo/odoo#56244 X-original-commit: 70f671a32a504c6aa92fd19e38e6151c10b2325b Signed-off-by: Quentin De Paoli (qdp) --- 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 1a61e2be1ef..fcdc9ffb6ae 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -1038,10 +1038,10 @@ class AccountMove(models.Model): reference_move = self.search(domain + [('date', '<=', self.date)], order='date desc', limit=1) or self.search(domain, order='date asc', limit=1) sequence_number_reset = self._deduce_sequence_number_reset(reference_move.name) if sequence_number_reset == 'year': - where_string += " AND date_trunc('year', date) = date_trunc('year', %(date)s) " + where_string += " AND date_trunc('year', date::timestamp without time zone) = date_trunc('year', %(date)s) " param['date'] = self.date elif sequence_number_reset == 'month': - where_string += " AND date_trunc('month', date) = date_trunc('month', %(date)s) " + where_string += " AND date_trunc('month', date::timestamp without time zone) = date_trunc('month', %(date)s) " param['date'] = self.date if self.journal_id.refund_sequence: