[FIX]base, ir_actions: ir_values with client_multi_actions and a server action with...
authorDenis Ledoux <dle@openerp.com>
Tue, 12 Nov 2013 16:27:26 +0000 (17:27 +0100)
committerDenis Ledoux <dle@openerp.com>
Tue, 12 Nov 2013 16:27:26 +0000 (17:27 +0100)
bzr revid: dle@openerp.com-20131112162726-24z38xvzq5o1spoe

openerp/addons/base/ir/ir_actions.py

index e13602d..0810c51 100644 (file)
@@ -862,7 +862,7 @@ class actions_server(osv.osv):
             raise osv.except_osv(_('Error'), _("Please specify an action to launch!"))
         return self.pool[action.action_id.type].read(cr, uid, action.action_id.id, context=context)
 
-    def run_action_code(self, cr, uid, action, eval_context=None, context=None):
+    def run_action_code_multi(self, cr, uid, action, eval_context=None, context=None):
         eval(action.code.strip(), eval_context, mode="exec", nocopy=True)  # nocopy allows to return 'action'
         if 'action' in eval_context:
             return eval_context['action']
@@ -996,35 +996,44 @@ class actions_server(osv.osv):
         user = self.pool.get('res.users').browse(cr, uid, uid)
         active_ids = context.get('active_ids', [context.get('active_id', None)])
         for action in self.browse(cr, uid, ids, context):
-            obj = None
             obj_pool = self.pool[action.model_id.model]
-            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)
-                # run context dedicated to a particular active_id
-                run_context = dict(context, active_ids=[active_id], active_id=active_id)
-                # evaluation context for python strings to evaluate
-                eval_context = {
-                    'self': obj_pool,
-                    'object': obj,
-                    'obj': obj,
-                    'pool': self.pool,
-                    'time': time,
-                    'cr': cr,
-                    'context': dict(run_context),  # copy context to prevent side-effects of eval
-                    'uid': uid,
-                    'user': user
-                }
-
-                # evaluate the condition, with the specific case that a void (aka False) condition is considered as True
-                condition = action.condition
-                if action.condition is False:
-                    condition = True
+            # evaluation context for python strings to evaluate
+            eval_context = {
+                'self': obj_pool,
+                'object': None,
+                'obj': None,
+                'pool': self.pool,
+                'time': time,
+                'cr': cr,
+                'uid': uid,
+                'user': user,
+            }
+            condition = action.condition
+            if condition is False:
+                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                
                 expr = eval(str(condition), eval_context)
                 if not expr:
                     continue
-                # call the method related to the action: run_action_<STATE>
-                if hasattr(self, 'run_action_%s' % action.state):
+                # call the multi method
+                res = getattr(self, 'run_action_%s_multi' % action.state)(cr, uid, action, eval_context=eval_context, context=run_context)
+            elif hasattr(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)
         return res