diff --git a/openerp/addons/base/ir/ir_actions.py b/openerp/addons/base/ir/ir_actions.py index 0810c51c6cf..4451a2589b2 100644 --- a/openerp/addons/base/ir/ir_actions.py +++ b/openerp/addons/base/ir/ir_actions.py @@ -2,7 +2,7 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# Copyright (C) 2004-2011 OpenERP S.A. +# Copyright (C) 2004-2013 OpenERP S.A. # # 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_ - 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