[FIX] allow to use server-side domains with widget='selection' fields
authorChristophe Simonis <christophe@tinyerp.com>
Tue, 28 Apr 2009 14:40:14 +0000 (16:40 +0200)
committerChristophe Simonis <christophe@tinyerp.com>
Tue, 28 Apr 2009 14:40:14 +0000 (16:40 +0200)
[FIX] widget='selection' fields now handle correctly the required fields

bzr revid: christophe@tinyerp.com-20090428144014-7wxt52bfy5odnf5r

bin/osv/orm.py

index b3b92dc..cfc3111 100644 (file)
@@ -800,13 +800,14 @@ class orm_template(object):
                 attrs = {}
                 try:
                     if node.getAttribute('name') in self._columns:
-                        relation = self._columns[node.getAttribute('name')]._obj
+                        column = self._columns[node.getAttribute('name')]
                     else:
-                        relation = self._inherit_fields[node.getAttribute('name')][2]._obj
+                        column = self._inherit_fields[node.getAttribute('name')][2]
                 except:
-                    relation = False
+                    column = False
 
-                if relation:
+                if column:
+                    relation = column._obj
                     childs = False
                     views = {}
                     for f in node.childNodes:
@@ -821,9 +822,12 @@ class orm_template(object):
                             }
                     attrs = {'views': views}
                     if node.hasAttribute('widget') and node.getAttribute('widget')=='selection':
-                        # We can not use the domain has it is defined according to the record !
-                        attrs['selection'] = self.pool.get(relation).name_search(cr, user, '', context=context)
-                        if not attrs.get('required',False):
+                        # We can not use the 'string' domain has it is defined according to the record !
+                        dom = None
+                        if column._domain and not isinstance(column._domain, (str, unicode)):
+                            dom = column._domain
+                        attrs['selection'] = self.pool.get(relation).name_search(cr, user, '', dom, context=context)
+                        if (node.hasAttribute('required') and not int(node.getAttribute('required'))) or not column.required:
                             attrs['selection'].append((False,''))
                 fields[node.getAttribute('name')] = attrs