[FIX] ir.actions.server: active record (active_id) always put in the evaluation context
authorChristophe Simonis <chs@openerp.com>
Tue, 12 Nov 2013 18:04:23 +0000 (19:04 +0100)
committerChristophe Simonis <chs@openerp.com>
Tue, 12 Nov 2013 18:04:23 +0000 (19:04 +0100)
bzr revid: chs@openerp.com-20131112180423-ce3enlyk6y3jjphh

openerp/addons/base/ir/ir_actions.py

index 0810c51..4451a25 100644 (file)
@@ -2,7 +2,7 @@
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution
-#    Copyright (C) 2004-2011 OpenERP S.A. <http://www.openerp.com>
+#    Copyright (C) 2004-2013 OpenERP S.A. <http://www.openerp.com>
 #
 #    This program is free software: you can redistribute it and/or modify
 #    it under the terms of the GNU Affero General Public License as
@@ -994,14 +994,18 @@ class actions_server(osv.osv):
             context = {}
         res = False
         user = self.pool.get('res.users').browse(cr, uid, uid)
-        active_ids = context.get('active_ids', [context.get('active_id', None)])
+        active_ids = context.get('active_ids', [context.get('active_id')])
         for action in self.browse(cr, uid, ids, context):
             obj_pool = self.pool[action.model_id.model]
+            obj = None
+            if context.get('active_model') == action.model_id.model and context.get('active_id'):
+                obj = obj_pool.browse(cr, uid, context['active_id'], context=context)
+
             # evaluation context for python strings to evaluate
             eval_context = {
                 'self': obj_pool,
-                'object': None,
-                'obj': None,
+                'object': obj,
+                'obj': obj,
                 'pool': self.pool,
                 'time': time,
                 'cr': cr,
@@ -1010,31 +1014,30 @@ class actions_server(osv.osv):
             }
             condition = action.condition
             if condition is False:
+                # Void (aka False) conditions are considered as True
                 condition = True
             if hasattr(self, 'run_action_%s_multi' % action.state):
                 # set active_ids in context only needed if one active_id
                 run_context = dict(context, active_ids=active_ids)
-                eval_context["context"] = run_context                
+                eval_context["context"] = run_context
                 expr = eval(str(condition), eval_context)
                 if not expr:
                     continue
                 # call the multi method
-                res = getattr(self, 'run_action_%s_multi' % action.state)(cr, uid, action, eval_context=eval_context, context=run_context)
+                func = getattr(self, 'run_action_%s_multi' % action.state)
+                res = func(cr, uid, action, eval_context=eval_context, context=run_context)
+
             elif hasattr(self, 'run_action_%s' % action.state):
+                func = getattr(self, 'run_action_%s' % action.state)
                 for active_id in active_ids:
-                    if context.get('active_model') == action.model_id.model and active_id:
-                        obj = obj_pool.browse(cr, uid, context['active_id'], context=context)
-                        eval_context['obj'] = obj
-                        eval_context['object'] = obj
                     # run context dedicated to a particular active_id
                     run_context = dict(context, active_ids=[active_id], active_id=active_id)
                     eval_context["context"] = run_context
-                    # evaluate the condition, with the specific case that a void (aka False) condition is considered as True
                     expr = eval(str(condition), eval_context)
                     if not expr:
                         continue
                     # call the single method related to the action: run_action_<STATE>
-                    res = getattr(self, 'run_action_%s' % action.state)(cr, uid, action, eval_context=eval_context, context=run_context)
+                    res = func(cr, uid, action, eval_context=eval_context, context=run_context)
         return res