[FIX] web: X2m with custom controller

The goal of this commit is to allow an X2m in list mode with a custom
controller to use the controller context when creating a new line with
a 'tab' keydown.

Part-of: odoo/odoo#78221
This commit is contained in:
FrancoisGe
2022-07-22 16:21:43 +02:00
committed by Géry Debongnie
parent 415746602f
commit 91c32bb980
2 changed files with 40 additions and 1 deletions
@@ -1138,7 +1138,7 @@ export class ListRenderer extends Component {
// add a line
if (record.checkValidity()) {
const { context } = this.creates[0];
this.props.onAdd(context);
this.props.onAdd({ context });
}
} else if (
activeActions.create &&
@@ -9337,6 +9337,45 @@ QUnit.module("Fields", (hooks) => {
}
);
QUnit.test("o2m add a line custom control create editable with 'tab'", async function (assert) {
await makeView({
type: "form",
resModel: "partner",
serverData,
arch: `
<form>
<group>
<field name="turtles">
<tree editable="bottom">
<control>
<create string="Add soft shell turtle" context="{'default_turtle_foo': 'soft'}"/>
</control>
<field name="turtle_foo"/>
</tree>
</field>
</group>
</form>`,
resId: 1,
mockRPC(route, args) {
const { method, kwargs } = args;
if (method === "onchange") {
assert.step("onchange");
assert.strictEqual(kwargs.context.default_turtle_foo, "soft");
}
},
});
await clickEdit(target);
await click(target.querySelector(".o_data_row .o_data_cell"));
await editInput(target, "[name='turtle_foo'] input", "Test");
assert.containsOnce(target, ".o_data_row");
triggerHotkey("Tab");
await nextTick();
assert.containsN(target, ".o_data_row", 2);
assert.verifySteps(["onchange"]);
});
QUnit.test("one2many with onchange, required field, shortcut enter", async function (assert) {
serverData.models.turtle.onchanges = {
turtle_foo: function () {},