[FIX] web: domain selector: treat false,true as in py interpreter

A string representation of a domain like "[('bar', '=', false)]" is
evaluated by py.js the same way as "[('bar', '=', False)]".So both domains
are recognized as correct while false is not a valid python expression.
We do the same in domain selector, the expression "false" ("true")
will be understood as "False" (resp. "True").

Part-of: odoo/odoo#126350
This commit is contained in:
Mathieu Duckerts-Antoine
2023-07-03 16:58:54 +02:00
parent 089e0e680c
commit 1b94eefe26
2 changed files with 18 additions and 0 deletions
@@ -128,6 +128,8 @@ export function getValue(ast) {
return ast.value;
} else if (ast.type === 6 && ast.op === "-" && ast.right.type === 0) {
return -ast.right.value;
} else if (ast.type === 5 && ["false", "true"].includes(ast.value)) {
return JSON.parse(ast.value);
} else {
return new DomainValueExpr(ast);
}
@@ -57,6 +57,11 @@ async function makeDomainSelector(params = {}) {
},
};
}
async set(domain) {
this.domainSelectorProps.domain = domain;
this.render();
await nextTick();
}
}
Parent.components = { DomainSelector };
Parent.template = xml`<DomainSelector t-props="domainSelectorProps"/>`;
@@ -1288,4 +1293,15 @@ QUnit.module("Components", (hooks) => {
await click(target, ".o_model_field_selector");
await click(target, ".o_model_field_selector_popover_item[data-name=foo] button");
});
QUnit.test("treat false and true like False and True", async (assert) => {
const parent = await makeDomainSelector({
resModel: "partner",
domain: `[("bar","=",false)]`,
readonly: true,
});
assert.strictEqual(target.querySelector(".o_domain_leaf").textContent, `Baris not set`);
await parent.set(`[("bar","=",true)]`);
assert.strictEqual(target.querySelector(".o_domain_leaf").textContent, `Baris set`);
});
});