From 8ca03fb6e3807b77a2aaca4f487dde3ed10a37ab Mon Sep 17 00:00:00 2001 From: Lucas Perais Date: Tue, 12 Jul 2022 11:25:49 +0000 Subject: [PATCH] [FIX] web: form: the status bar must be present if in arch Before this commit, when the status bar did not have buttons to display it was not displayed at all. After this commit, we display it even if there are not any button inside. Part-of: odoo/odoo#78221 --- .../static/src/views/form/form_compiler.js | 30 ++++++++-------- .../status_bar_buttons/status_bar_buttons.js | 6 +++- .../tests/views/form/form_compiler_tests.js | 36 +++++++++++++++++-- .../tests/views/form/form_view_tests.js | 12 +++++++ 4 files changed, 65 insertions(+), 19 deletions(-) diff --git a/addons/web/static/src/views/form/form_compiler.js b/addons/web/static/src/views/form/form_compiler.js index 8d1bcbb79f8..aaf76f8588f 100644 --- a/addons/web/static/src/views/form/form_compiler.js +++ b/addons/web/static/src/views/form/form_compiler.js @@ -356,23 +356,21 @@ export class FormCompiler extends ViewCompiler { buttons.push(compiled); } } - if (buttons.length) { - let slotId = 0; - const statusBarButtons = createElement("StatusBarButtons"); - statusBarButtons.setAttribute("readonly", "!props.record.isInEdition"); - for (const button of buttons) { - const slot = createElement("t", { - "t-set-slot": `button_${slotId++}`, - isVisible: button.getAttribute("t-if") || true, - displayInReadOnly: - button.hasAttribute("className") && - button.getAttribute("className").includes("oe_read_only"), - }); - append(slot, button); - append(statusBarButtons, slot); - } - append(statusBar, statusBarButtons); + let slotId = 0; + const statusBarButtons = createElement("StatusBarButtons"); + statusBarButtons.setAttribute("readonly", "!props.record.isInEdition"); + for (const button of buttons) { + const slot = createElement("t", { + "t-set-slot": `button_${slotId++}`, + isVisible: button.getAttribute("t-if") || true, + displayInReadOnly: + button.hasAttribute("className") && + button.getAttribute("className").includes("oe_read_only"), + }); + append(slot, button); + append(statusBarButtons, slot); } + append(statusBar, statusBarButtons); append(statusBar, others); return statusBar; } diff --git a/addons/web/static/src/views/form/status_bar_buttons/status_bar_buttons.js b/addons/web/static/src/views/form/status_bar_buttons/status_bar_buttons.js index e810ab75ca1..d525216b306 100644 --- a/addons/web/static/src/views/form/status_bar_buttons/status_bar_buttons.js +++ b/addons/web/static/src/views/form/status_bar_buttons/status_bar_buttons.js @@ -7,9 +7,13 @@ const { Component } = owl; export class StatusBarButtons extends Component { get visibleSlotNames() { + if (!this.props.slots) { + return []; + } return Object.entries(this.props.slots) .filter( - (entry) => entry[1].isVisible && (entry[1].displayInReadOnly ? this.props.readonly : true) + (entry) => + entry[1].isVisible && (entry[1].displayInReadOnly ? this.props.readonly : true) ) .map((entry) => entry[0]); } diff --git a/addons/web/static/tests/views/form/form_compiler_tests.js b/addons/web/static/tests/views/form/form_compiler_tests.js index f926300888c..01f44e24faa 100644 --- a/addons/web/static/tests/views/form/form_compiler_tests.js +++ b/addons/web/static/tests/views/form/form_compiler_tests.js @@ -129,7 +129,7 @@ QUnit.module("Form Compiler", () => { const expected = /*xml*/ `
-
+
someDiv
`; @@ -152,7 +152,7 @@ QUnit.module("Form Compiler", () => {
-
+
someDiv
inside sheet
@@ -204,6 +204,38 @@ QUnit.module("Form Compiler", () => { `; assert.areContentEquivalent(compileTemplate(arch), expected); }); + + QUnit.test("properly compile status bar with content", (assert) => { + const arch = /*xml*/ ` +
+
someDiv
+
`; + + const expected = /*xml*/ ` +
+ + +
someDiv
+
+
+
`; + + assert.areContentEquivalent(compileTemplate(arch), expected); + }); + + QUnit.test("properly compile status bar without content", (assert) => { + const arch = /*xml*/ ` +
+
+
`; + + const expected = /*xml*/ ` +
+ +
`; + + assert.areContentEquivalent(compileTemplate(arch), expected); + }); }); QUnit.module("Form Renderer", (hooks) => { diff --git a/addons/web/static/tests/views/form/form_view_tests.js b/addons/web/static/tests/views/form/form_view_tests.js index 02ac9107d7c..0e066ba5577 100644 --- a/addons/web/static/tests/views/form/form_view_tests.js +++ b/addons/web/static/tests/views/form/form_view_tests.js @@ -293,6 +293,18 @@ QUnit.module("Views", (hooks) => { assert.containsNone(target, "label.o_form_label_empty:contains(timmy)"); }); + QUnit.test("status bar rendering without buttons", async (assert) => { + await makeView({ + type: "form", + resModel: "partner", + serverData, + arch: `
`, + resId: 2, + }); + + assert.containsOnce(target, ".o_form_sheet_bg > .o_form_statusbar > .o_statusbar_buttons"); + }); + QUnit.test("duplicate fields rendered properly", async function (assert) { await makeView({ type: "form",