如何在odoo 11中的jQuery中调用python函数 [英] How to call python function in jquery in odoo 11

查看:471
本文介绍了如何在odoo 11中的jQuery中调用python函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python代码:

@api.model
def test_method(self):
    a= 10
    b = 20
    c = a+b
    return c

jQuery:

var Model = require('web.Model');
$(document).ready(function() {
  var test_model = new Model("MyClass");
  test_model.call("test_method").then(function(c) {
    console.log("res ult:" + JSON.stringify(result));
  });
});

错误:

缺少取决于,

Missing depends,

以上代码将在odoo 10中运行,但在oodo 11中不运行.我想知道如何从JS调用python函数.

The above code will is working in odoo 10 but not in odoo 11. I want to know how to call a python function from JS.

推荐答案

在Odoo 11中,您需要使用

in Odoo 11 you need to use

var rpc = require('web.rpc');

代替

var Model = require('web.Model');

然后使用.query()方法调用一个方法,如下所示:

And later call a method using .query() method as below:

rpc.query({
            model: 'model.name',
            method: 'method_name',
            args: [{
                'arg1': value1,
                'arg2': value2,
            }]
        }).then(function (returned_value) { // do something }

这篇关于如何在odoo 11中的jQuery中调用python函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆