Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
1 Responder
4019 Visualizações

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
Cancelar
Melhor resposta

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
Cancelar
Autor

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

Publicações relacionadas Respostas Visualizações Atividade
1
mai. 21
15452
1
abr. 20
2742
0
mar. 20
1925
1
fev. 20
3625
1
ago. 19
6250