Before this revision, when you pass `context` in the arguments of a JSON routes, this one gets automatically injected in the environment context. This is not the case for regular HTTP routes. It makes sense to propagate the context for the JSONRPC protocol, JSON routes used by the backend, such as `call_kw`, but it doesn't make sense to pass this context automatically for any other kind of routes, such as front-end routes or routes used by custom Javascript widgets. This change brings a more unified behavior for routes of types HTTP and JSON. In addition, most developers were not aware of this "feautre", that passing `context` in the arguments of a JSON route leaded to the injection of this context in the environment context. This is actually reflected by the diff size this changes required, only a dozens of routes needed to be adapted, to manually add the context in their route arguments and to inject it in their environment context. closes odoo/odoo#121726 X-original-commit: a7a5655631e6d5b05fd2ba3d0c80617aae6d9cfe Related: odoo/enterprise#41229 Signed-off-by: Denis Ledoux (dle) <dle@odoo.com>
48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
import logging
|
|
from odoo import _
|
|
from odoo.exceptions import MissingError
|
|
from odoo.http import Controller, request, route
|
|
from .utils import clean_action
|
|
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
class Action(Controller):
|
|
|
|
@route('/web/action/load', type='json', auth="user")
|
|
def load(self, action_id, additional_context=None):
|
|
Actions = request.env['ir.actions.actions']
|
|
value = False
|
|
try:
|
|
action_id = int(action_id)
|
|
except ValueError:
|
|
try:
|
|
action = request.env.ref(action_id)
|
|
assert action._name.startswith('ir.actions.')
|
|
action_id = action.id
|
|
except Exception as exc:
|
|
raise MissingError(_("The action %r does not exist.", action_id)) from exc
|
|
|
|
base_action = Actions.browse([action_id]).sudo().read(['type'])
|
|
if base_action:
|
|
action_type = base_action[0]['type']
|
|
if action_type == 'ir.actions.report':
|
|
request.update_context(bin_size=True)
|
|
if additional_context:
|
|
request.update_context(**additional_context)
|
|
action = request.env[action_type].sudo().browse([action_id]).read()
|
|
if action:
|
|
value = clean_action(action[0], env=request.env)
|
|
return value
|
|
|
|
@route('/web/action/run', type='json', auth="user")
|
|
def run(self, action_id, context=None):
|
|
if context:
|
|
request.update_context(**context)
|
|
action = request.env['ir.actions.server'].browse([action_id])
|
|
result = action.run()
|
|
return clean_action(result, env=action.env) if result else False
|