我想在Odoo 9.0的销售仪表板中禁用演示数据。我确定了javascript中的确切行,应该按照我的预期进行更改。 这是sales_team /(...)/ sales_team_dashboard.js的原始代码
render: function() {
var super_render = this._super;
var self = this;
return this.fetch_data().then(function(result){
self.show_demo = result && result['nb_opportunities'] == 0;
var sales_dashboard = QWeb.render('sales_team.SalesDashboard',{
widget: self,
show_demo: self.show_demo,
values: result,
});
super_render.call(self);
$(sales_dashboard).prependTo(self.$el);
});
},
实际上,我需要改变的是这一行:
self.show_demo = result && result['nb_opportunities'] == 0;
如下
self.show_demo = false;
我测试了代码并且它有效。但是,我想保持原来的Odoo模块不变,所以我想从我自己的模块中覆盖原始的javascript。 我试过这个:
odoo.define('my_module.dashboard', function(require) {
"use strict";
console.log('dashboard #1');
var dashboard = require('sales_team.dashboard');
console.log('dashboard #2');
var SalesTeamDashboardView = dashboard.extend({
template: 'sales_team.SalesDashboard',
render: function() {
console.log('dashboard #3');
var super_render = this._super;
var self = this;
return this.fetch_data().then(function(result){
console.log('dashboard #4');
self.show_demo = false;
var sales_dashboard = QWeb.render(template, {
widget: self,
show_demo: self.show_demo,
values: result,
});
super_render.call(self);
console.log('dashboard #5');
$(sales_dashboard).prependTo(self.$el);
});
},
});
console.log('dashboard #6');
//core.view_registry.add('sales_team_dashboard', SalesTeamDashboardView);
return SalesTeamDashboardView;
});
加载页面后会出现在控制台中。
dashboard #1 web.assets_backend.js:4447
dashboard #2 web.assets_backend.js:4447
dashboard #6 web.assets_backend.js:4447
似乎javascript已经运行但渲染功能尚未被覆盖。我该怎么做才能覆盖它?我可以检查以后另一个模块是否没有覆盖该功能吗? 有什么我做错了吗?由于我是JS的新手,我知道我可能会使用javascript反模式。请随意指出这些。
答案 0 :(得分:2)
请尝试以下代码:
odoo.define('my_module.dashboard', function(require) {
"use strict";
console.log('dashboard #1');
var dashboard = require('sales_team.dashboard');
console.log('dashboard #2');
var SalesTeamDashboardView = dashboard.include({
render: function() {
console.log('dashboard #3');
var super_render = this._super;
var self = this;
return this.fetch_data().then(function(result){
console.log('dashboard #4');
self.show_demo = false;
var sales_dashboard = QWeb.render(template, {
widget: self,
show_demo: self.show_demo,
values: result,
});
super_render.call(self);
console.log('dashboard #5');
$(sales_dashboard).prependTo(self.$el);
});
},
});
});