From 312b9b15025f64ceef4dbdd263c0663065a9ce81 Mon Sep 17 00:00:00 2001 From: Lucas Perais Date: Wed, 10 Aug 2022 11:08:43 +0000 Subject: [PATCH] [FIX] web: correctly compile invisible when t-if already exists Have a section of a settings view that can be search in. Have a dynamic invisble modifier (governed by a domain) on it. Before this commit, the condition were just juxtaposed, which will cause problem if one of them contains a "OR" operator. So, sections that should have been invisible were visible because the if looked like: search() or search_other() and isVisible(). After this commit, the t-ifs are correctly combined so that they look like: (search() or search_other()) and isVisible(). closes odoo/odoo#97811 Signed-off-by: Samuel Degueldre --- addons/web/static/src/views/view_compiler.js | 12 ++++----- .../tests/views/form/form_compiler_tests.js | 25 ++++++++++++++++++- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/addons/web/static/src/views/view_compiler.js b/addons/web/static/src/views/view_compiler.js index 3bd66b47cf5..156f7c74aa1 100644 --- a/addons/web/static/src/views/view_compiler.js +++ b/addons/web/static/src/views/view_compiler.js @@ -254,12 +254,12 @@ export class ViewCompiler { return; } if (!params.enableInvisible) { - combineAttributes( - compiled, - "t-if", - `!evalDomainFromRecord(props.record,${JSON.stringify(invisible)})`, - " and " - ); + let isVisileExpr = `!evalDomainFromRecord(props.record,${JSON.stringify(invisible)})`; + if (compiled.hasAttribute("t-if")) { + const formerTif = compiled.getAttribute("t-if"); + isVisileExpr = `( ${formerTif} ) and ${isVisileExpr}`; + } + compiled.setAttribute("t-if", isVisileExpr); } else { appendAttr(compiled, "class", `o_invisible_modifier:${invisible}`); } 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 4c9ee6056d1..7f4c7b4c00a 100644 --- a/addons/web/static/tests/views/form/form_compiler_tests.js +++ b/addons/web/static/tests/views/form/form_compiler_tests.js @@ -3,7 +3,8 @@ import { makeView } from "../helpers"; import { setupViewRegistries } from "@web/../tests/views/helpers"; import { FormCompiler } from "@web/views/form/form_compiler"; import { registry } from "@web/core/registry"; -import { click, getFixture } from "../../helpers/utils"; +import { click, getFixture, patchWithCleanup } from "../../helpers/utils"; +import { createElement } from "@web/core/utils/xml"; function compileTemplate(arch) { const parser = new DOMParser(); @@ -371,4 +372,26 @@ QUnit.module("Form Renderer", (hooks) => { assert.containsOnce(target, "button[id=action_button]"); }); + + QUnit.test("invisible is correctly computed with another t-if", (assert) => { + patchWithCleanup(FormCompiler.prototype, { + setup() { + this._super(); + this.compilers.push({ + selector: "myNode", + fn: () => { + const div = createElement("div"); + div.className = "myNode"; + div.setAttribute("t-if", "myCondition or myOtherCondition"); + return div; + }, + }); + }, + }); + + const arch = ``; + + const expected = `
`; + assert.areEquivalent(compileTemplate(arch), expected); + }); });