[FIX] web: py_js: add "true"/"false" in context

Before this commit, py_js was unabled to evaluate expressions
containing "true" or "false" (boolean values, JS syntax), which
seems reasonnable for a python interpreter. However in Odoo, we
often use that syntax in modifiers (e.g. required="true"). For
that reason, we need to add those two keywords in the evaluation
context.

Part-of: odoo/odoo#87522
This commit is contained in:
Aaron Bohy
2022-04-29 09:57:46 +02:00
committed by Denis Ledoux
parent 0c30f9e378
commit 30d2d2e7dc
2 changed files with 8 additions and 0 deletions
@@ -58,4 +58,7 @@ export const BUILTINS = {
},
relativedelta: PyRelativeDelta,
true: true,
false: false,
};
@@ -145,6 +145,11 @@ QUnit.module("py", {}, () => {
}
);
QUnit.test("true and false available in context", (assert) => {
assert.strictEqual(evaluateExpr("true"), true);
assert.strictEqual(evaluateExpr("false"), false);
});
QUnit.test("throw error if name is not defined", (assert) => {
assert.throws(() => evaluateExpr("a"));
});