From 29b9fd5f25f53e5ea03994de483fff8c7b75b50d Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Wed, 25 Nov 2009 15:30:58 +0100 Subject: [PATCH] [IMP] _defaults: allow to pass directly the value instead of a lambda bzr revid: chs@tinyerp.com-20091125143058-upa8zaz6gwo27685 --- bin/osv/orm.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/bin/osv/orm.py b/bin/osv/orm.py index e417d6371c7..04d493ce95e 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -1596,7 +1596,11 @@ class orm_memory(orm_template): # get the default values for the inherited fields for f in fields_list: if f in self._defaults: - value[f] = self._defaults[f](self, cr, uid, context) + if callable(self._defaults[f]): + value[f] = self._defaults[f](self, cr, uid, context) + else: + value[f] = self._defaults[f] + fld_def = ((f in self._columns) and self._columns[f]) \ or ((f in self._inherit_fields) and self._inherit_fields[f][2]) \ or False @@ -1897,7 +1901,11 @@ class orm(orm_template): # initialize it if not create and k in self._defaults: - default = self._defaults[k](self, cr, 1, {}) + if callable(self._defaults[k]): + default = self._defaults[k](self, cr, 1, context) + else: + default = self._defaults[k] + ss = self._columns[k]._symbol_set query = 'UPDATE "%s" SET "%s"=%s' % (self._table, k, ss[0]) cr.execute(query, (ss[1](default),)) @@ -1983,7 +1991,11 @@ class orm(orm_template): if f.required and f_pg_notnull == 0: # set the field to the default value if any if k in self._defaults: - default = self._defaults[k](self, cr, 1, {}) + if callable(self._defaults[k]): + default = self._defaults[k](self, cr, 1, context) + else: + default = self._defaults[k] + if (default is not None): ss = self._columns[k]._symbol_set query = 'UPDATE "%s" SET "%s"=%s WHERE "%s" is NULL' % (self._table, k, ss[0], k) @@ -2164,7 +2176,11 @@ class orm(orm_template): # get the default values defined in the object for f in fields_list: if f in self._defaults: - value[f] = self._defaults[f](self, cr, uid, context) + if callable(self._defaults[f]): + value[f] = self._defaults[f](self, cr, uid, context) + else: + value[f] = self._defaults[f] + fld_def = ((f in self._columns) and self._columns[f]) \ or ((f in self._inherit_fields) and self._inherit_fields[f][2]) \ or False @@ -3130,7 +3146,11 @@ class orm(orm_template): default = {} if 'state' not in default: if 'state' in self._defaults: - default['state'] = self._defaults['state'](self, cr, uid, context) + if callable(self._defaults['state']): + default['state'] = self._defaults['state'](self, cr, uid, context) + else: + default['state'] = self._defaults['state'] + data = self.read(cr, uid, [id], context=context)[0] fields = self.fields_get(cr, uid, context=context) trans_data=[]