跳至內容
選單
此問題已被標幟
2 回覆
5613 瀏覽次數

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;

});

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
7
12月 23
26164
2
8月 24
6542
1
10月 22
24265
2
9月 21
12965
1
8月 21
8463