[FIX] base: add env to ir_action and ir_ui_view qweb context
To impel new api usage in server actions and qweb templates.
This commit is contained in:
parent
457b940c0e
commit
06c681ba11
|
@ -577,16 +577,14 @@ class ir_actions_server(osv.osv):
|
||||||
'condition': 'True',
|
'condition': 'True',
|
||||||
'type': 'ir.actions.server',
|
'type': 'ir.actions.server',
|
||||||
'sequence': 5,
|
'sequence': 5,
|
||||||
'code': """# You can use the following variables:
|
'code': """# Available locals:
|
||||||
# - self: ORM model of the record on which the action is triggered
|
# - time, datetime, dateutil: Python libraries
|
||||||
|
# - env: Odoo Environement
|
||||||
|
# - model: Model of the record on which the action is triggered
|
||||||
# - object: Record on which the action is triggered if there is one, otherwise None
|
# - object: Record on which the action is triggered if there is one, otherwise None
|
||||||
# - pool: ORM model pool (i.e. self.pool)
|
|
||||||
# - cr: database cursor
|
|
||||||
# - uid: current user id
|
|
||||||
# - context: current context
|
|
||||||
# - time: Python time module
|
|
||||||
# - workflow: Workflow engine
|
# - workflow: Workflow engine
|
||||||
# If you plan to return an action, assign: action = {...}""",
|
# - Warning: Warning Exception to use with raise
|
||||||
|
# To return an action, assign: action = {...}""",
|
||||||
'use_relational_model': 'base',
|
'use_relational_model': 'base',
|
||||||
'use_create': 'new',
|
'use_create': 'new',
|
||||||
'use_write': 'current',
|
'use_write': 'current',
|
||||||
|
@ -947,25 +945,35 @@ class ir_actions_server(osv.osv):
|
||||||
:param action: the current server action
|
:param action: the current server action
|
||||||
:type action: browse record
|
:type action: browse record
|
||||||
:returns: dict -- evaluation context given to (safe_)eval """
|
: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_pool = self.pool[action.model_id.model]
|
||||||
|
env = openerp.api.Environment(cr, uid, context)
|
||||||
|
model = env[action.model_id.model]
|
||||||
obj = None
|
obj = None
|
||||||
if context.get('active_model') == action.model_id.model and context.get('active_id'):
|
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)
|
obj = model.browse(context['active_id'])
|
||||||
return {
|
return {
|
||||||
'self': obj_pool,
|
# python libs
|
||||||
'object': obj,
|
|
||||||
'obj': obj,
|
|
||||||
'pool': self.pool,
|
|
||||||
'time': time,
|
'time': time,
|
||||||
'datetime': datetime,
|
'datetime': datetime,
|
||||||
'dateutil': dateutil,
|
'dateutil': dateutil,
|
||||||
|
# orm
|
||||||
|
'env': env,
|
||||||
|
'model': model,
|
||||||
|
'workflow': workflow,
|
||||||
|
# Exceptions
|
||||||
|
'Warning': openerp.exceptions.Warning,
|
||||||
|
# record
|
||||||
|
# TODO: When porting to master move badly named obj and object to
|
||||||
|
# deprecated and define record (active_id) and records (active_ids)
|
||||||
|
'object': obj,
|
||||||
|
'obj': obj,
|
||||||
|
# Deprecated use env or model instead
|
||||||
|
'self': obj_pool,
|
||||||
|
'pool': self.pool,
|
||||||
'cr': cr,
|
'cr': cr,
|
||||||
'uid': uid,
|
'uid': uid,
|
||||||
'user': user,
|
|
||||||
'context': context,
|
'context': context,
|
||||||
'workflow': workflow,
|
'user': env.user,
|
||||||
'Warning': openerp.exceptions.Warning,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def run(self, cr, uid, ids, context=None):
|
def run(self, cr, uid, ids, context=None):
|
||||||
|
|
|
@ -987,6 +987,7 @@ class view(osv.osv):
|
||||||
if values is None:
|
if values is None:
|
||||||
values = dict()
|
values = dict()
|
||||||
qcontext = dict(
|
qcontext = dict(
|
||||||
|
env=api.Environment(cr, uid, context),
|
||||||
keep_query=keep_query,
|
keep_query=keep_query,
|
||||||
request=request, # might be unbound if we're not in an httprequest context
|
request=request, # might be unbound if we're not in an httprequest context
|
||||||
debug=request.debug if request else False,
|
debug=request.debug if request else False,
|
||||||
|
|
Loading…
Reference in New Issue