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

Hi,
I want to call a python function from my JavaScript code. This is my code,

rpc.query({
    model: 'my_model',
   method: 'my_method',
   args: ['']
});            

It works perfectly when I'm signed in. But the problem is, the function is not getting called when I'm not signed in. I do want to call the function from the website without signing in. Is there any solutions to achieve this ?


Thanks in advance.

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

try this instead of RPC call

this.trigger_up('button_clicked', {

name: 'my_method',
type: 'object',
record: this.record,
});
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

For example custom model.

class custom(models.Model):

_name = "custom.model"

def get_values(self):

    return 'python method'

From the javascript file you can call like:

new Model("custom.model").call("get_values",[args]).then(function(result){

console.log(result);//show result in console

});


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

Thanks Sushma, but this method works only for odoo 10 and I'm dealing with odoo 11.

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 9 20
3429
0
thg 4 18
2467
0
thg 3 15
5496
1
thg 9 24
2163
2
thg 4 21
26120