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

I’m currently working on customizing dialogs in Odoo and I would like to either hide the title of the dialog or remove the close (X) button that appears in the header of the dialogService.

So far, I’ve been able to open dialogs with custom buttons and content, but I haven’t found a clean way to control the header area. Ideally, I’d like to keep the dialog body and footer buttons, but without showing the default title or the close icon.

Has anyone achieved this before? Any suggestions on whether it should be done through CSS overrides, patching the Dialog component, or some configuration I might have missed?

Avatar
Discard
Best Answer

Hi,

In Odoo 17/18 (OWL-based frontend), the dialogs you open with dialogService.add() are instances of the Dialog component. By default, they render with a header section that contains the title and the close (X) button. Unfortunately, there isn’t a built-in option in the service API to suppress just the header, so you need to tweak the component behavior yourself.


1. Use a patch on the Dialog component

You can patch the Dialog component in JavaScript to make the header optional:

/** @odoo-module **/


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

import { Dialog } from "@web/core/dialog/dialog";


patch(Dialog.prototype, {

    setup() {

        this._super();

        // You could add a prop (e.g. hideHeader) to control this

    },

    get showHeader() {

        // if the props specify hideHeader, do not render the header

        return !this.props.hideHeader;

    },

});


Then, when calling dialogService.add(), you’d pass:


this.dialogService.add(Dialog, {

    hideHeader: true,

    body: "Custom body content here",

    buttons: [{ text: "OK", primary: true, close: true }],

});


This way you keep the footer buttons but no title/X.


2. Custom wrapper dialog component

Another approach is to create a new component that wraps Dialog but overrides the template so it doesn’t include the header. Then you can open this custom component via dialogService.add().


/** @odoo-module **/

import { Dialog } from "@web/core/dialog/dialog";


export class HeaderlessDialog extends Dialog {

    static template = "your_module.HeaderlessDialog"; // custom template without header

}


In your XML template, remove the header entirely but keep the body/footer slots.


If it’s for a single use case, CSS with a custom class is the quickest. If you want reusable control, patching Dialog to support a hideHeader prop is the cleanest solution.


Hope it helps

Avatar
Discard
Author

Hi, thanks for your reply. I tried what you said, but it didn't work. I'll share my original code so you can review it; I probably missed something.

This is my code:
quantity_dialog.xml

<?xml version="1.0" encoding="UTF-8"?>

<t t-name="alx_barcode_psv.QuantityDialog">

<Dialog size="'md'" title="props.title || _('Ingrese cantidad')" footer="false" withCloseButton="false">

<t t-set="DialogHeader" t-value="''"/>

<div class="o_form_label mb-2">

<t t-esc="props.subtitle || ''"/>

</div>

<div class="mb-3">

<label class="form-label">

<t t-esc="props.label || _('Cantidad a agregar')"/>

</label>

<input type="number"

class="form-control"

t-model="state.qty"

min="0"

step="any"

t-att-autofocus="true"/>

<div class="d-flex justify-content-end mt-4">

<button style="margin-right: 8px;" type="button" class="btn btn-secondary" t-on-click="onCancel">

Cancelar

</button>

<button type="button" class="btn btn-primary" t-on-click="onConfirm">

Aceptar

</button>

</div>

</div>

</Dialog>

</t>

/** @odoo-module **/

import { _t } from "@web/core/l10n/translation";

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

import BarcodePickingModel from "@stock_barcode/models/barcode_picking_model";

import { Component, useState } from "@odoo/owl";

import { Dialog } from "@web/core/dialog/dialog";

// COMPONENTE QuantityDialog embebido

class QuantityDialog extends Component {

static template = "alx_barcode_psv.QuantityDialog";

static components = { Dialog };

setup() {

const { defaultQty = 1 } = this.props;

this.state = useState({ qty: String(defaultQty) });

}

onConfirm() {

const value = parseFloat(this.state.qty);

if (isNaN(value) || value <= 0) return;

this.props.resolve(value);

this.props.close();

this._reactivateScanner();

}

onCancel() {

this.props.resolve(false);

this.props.close();

this._reactivateScanner();

}

_reactivateScanner() {

const model = this.props.model;

if (model && typeof model.startBarcodeScanner === "function") {

model.startBarcodeScanner();

model.trigger("playSound");

}

}

}

// Función de diálogo

function askQuantity(dialogService, product, model) {

return new Promise((resolve) => {

const title = _t("Cantidad para %s", product?.display_name || _t("Producto"));

const subtitle = product?.code ? `[${product.code}] ${product.display_name}` : (product?.display_name || "");

dialogService.add(QuantityDialog, {

title,

subtitle,

label: _t("Cantidad a agregar"),

defaultQty: 1,

resolve,

model,

closeOnOutsideClick: false,

closeOnEsc: false,

});

});

}

// Validación de producto no reservado

function denyNewLine(product) {

const name =

(product?.code ? `[${product.code}] ` : "") +

(product?.display_name || _t("Producto"));

this.trigger("playSound");

this.notification(

_t("No puedes escanear el producto %s porque no está reservado en esta operación.", name),

{ type: "danger" }

);

}

// Guardamos funciones originales

const ORIG = {

updateLine: BarcodePickingModel.prototype.updateLine,

setQtyDone: BarcodePickingModel.prototype.setQtyDone,

};

// Parcheo al modelo

patch(BarcodePickingModel.prototype, {

createNewLine(params) {

denyNewLine.call(this, params?.fieldsParams?.product_id);

return false;

},

async _createNewLine(params) {

denyNewLine.call(this, params?.fieldsParams?.product_id);

return false;

},

askBeforeNewLinesCreation(/* product */) {

return false;

},

async updateLine(line, fieldsParams = {}) {

if (fieldsParams.__skipQtyPopup || fieldsParams.package || fieldsParams.resultPackage) {

return await ORIG.updateLine.call(this, line, fieldsParams);

}

const product = fieldsParams.product || line?.product_id;

if (!product) {

return await ORIG.updateLine.call(this, line, fieldsParams);

}

this.trigger("playSound");

const qty = await askQuantity(this.dialogService, product, this);

if (!qty) {

this.notification(_t("Operación cancelada"), { type: "warning" });

return false;

}

const current = this.getQtyDone(line) || 0;

const newQty = current + qty;

fieldsParams.qty_done = newQty;

fieldsParams.__skipQtyPopup = true;

const res = await ORIG.updateLine.call(this, line, fieldsParams);

this.trigger("update");

return res;

},

});

{

"name": "Barcode Validations and entries",

"author": "ARCA Labs",

"depends": ["base","stock_barcode","barcodes"],

"data": [],

"assets": {

"web.assets_backend": [

"alx_barcode_psv/static/src/js/barcode_model_override.js",

"alx_barcode_psv/static/src/components/quantity_dialog/quantity_dialog.xml",

],

},

}

Related Posts Replies Views Activity
2
Jul 25
922
1
Jul 25
1934
1
Sep 25
280
3
Sep 25
469
4
Aug 25
1558