[FIX] orm: do not recompute m2o stored function field at read.

The get() method of m2o function fields is used for 2 different things:
 - call the function defining the m2o
 - get the name_get representation of the value

Until this pathc, only the first case was handled, resulting to a useless
recomputation of the field when reading it.
This commit is contained in:
Christophe Simonis 2014-06-06 10:53:42 +02:00
parent 306d5c89a0
commit 517162ce14
1 changed files with 10 additions and 2 deletions

View File

@ -1142,9 +1142,17 @@ class function(_column):
return result
def get(self, cr, obj, ids, name, uid=False, context=None, values=None):
result = self._fnct(obj, cr, uid, ids, name, self._arg, context)
multi = self._multi
# if we already have a value, don't recompute it.
# This happen if case of stored many2one fields
if values and not multi and name in values[0]:
result = {v['id']: v[name] for v in values}
elif values and multi and all(n in values[0] for n in name):
result = {v['id']: dict({n: v[n]} for n in name) for v in values}
else:
result = self._fnct(obj, cr, uid, ids, name, self._arg, context)
for id in ids:
if self._multi and id in result:
if multi and id in result:
for field, value in result[id].iteritems():
if value:
result[id][field] = self.postprocess(cr, uid, obj, field, value, context)