Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
3763 Weergaven

I've created a user menu item next to logout button, and that new button contains a JS to call Python code function to redirect to another page. I'm trying to return an act_url to redirect, but its not working :/

I can't redirect directly from JS script because I NEED to call request.session to get the id_token, can't do it from JS.

My JS file:

odoo.define('login_redirect.ComplementMenu', function(require) { 
"use strict";
 var UserMenu = require('web.UserMenu');
 var rpc = require('web.rpc');
 var ComplementMenu = UserMenu.include({
 /** 
 * @private
 */ 
 _onMenuTeste: function () {
 //alert("test");
 rpc.query({
     model: 'logout.test',                
     method: 'raise_key',
     args: [],            
}); 

 },
 });
 return ComplementMenu; });


My python code:

class LogoutConfig(models.Model):
 _name = 'logout.test'

@api.model
def raise_key(self):  

#raise Warning("TESTE")
 url_logout = request.httprequest.url_root + 'web/session/logout' 

 url_test = "***LINK***?id_token_hint={0}" \
 "&post_logout_redirect_uri={1}" .format(str(request.session["id_token"]), url_logout) 

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

The raise warning is working, but that return isn't working :/ I was using that same python function by calling form a server action and it was working, but not from JS script, anyone knows why?


Thanks!

Avatar
Annuleer
Beste antwoord

it's not working because you just call `raise_key` method but didn't handle its return. You have handle the return value of method call and call do action like.

============================

var self = this;
rpc.query({
   model: 'logout.test',
   method: 'raise_key',
   args: [],
}).then(function(action) {
     self.do_action(action);  
})

Avatar
Annuleer
Auteur

It working now, Thanks a lot! Do you know where I can find documentation for those kind of things?

there is official doc https://www.odoo.com/documentation/11.0/reference/javascript_reference.html#overview but batter way of leaning those kinds of thing by reading the codebase

Gerelateerde posts Antwoorden Weergaven Activiteit
1
mei 21
15287
1
apr. 20
2590
0
mrt. 20
1759
1
feb. 20
3503
1
aug. 19
6130