Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Odoo - Custom template menu load

Tags:

python

odoo

Currently I am working on the odoo module, which needs to have its own (custom made and designed) dashboard. So this dashboard will be visible only when user login to the backend (where he is able to mange apps, settings and similar things).

Seems like only possible way to do this is to create a separate controller, render specific template implemented for that controller/dashboard, and tie that with the menu button.

That's all fine, but when we render template, it is blank. I would like to load standard backend menu for this template - and the just work on the template body.

Is there any view I can inherit, or any way which I can use, where I can create a template which will load top menu bar automatically for that template?


I tried to inherit "web.webclient_bootstrap" template, and to append things within the main div of this template, but its not working. Seems that, when you are inhering this template, session_info is empty?

like image 468
cool Avatar asked Dec 11 '18 03:12

cool


1 Answers

After research of odoo source code - discussions with people which are more involved into odoo development - and in general - working more with odoo - i found the way how to do this.

Initially question have a wrong assumption - that this is possible to do by rendering using the controller. What is important to understand is that - odoo backend is rendered as "single js page", and any kind of customization on the dashboard side (which are not provided by default by odoo which you can define in views) - needs to be done by creating js widgets and altering dom objects directly with javascript.

Solution bellow represents a action/page on the dashboard side - which will render blank page with only "Test" word on it.

odoo.define("mymodule.customdashboard", function (require) {
    "use strict";

    var core = require("web.core");
    var AbstractAction = require("web.AbstractAction");
    var Widget = require("web.Widget");

    var qweb = core.qweb;
    var _t = core._t;

    require("web.dom_ready");

    var CustomDashboard = AbstractAction.extend({
        template: "custom_dashboard",
        events: {
        },

        init: function(parent, action){
            this._super.apply(this, arguments);
            var options = action.params || {};
            this.params = options;
        },

        start: function(){
            this.$(".dashboard-wrapper").append(qweb.render("campaign_dashboard_campaign_list", {"someArgData": "Test"}));
        }
    });

    core.action_registry.add("custom.dashboard", CustomDashboard);

    return {
        CustomDashboard: CustomDashboard
    }
});

Where campaign_dashboard_campaign_list is name of the template WHICH is going to be invoked AND with parameter, inserted with all of the html data into the dom element which contains class .dashboard-wrapper (which exists in another template called custom_dashboard defined at the top of the class.

like image 58
cool Avatar answered Oct 18 '22 08:10

cool