[IMP] orm.fields_view_get: return cached selection values even when field is not...
authorOlivier Dony <odo@openerp.com>
Wed, 1 Sep 2010 12:08:27 +0000 (14:08 +0200)
committerOlivier Dony <odo@openerp.com>
Wed, 1 Sep 2010 12:08:27 +0000 (14:08 +0200)
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

index ad9ca48..ab07720 100644 (file)
@@ -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'):