This question has been flagged
1 Reply
8717 Views

I am using odoo community v13. I want user to redirect to '/abc' url of website after json method's execution. How to do that?
Thanks in advance.

I did like this:
ex:

@http.route(['/my/jsonurl/'], type='json',auth='public')

def redierct_url(self, **kw):
    // my code

    return request.redirect('/abc')


Avatar
Discard
Best Answer

Depending on your usecase, you may be able to write/extend the JavaScript Code. During my research I did not find a built-in way to perform redirects with the website frontend Odoo JSON API (using JavaScript _rpc requests). Finally, I used a similar approach as you can see in 

\https://github.com/odoo/odoo/blob/14.0/addons/portal/static/src/js/portal_signature.js#L128

this._rpc({
...
}).then(function(data) {
if (data.force_refresh) {
if (data.redirect_url) {
window.location = data.redirect_url;
} else {
\window.location.reload();
}
// to avoid triggering chained .then callbacks
return Promise.reject();
}
...
})

where the route returns a dict à la 

return {
'force_refresh': True,
'redirect_url': ...,
)

For the sake of completeness: in the admin backend there is a build-in way, return a URL action

return {
'type': 'ir.actions.act_url',
'url': url,
'target': 'self',
}

Avatar
Discard