From 1b7698193544b66c9ad84c2e351e5a786e6dbdad Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Wed, 1 Sep 2010 14:08:27 +0200 Subject: [PATCH] [IMP] orm.fields_view_get: return cached selection values even when field is not invisible This solves potential issues at client-side when a refresh or on_change trigger changes the value of the invisible field but the client does not allow it because it is not part of the available values as far as it knows. bzr revid: odo@openerp.com-20100901120827-kbthqdkm6qlc1ugu --- bin/osv/orm.py | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/bin/osv/orm.py b/bin/osv/orm.py index ad9ca48..ab07720 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -1313,29 +1313,25 @@ class orm_template(object): } attrs = {'views': views} if node.get('widget') and node.get('widget') == 'selection': - if not check_group(node): - name = node.get('name') - default = self.default_get(cr, user, [name], context=context).get(name) - if default: - attrs['selection'] = relation.name_get(cr, 1, [default], context=context) - else: - attrs['selection'] = [] - # We can not use the 'string' domain has it is defined according to the record ! - else: - # If domain and context are strings, we keep them for client-side, otherwise - # we evaluate them server-side to consider them when generating the list of - # possible values - # TODO: find a way to remove this hack, by allow dynamic domains - dom = [] - if column._domain and not isinstance(column._domain, basestring): - dom = column._domain - dom += eval(node.get('domain','[]'), {'uid':user, 'time':time}) - search_context = dict(context) - if column._context and not isinstance(column._context, basestring): - search_context.update(column._context) - attrs['selection'] = relation._name_search(cr, 1, '', dom, context=search_context, limit=None, name_get_uid=1) - if (node.get('required') and not int(node.get('required'))) or not column.required: - attrs['selection'].append((False,'')) + # Prepare the cached selection list for the client. This needs to be + # done even when the field is invisible to the current user, because + # other events could need to change its value to any of the selectable ones + # (such as on_change events, refreshes, etc.) + + # If domain and context are strings, we keep them for client-side, otherwise + # we evaluate them server-side to consider them when generating the list of + # possible values + # TODO: find a way to remove this hack, by allow dynamic domains + dom = [] + if column._domain and not isinstance(column._domain, basestring): + dom = column._domain + dom += eval(node.get('domain','[]'), {'uid':user, 'time':time}) + search_context = dict(context) + if column._context and not isinstance(column._context, basestring): + search_context.update(column._context) + attrs['selection'] = relation._name_search(cr, 1, '', dom, context=search_context, limit=None, name_get_uid=1) + if (node.get('required') and not int(node.get('required'))) or not column.required: + attrs['selection'].append((False,'')) fields[node.get('name')] = attrs elif node.tag in ('form', 'tree'): -- 1.7.10.4