bugfix for active=false search
[odoo/odoo.git] / bin / osv / orm.py
index 9572053..0acfba6 100644 (file)
@@ -1,31 +1,24 @@
 # -*- encoding: utf-8 -*-
 ##############################################################################
 #
-# Copyright (c) 2004-2008 Tiny SPRL (http://tiny.be) All Rights Reserved.
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
+#    $Id$
 #
-# $Id$
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
 #
-# WARNING: This program as such is intended to be used by professional
-# programmers who take the whole responsability of assessing all potential
-# consequences resulting from its eventual inadequacies and bugs
-# End users who are looking for a ready-to-use solution with commercial
-# garantees and support are strongly adviced to contract a Free Software
-# Service Company
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
 #
-# This program is Free Software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-###############################################################################
+##############################################################################
 
 #
 # Object relationnal mapping to postgresql module
@@ -366,7 +359,7 @@ class orm_template(object):
                             view_load=%s, select_level=%s, readonly=%s ,required=%s
                         WHERE
                             model=%s AND name=%s""", (
-                                vals['model_id'], vals['field_description'], vals['ttype'], 
+                                vals['model_id'], vals['field_description'], vals['ttype'],
                                 vals['relation'], bool(vals['view_load']),
                                 vals['select_level'], bool(vals['readonly']),bool(vals['required']), vals['model'], vals['name']
                             ))
@@ -731,7 +724,7 @@ class orm_template(object):
                         if val:
                             val2 = translation_obj._get_source(cr, user,
                                 self._name + ',' + f, 'selection',
-                                context.get('lang', False) or 'en_US', val)                    
+                                context.get('lang', False) or 'en_US', val)
                         sel2.append((key, val2 or val))
                     sel = sel2
                     res[f]['selection'] = sel
@@ -788,12 +781,23 @@ class orm_template(object):
                                 'fields': xfields
                             }
                     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):
+                            attrs['selection'].append((False,''))
                 fields[node.getAttribute('name')] = attrs
 
         elif node.nodeType==node.ELEMENT_NODE and node.localName in ('form', 'tree'):
             result = self.view_header_get(cr, user, False, node.localName, context)
             if result:
                 node.setAttribute('string', result.decode('utf-8'))
+
+        elif node.nodeType==node.ELEMENT_NODE and node.localName == 'calendar':
+            for additional_field in ('date_start', 'date_delay', 'date_stop', 'color'):
+                if node.hasAttribute(additional_field) and node.getAttribute(additional_field):
+                    fields[node.getAttribute(additional_field)] = {}
+
         if node.nodeType == node.ELEMENT_NODE and node.hasAttribute('groups'):
             if node.getAttribute('groups'):
                 groups = node.getAttribute('groups').split(',')
@@ -834,7 +838,7 @@ class orm_template(object):
                     continue
 
                 ok = True
-            
+
                 if user != 1:   # admin user has all roles
                     serv = netsvc.LocalService('object_proxy')
                     user_roles = serv.execute_cr(cr, user, 'res.users', 'read', [user], ['roles_id'])[0]['roles_id']
@@ -894,7 +898,6 @@ class orm_template(object):
             context = {}
         def _inherit_apply(src, inherit):
             def _find(node, node2):
-                # Check if xpath query or normal inherit (with field matching)
                 if node2.nodeType == node2.ELEMENT_NODE and node2.localName == 'xpath':
                     res = xpath.Evaluate(node2.getAttribute('expr'), node)
                     return res and res[0]
@@ -1245,6 +1248,11 @@ class orm_memory(orm_template):
                             field_value2[i][field2] = field_value[i][field2]
                     field_value = field_value2
                 value[field] = field_value
+
+        # get the default values from the context
+        for key in context or {}:
+            if key.startswith('default_'):
+                value[key[8:]] = context[key]
         return value
 
     def search(self, cr, user, args, offset=0, limit=None, order=None,
@@ -1680,6 +1688,9 @@ class orm(orm_template):
                             field_value2[i][field2] = field_value[i][field2]
                     field_value = field_value2
                 value[field] = field_value
+        for key in context or {}:
+            if key.startswith('default_'):
+                value[key[8:]] = context[key]
         return value