[MERGE] [IMP] ir_actions: server action: the context used to evaluate python code (condition, code server action) is prepared in its own method. This eases the inheritance process and allow s other modules to add new items in the evaluation context. An example of use is to add the request object in the website module, allowing some server action to be accessible through the website front-end.

bzr revid: tde@openerp.com-20140206083938-byoxo7o0uvcmj18d
This commit is contained in:
Thibault Delavallée 2014-02-06 09:39:38 +01:00
commit 6280ba8f10
1 changed files with 24 additions and 17 deletions

View File

@ -910,6 +910,29 @@ class ir_actions_server(osv.osv):
if action.link_new_record and action.link_field_id:
self.pool[action.model_id.model].write(cr, uid, [context.get('active_id')], {action.link_field_id.name: res_id})
def _get_eval_context(self, cr, uid, action, context=None):
""" Prepare the context used when evaluating python code, like the
condition or code server actions.
:param action: the current server action
:type action: browse record
:returns: dict -- evaluation context given to (safe_)eval """
user = self.pool.get('res.users').browse(cr, uid, uid, context=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)
return {
'self': obj_pool,
'object': obj,
'obj': obj,
'pool': self.pool,
'time': time,
'cr': cr,
'uid': uid,
'user': user,
}
def run(self, cr, uid, ids, context=None):
""" Runs the server action. For each server action, the condition is
checked. Note that a void (``False``) condition is considered as always
@ -932,25 +955,9 @@ class ir_actions_server(osv.osv):
if context is None:
context = {}
res = False
user = self.pool.get('res.users').browse(cr, uid, uid)
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': obj,
'obj': obj,
'pool': self.pool,
'time': time,
'cr': cr,
'uid': uid,
'user': user,
}
eval_context = self._get_eval_context(cr, uid, action, context=context)
condition = action.condition
if condition is False:
# Void (aka False) conditions are considered as True