From 517162ce145e78795030cd956e3a0e6e2c8144c3 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Fri, 6 Jun 2014 10:53:42 +0200 Subject: [PATCH] [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. --- openerp/osv/fields.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/openerp/osv/fields.py b/openerp/osv/fields.py index 17e6147f588..529f0563f8d 100644 --- a/openerp/osv/fields.py +++ b/openerp/osv/fields.py @@ -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)