From 3f91f85f60eaa15cad89d76bf4062db964e7ee6c Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Tue, 12 Aug 2014 12:07:10 +0200 Subject: [PATCH] [IMP] ORM: Coalesce NULL boolean values to false when generating ORDER BY After commit f28be81, boolean columns may have more NULL entries than before. In the (rare) cases where a boolean column was used for an ORDER clause (e.g. in the /shop page of website_sale), this causes a change of the resulting ordering. By coalescing NULL values to false in SQL, we make the ordering consistent with what the framework does for domain expressions with booleans, and when reading boolean values, that is, NULL is the same as False. --- openerp/models.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/openerp/models.py b/openerp/models.py index 664186b950c..e8b531a8f64 100644 --- a/openerp/models.py +++ b/openerp/models.py @@ -4420,6 +4420,7 @@ class BaseModel(object): order_split = order_part.strip().split(' ') order_field = order_split[0].strip() order_direction = order_split[1].strip() if len(order_split) == 2 else '' + order_column = None inner_clause = None if order_field == 'id': order_by_elements.append('"%s"."%s" %s' % (self._table, order_field, order_direction)) @@ -4442,6 +4443,8 @@ class BaseModel(object): continue # ignore non-readable or "non-joinable" fields else: raise ValueError( _("Sorting field %s not found on model %s") %( order_field, self._name)) + if order_column and order_column._type == 'boolean': + inner_clause = "COALESCE(%s, false)" % inner_clause if inner_clause: if isinstance(inner_clause, list): for clause in inner_clause: