1
votes

I want to disable demo data in sales dashboard in Odoo 9.0. I identified the exact lines in javascript that should be changed to work as I expect. This is original code from 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);
    });
},

All I need to change is, actually, this line:

self.show_demo = result && result['nb_opportunities'] == 0;

as follows

self.show_demo = false;

I tested the code and it works. However, I would like to keep the original Odoo modules untouched so I would like to override the original javascript from within my own module. I tried this:

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;

});

This appears in console after loading the page.

dashboard #1  web.assets_backend.js:4447 
dashboard #2  web.assets_backend.js:4447 
dashboard #6  web.assets_backend.js:4447

It seems that the javascript has been run but the render function has not been overriden. What can I do to override it? Can I check if the function is not overriden later by another module?
Is there something I did wrong? As I am new to JS I am aware I might use javascript anti-patterns. Please feel free to point those out.

1

1 Answers

3
votes

Please try the below code:

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);
        });
    },
    });

});