Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
4432 Lượt xem

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!

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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);  
})

Ảnh đại diện
Huỷ bỏ
Tác giả

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 5 21
15778
1
thg 4 20
3095
0
thg 3 20
2248
1
thg 2 20
3964
1
thg 8 19
6485