Skip to Content
Menu
This question has been flagged
2 Replies
3272 Views

Hello! I hope this post finds you well! I have a model and I'm trying to remove the control panel for the view. I have tried adding a JavaScript like this:


odoo.define('hotel_reservation.QuickRemoveStuff', function (require) {
"use strict";

console.log("well it logs..");

var FormView = require('web.FormView');
var FormRenderer = require('web.FormRenderer');

FormRenderer.include({
render: function () {
if (!this.withControlPanel) {
this.$('.o_form_buttons').addClass('d-none');
}
return this._super.apply(this, arguments);
},
});

var QuickRemoveStuff = FormView.extend({
});

QuickRemoveStuff.prototype.withControlPanel = false;

return {
QuickRemoveStuff: QuickRemoveStuff,
};
});



Now it loads and logs without erros but the control panel still remains.
I also added `renderer="QuickRemoveStuff"` this in xml.

Can someone please give some help on how to seccsfully remove this?

Avatar
Discard
Best Answer

Hi,


We can alter Odoo's control panel using the patching method. For this, use the following code:

/** @odoo-module */


import { ControlPanel } from "@web/search/control_panel/control_panel";

import { patch } from "@web/core/utils/patch";

import { useRef, onPatched, onMounted, useState } from "@odoo/owl";


patch(ControlPanel.prototype,{

    setup() {

        super.setup();

        onMounted(() => {

            #You can set any condition that you wish to remove the control panel at any time or from any place.

            if (this.env.searchModel == 'your.model') {

                this.root.el.style.setProperty("display", "none", "important");

            }

        });

    },

});


Hope this helps.

Avatar
Discard
Best Answer

try this way
odoo.define('hotel_reservation.QuickRemoveStuff', function (require) {
"use strict";

var FormRenderer = require('web.FormRenderer');

FormRenderer.include({
renderButtons: function () {
if (!this.withControlPanel) {
this.$('.o_form_buttons').hide();
}
return this._super.apply(this, arguments);
},
});

return {
withControlPanel: false,
};
});
Step 2: Add the JavaScript file to Odoo assets Make sure the JavaScript file is placed in the appropriate location within your Odoo module (e.g., hotel_reservation/static/src/js/quick_remove_stuff.js).

Step 3: Include the JavaScript file in your XML view In your XML view, add the following line to include the JavaScript file:
template id="assets_backend" name="hotel_reservation assets" inherit_id="web.assets_backend">
xpath expr="." position="inside">
script type="text/javascript" src="/hotel_reservation/static/src/js/quick_remove_stuff.js">
/xpath>
/template>

Make sure to adjust the path to the JavaScript file according to your module's structure.

Step 4: Apply the renderer in your XML view In your XML view, specify the custom renderer by adding renderer="QuickRemoveStuff" to the appropriate view element, such as

or

form string="Your Form" renderer="QuickRemoveStuff">
!-- Your form fields -->
/form>

Step 5: Update the module After making these changes, update your Odoo module to reflect the modifications. You can restart Odoo or use the Odoo developer mode to update the module.
Avatar
Discard
Author

Thank you for your response! I did what you said, and the control panel is still there. I will take a look later again but I'm afraid it will be the same.

Related Posts Replies Views Activity
0
Jul 17
2820
0
Mar 15
6399
1
Feb 24
2039
0
Nov 23
1831
1
May 20
11855