[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 <sad@odoo.com>
This commit is contained in:
@@ -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}`);
|
||||
}
|
||||
|
||||
@@ -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 = `<myNode modifiers="{"invisible": [["field", "=", "value"]]}" />`;
|
||||
|
||||
const expected = `<t><div class="myNode" t-if="( myCondition or myOtherCondition ) and !evalDomainFromRecord(props.record,[["field","=","value"]])" t-ref="compiled_view_root"/></t>`;
|
||||
assert.areEquivalent(compileTemplate(arch), expected);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user