Skip to content

Commit

Permalink
[FIX] base: add env to ir_action and ir_ui_view qweb context
Browse files Browse the repository at this point in the history
To impel new api usage in server actions and qweb templates.
  • Loading branch information
antonylesuisse committed Jan 28, 2015
1 parent 457b940 commit 06c681b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
42 changes: 25 additions & 17 deletions openerp/addons/base/ir/ir_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,16 +577,14 @@ def _get_states_wrapper(self, cr, uid, context=None):
'condition': 'True',
'type': 'ir.actions.server',
'sequence': 5,
'code': """# You can use the following variables:
# - self: ORM model of the record on which the action is triggered
'code': """# Available locals:
# - 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
# - 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
# 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_create': 'new',
'use_write': 'current',
Expand Down Expand Up @@ -947,25 +945,35 @@ def _get_eval_context(self, cr, uid, action, context=None):
: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]
env = openerp.api.Environment(cr, uid, context)
model = env[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)
obj = model.browse(context['active_id'])
return {
'self': obj_pool,
'object': obj,
'obj': obj,
'pool': self.pool,
# python libs
'time': time,
'datetime': datetime,
'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,
'uid': uid,
'user': user,
'context': context,
'workflow': workflow,
'Warning': openerp.exceptions.Warning,
'user': env.user,
}

def run(self, cr, uid, ids, context=None):
Expand Down
1 change: 1 addition & 0 deletions openerp/addons/base/ir/ir_ui_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,7 @@ def render(self, cr, uid, id_or_xml_id, values=None, engine='ir.qweb', context=N
if values is None:
values = dict()
qcontext = dict(
env=api.Environment(cr, uid, context),
keep_query=keep_query,
request=request, # might be unbound if we're not in an httprequest context
debug=request.debug if request else False,
Expand Down

0 comments on commit 06c681b

Please sign in to comment.