Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
3303 Widoki

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?

Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
Najlepsza odpowiedź

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.
Awatar
Odrzuć
Autor

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.

Powiązane posty Odpowiedzi Widoki Czynność
0
lip 17
2858
0
mar 15
6425
1
sie 25
2129
0
lis 23
1850
1
maj 20
11912