Odoo v12 javascript双rpc调用问题



我已经创建了类crm.dashboard.py有两个方法,我想在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中找不到get_test_info方法。dashboard"。

问题不在于你的JS,而在于"您的";python文件。

可能的错误:

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

最新更新