Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
14757 มุมมอง

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.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

try this instead of RPC call

this.trigger_up('button_clicked', {

name: 'my_method',
type: 'object',
record: this.record,
});
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

});


อวตาร
ละทิ้ง
ผู้เขียน

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

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ก.ย. 20
3419
0
เม.ย. 18
2467
0
มี.ค. 15
5490
1
ก.ย. 24
2162
How to get model records in javascript แก้ไขแล้ว
2
เม.ย. 21
26117