2016-06-10 67 views
2

我有一段代碼可以在JavaScript中調用python方法,但代碼無效,並且會顯示一個錯誤.i.e。如何從odoo 9調用python方法javascript

error: Some modules could not be started 
Failed modules: ["group_js.costume"] 
Debug: Object {group_js.costume: Object} 

和我的.py文件是

class group_js(osv.osv): 
    _name = "group_js" 
    _description = "Group JS" 
    _columns={ 
     'js' : fields.text('Javascript',required = True , store=True), 
    } 
@api.multi 
def get_record(self): 
    return [(i.js) for i in self] 

我的js文件是

odoo.define('group_js.costume', function (instance) { 
    new instance.web.Model("group_js").call("get_record",[list_of_record]).then(function(result){ 
    console.log("hiiii"); 
    }); 
}); 

,所以我不知道如何解決這個問題,所以請幫我解決這個錯誤。

感謝

回答

1

撥叫你有odoo蟒蛇模型的方法模型()。在javascript調用()。

例如,想想py文件中的以下模型。

class group_js(models.Model): 
    _name = "model.example" 
    _description = "Example model" 

    def get_record(self): 
     return '' 

而且從JavaScript文件,你可以稱其爲:

new Model("model.example").call("get_record",[args]).then(function(result){ 
    console.log(result);//show in console Hello 
}); 

這裏調用方法的進一步的細節:

/** 
* Call a method (over RPC) on the bound OpenERP model. 
* 
* @param {String} method name of the method to call 
* @param {Array} [args] positional arguments 
* @param {Object} [kwargs] keyword arguments 
* @param {Object} [options] additional options for the rpc() method 
* @returns {jQuery.Deferred<>} call result 
*/