From 14a6cd841f1fd931cb0d82e1a364cb2aa1b2f0e5 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Mon, 4 Jun 2012 13:45:36 +0200 Subject: [PATCH] [FIX] OPW 575395: orm: don't defer function field computation during creation of parent records (inheritS) An optimization in the set() method of o2m fields disables the direct computation of function fields in order to avoid computing them line-by-line. This is done with context key 'no_store_function', and deferred at the end of the caller write() or create() method. This was unfortunately disabling all function fields in parent model (via _inheritS) at the time of creation, even though those were *not* batch-computed at the end. The patch removes the 'no_store_function' field in the context that is passed to inheritS parents during creation, as it was never meant to be passed. lp bug: https://launchpad.net/bugs/704922 fixed bzr revid: odo@openerp.com-20120604114536-4t6ulwl93zalfgr7 --- openerp/osv/orm.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/openerp/osv/orm.py b/openerp/osv/orm.py index aa81bc65c2b..a4e3aa17365 100644 --- a/openerp/osv/orm.py +++ b/openerp/osv/orm.py @@ -4120,11 +4120,16 @@ class BaseModel(object): del vals[self._inherits[table]] record_id = tocreate[table].pop('id', None) - + + # When linking/creating parent records, force context without 'no_store_function' key that + # defers stored functions computing, as these won't be computed in batch at the end of create(). + parent_context = dict(context) + parent_context.pop('no_store_function', None) + if record_id is None or not record_id: - record_id = self.pool.get(table).create(cr, user, tocreate[table], context=context) + record_id = self.pool.get(table).create(cr, user, tocreate[table], context=parent_context) else: - self.pool.get(table).write(cr, user, [record_id], tocreate[table], context=context) + self.pool.get(table).write(cr, user, [record_id], tocreate[table], context=parent_context) upd0 += ',' + self._inherits[table] upd1 += ',%s'