跳至内容
菜单
此问题已终结
2 回复
3185 查看

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?

形象
丢弃
最佳答案

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.

形象
丢弃
最佳答案

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.
形象
丢弃
编写者

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.

相关帖文 回复 查看 活动
0
7月 17
2774
0
3月 15
6295
1
2月 24
1861
0
11月 23
1754
1
5月 20
11666