Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
3332 Visualizzazioni

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
Abbandona
Risposta migliore

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
Abbandona
Risposta migliore

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
Abbandona
Autore

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.

Post correlati Risposte Visualizzazioni Attività
0
lug 17
2880
0
mar 15
6444
1
ago 25
2167
0
nov 23
1887
1
mag 20
11942