[IMP] fields: allow sorting on inherited field in list views

This commit is contained in:
Raphael Collet 2014-10-01 14:47:08 +02:00
parent a69996b50c
commit 53ff84493f
2 changed files with 12 additions and 3 deletions

View File

@ -374,9 +374,8 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi
var $column = $(e.currentTarget);
var col_name = $column.data('id');
var field = this.fields_view.fields[col_name];
// test if the field is a function field with store=false, since it's impossible
// for the server to sort those fields we desactivate the feature
if (field && field.store === false) {
// test whether the field is sortable
if (field && !field.sortable) {
return false;
}
this.dataset.sort(col_name);

View File

@ -408,6 +408,7 @@ class Field(object):
self.compute = self._compute_related
self.inverse = self._inverse_related
if field._description_searchable(env):
# allow searching on self only if the related field is searchable
self.search = self._search_related
# copy attributes from field to self (string, help, etc.)
@ -548,6 +549,15 @@ class Field(object):
bool(getattr(column, '_fnct_search', False))
return bool(self.search)
def _description_sortable(self, env):
if self.store:
column = env[self.model_name]._columns.get(self.name)
return bool(getattr(column, 'store', True))
if self.inherited:
# self is sortable if the inherited field is itself sortable
return self.related_field._description_sortable(env)
return False
_description_manual = property(attrgetter('manual'))
_description_depends = property(attrgetter('depends'))
_description_related = property(attrgetter('related'))