Skip to Content
Menu
This question has been flagged
2 Replies
5690 Rodiniai

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?

Portretas
Atmesti

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

Best Answer

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;

});

Portretas
Atmesti
Related Posts Replies Rodiniai Veikla
7
gruod. 23
26252
2
rugp. 24
6644
1
spal. 22
24343
2
rugs. 21
13043
1
rugp. 21
8546