تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
5666 أدوات العرض

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
ديسمبر 23
26218
2
أغسطس 24
6622
1
أكتوبر 22
24307
2
سبتمبر 21
13020
1
أغسطس 21
8510