From fe313162b689e316bd603f138627e3ca0852dfa1 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Thu, 12 Aug 2010 17:59:18 +0200 Subject: [PATCH] [FIX] orm/_inherits: don't fail when trying to sort by inherited fields that are not stored - just ignore Also properly used _classic_read instead of _classic_write to check whether a field is stored. bzr revid: odo@openerp.com-20100812155918-c96q8w730cs5w1zp --- bin/osv/orm.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/bin/osv/orm.py b/bin/osv/orm.py index 0a908d32bea..d9918f6aeca 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -3823,16 +3823,21 @@ class orm(orm_template): if order: self._check_qorder(order) o = order.split(' ')[0] - if (o in self._columns) and getattr(self._columns[o], '_classic_write'): - order_by = order + if (o in self._columns): + # we can only do efficient sort if the fields is stored in database + if getattr(self._columns[o], '_classic_read'): + order_by = order elif (o in self._inherit_fields): - # Allowing inherited field for server side sorting - inherited_tables, inherit_join = self._inherits_join_calc(o,[],[]) # dry run to determine parent - inherited_sort_table = inherited_tables[0] - order_by = inherited_sort_table + '.' + order - if inherited_sort_table not in tables: - # add the missing join - self._inherits_join_calc(o, tables, where_clause) + parent_obj = self.pool.get(self._inherit_fields[o][0]) + if getattr(parent_obj._columns[o], '_classic_read'): + # Allowing inherits'ed field for server side sorting + inherited_tables, inherit_join = self._inherits_join_calc(o,[],[]) # dry run to determine parent + if inherited_tables: + inherited_sort_table = inherited_tables[0] + order_by = inherited_sort_table + '.' + order + if inherited_sort_table not in tables: + # add the missing join + self._inherits_join_calc(o, tables, where_clause) limit_str = limit and ' limit %d' % limit or '' offset_str = offset and ' offset %d' % offset or ''