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

I need to call python file from JS. I am using model calling function but whenever It will call it returns false due to synchronous and asynchronous concept. Ex-

get_sale_total_price: function(id){

    var sale_total_price = false;

    Model.call('get_sale_total_price', [id]).then(function(callback) {

        if (callback){

            sale_total_price = callback.price;

        }

    }

    return sale_total_price;

}

Is there any ways to fix without set-interval function?

อวตาร
ละทิ้ง

code inside model.call executes after all lines in your function executes.

คำตอบที่ดีที่สุด

You Have to Use deferred and resolve

or Try This :

rpc.query({

    model: 'your.model',       // python model name

    method: 'get_sale_total_price',      // python method name

    args: [args],      // args

}).then(function (result) {
    sale_total_price = result;

});

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
7
ธ.ค. 23
26281
2
ส.ค. 24
6660
1
ต.ค. 22
24370
2
ก.ย. 21
13072
1
ส.ค. 21
8566