Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
5545 Widoki

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?

Awatar
Odrzuć

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

Najlepsza odpowiedź

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;

});

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
7
gru 23
26032
2
sie 24
6379
1
paź 22
24123
2
wrz 21
12809
1
sie 21
8350