تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
3334 أدوات العرض

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
يوليو 17
2880
0
مارس 15
6444
1
أغسطس 25
2170
0
نوفمبر 23
1888
1
مايو 20
11946