[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
This commit is contained in:
Olivier Dony
2010-08-12 17:59:18 +02:00
parent 34be1742ad
commit fe313162b6
+14 -9
View File
@@ -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 ''