简体   繁体   English

如何从odoo 9 javascript调用python方法

[英]how to call python method from odoo 9 javascript

I have a piece of code to call the python method in javascript , but the code did not work , and an error will be show .ie 我有一段代码在javascript中调用python方法,但代码不起作用,将显示错误.ie

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

and my .py file is 我的.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]

my .js file is 我的.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");
   });
});

so i have no idea how to fix that , so please help me for fix this error . 所以我不知道如何解决这个问题,所以请帮我解决这个错误。

Thanks 谢谢

To call a method from the odoo python model you have Model().call() in javascript. 要从odoo python模型调用一个方法,你可以在javascript中使用Model()。call()。

For example think of following model in py file. 例如,考虑py文件中的以下模型。

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

   def get_record(self):
       return ''

And from the javascript file you can call it as: 从javascript文件中,您可以将其命名为:

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

Here the further details of call method: 这里是调用方法的更多细节:

/**
 * 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
 */

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM