[FIX] web: parent access in button context broken
Before this commit, accessing parent in a button context broke the button throwing `EvaluationError: Name 'parent' is not defined`. to fix,the proxy object `params.evalContext` was passed to `evaluateExpr` similar to examples seen in `list_renderer.js` closes odoo/odoo#102293 X-original-commit: 90afb529969ce7de83a20060f5c35a64ce4cf971 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com> Signed-off-by: Ahmed Khalaf <ahkh@odoo.com>
This commit is contained in:
@@ -71,8 +71,7 @@ export function useViewButtons(model, ref, options = {}) {
|
||||
let buttonContext = {};
|
||||
if (clickParams.context) {
|
||||
if (typeof clickParams.context === "string") {
|
||||
const valuesForEval = Object.assign({}, params.evalContext);
|
||||
buttonContext = evaluateExpr(clickParams.context, valuesForEval);
|
||||
buttonContext = evaluateExpr(clickParams.context, params.evalContext);
|
||||
} else {
|
||||
buttonContext = clickParams.context;
|
||||
}
|
||||
|
||||
@@ -9018,6 +9018,33 @@ QUnit.module("Fields", (hooks) => {
|
||||
assert.verifySteps(["do_something"]);
|
||||
});
|
||||
|
||||
QUnit.test("o2m button with parent in context", async function (assert) {
|
||||
await makeView({
|
||||
type: "form",
|
||||
resModel: "partner",
|
||||
serverData,
|
||||
resId: 1,
|
||||
arch: `
|
||||
<form>
|
||||
<field name="turtles">
|
||||
<tree>
|
||||
<field name="display_name"/>
|
||||
<button string="Action Button" name="test_button" type="object" context="{'parent_name': parent.display_name}"/>
|
||||
</tree>
|
||||
</field>
|
||||
</form>`,
|
||||
mockRPC(route, args) {
|
||||
if (args.method === "test_button") {
|
||||
assert.step("test_button");
|
||||
assert.strictEqual(args.kwargs.context.parent_name, 'first record');
|
||||
return true;
|
||||
}
|
||||
},
|
||||
});
|
||||
await click(target, 'button[name="test_button"]');
|
||||
assert.verifySteps(["test_button"]);
|
||||
});
|
||||
|
||||
QUnit.test("o2m add a line custom control create align with handle", async function (assert) {
|
||||
await makeView({
|
||||
type: "form",
|
||||
|
||||
Reference in New Issue
Block a user