[FIX] models: improve rationale for the management of flag 'recompute' in context
authorRaphael Collet <rco@openerp.com>
Mon, 18 Aug 2014 09:53:13 +0000 (11:53 +0200)
committerRaphael Collet <rco@openerp.com>
Tue, 19 Aug 2014 09:50:42 +0000 (11:50 +0200)
When the context contains 'recompute': False, the recomputation was not even
prepared. Now both create() and write() prepare the recomputation by invoking
method modified(). The flag only controls whether method recompute() is invoked.
In addintion, the former flag 'no_store_function' was converted to the flag
'recompute', so that both create() and write() use the same flag.

Fixes #1456

addons/account/account_move_line.py
addons/project_timesheet/project_timesheet.py
openerp/models.py
openerp/osv/fields.py

index c513261..642c209 100644 (file)
@@ -1297,7 +1297,7 @@ class account_move_line(osv.osv):
                     self.create(cr, uid, data, context)
             del vals['account_tax_id']
 
-        if check and not context.get('novalidate') and ((not context.get('no_store_function')) or journal.entry_posted):
+        if check and not context.get('novalidate') and (context.get('recompute', True) or journal.entry_posted):
             tmp = move_obj.validate(cr, uid, [vals['move_id']], context)
             if journal.entry_posted and tmp:
                 move_obj.button_validate(cr,uid, [vals['move_id']], context)
index 692249b..cfce80c 100644 (file)
@@ -137,7 +137,7 @@ class project_work(osv.osv):
                 amount = vals_line['unit_amount']
                 prod_id = vals_line['product_id']
                 unit = False
-                context = dict(context, no_store_function=False)
+                context = dict(context, recompute=True)
                 timeline_id = timesheet_obj.create(cr, uid, vals_line, context=context)
 
                 # Compute based on pricetype
index b292846..618303a 100644 (file)
@@ -3972,15 +3972,10 @@ class BaseModel(object):
 
             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[table].create(cr, user, tocreate[table], context=parent_context)
+                record_id = self.pool[table].create(cr, user, tocreate[table], context=context)
             else:
-                self.pool[table].write(cr, user, [record_id], tocreate[table], context=parent_context)
+                self.pool[table].write(cr, user, [record_id], tocreate[table], context=context)
 
             updates.append((self._inherits[table], '%s', record_id))
 
@@ -4105,13 +4100,13 @@ class BaseModel(object):
         # check Python constraints
         recs._validate_fields(vals)
 
-        # Mark new-style fields to recompute
+        # invalidate and mark new-style fields to recompute
         modified_fields = list(vals)
         if self._log_access:
             modified_fields += ['create_uid', 'create_date', 'write_uid', 'write_date']
         recs.modified(modified_fields)
 
-        if not context.get('no_store_function', False):
+        if context.get('recompute', True):
             result += self._store_get_values(cr, user, [id_new],
                 list(set(vals.keys() + self._inherits.values())),
                 context)
@@ -4124,7 +4119,7 @@ class BaseModel(object):
             # recompute new-style fields
             recs.recompute()
 
-        if self._log_create and not (context and context.get('no_store_function', False)):
+        if self._log_create and context.get('recompute', True):
             message = self._description + \
                 " '" + \
                 self.name_get(cr, user, [id_new], context=context)[0][1] + \
@@ -4269,7 +4264,7 @@ class BaseModel(object):
                         cr.execute('update "' + self._table + '" set ' + \
                             '"'+f+'"='+self._columns[f]._symbol_set[0] + ' where id = %s', (self._columns[f]._symbol_set[1](value), id))
 
-        # invalidate the cache for the modified fields
+        # invalidate and mark new-style fields to recompute
         self.browse(cr, uid, ids, context).modified(fields)
 
         return True
index 2126fff..5bac088 100644 (file)
@@ -684,7 +684,7 @@ class one2many(_column):
         result = []
         context = dict(context or {})
         context.update(self._context)
-        context['no_store_function'] = True
+        context['recompute'] = False    # recomputation is done by outer create/write
         if not values:
             return
         obj = obj.pool[self._obj]