微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Odoo v12 javascript双rpc调用问题

如何解决Odoo v12 javascript双rpc调用问题

我创建的类 crm.dashboard.py 有 2 个方法,我想在 JS 中调用它们,第一个控制器可以工作,但是当我调用第二个控制器时出现此错误

AttributeError: type object 'crm.dashboard' has no attribute 'get_test_info'  

请问有什么解决办法吗?

init: function(parent,context) {
    this._super(parent,context);
    var crm_data = [];
    var test_data = [];

    var self = this;
    if (context.tag == 'crm_dashboard.dashboard') {
        self._rpc({
            model: 'crm.dashboard',method: 'get_crm_info',},[]).then(function(result){
            self.crm_data = result[0]
        })

        self._rpc({
            model: 'crm.dashboard',method: 'get_test_info',[]).then(function(result){
            self.test_data = result[0]
        })


        .done(function(){
            self.render();
            self.href = window.location.href;
        });


    }
}

方法代码

@api.model
def get_test_info(self):

    expected_revenue = 0
    obj_test = self.env['sale.order'].sudo().search([])
    amount_total = 0
    for sale in obj_test:
        amount_total = round(amount_total + (sale.amount_untaxed + sale.amount_tax))
    test_details = [{}]
    if test_details:
        data = {
            'amount_total': amount_total,}

        test_details[0].update(data)

        print("TEST________________",test_details)
    return test_details

解决方法

消息显示“我在模型 crm.dashboard 中找不到 get_test_info 方法”。

问题不在于您的 JS,而在于“您的”python 文件。

可能的错误:

  • 模型为“crm.dashboard”和方法为“get_test_info”的 python 文件未在 __init__.py 中导入
  • 文件夹模型未导入模块的 __init__.py
  • 缺少依赖(暗示未安装)
  • 方法名称不同。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。