[FIX] web: prevent multiple updates when pressing enter

Steps to reproduce
==================

In 16.4:
- Go to Accounting > Reconcile 8 items
- Click on the first line on the right
- Edit the label and then press Enter
- Switch to another line

=> Odoo Server Error

Cause of the issue
==================

When pressing Enter, two events are triggered: keydown and change.
In the useInputField hook, there is a listener for both of those events,
and they both end up calling `record.update` with the current value from
the input.

In the relational model, the update is locked inside a mutex.

So the first update (triggered by the keydown) does an onchange.
This onchange deletes the current records (Command.CLEAR) and returns
new records.

Once this is done, the mutex is released. The second update (triggered
by the change event) then tries the same update. Since the value was
obtained when queuing for the mutex, it uses the old (now deleted)
record.

Solution
========

This adds a test for https://github.com/odoo/odoo/pull/154991
as part of the fix got lost in a conflict resolution for previous versions.

opw-3726818

closes odoo/odoo#157155

X-original-commit: fbebffe446de9dd80db2dbe5ca7bd2746dc2a54f
Signed-off-by: Simon Genin (ges@odoo) <ges@odoo.com>
Signed-off-by: Hubert Van De Walle <huvw@odoo.com>
This commit is contained in:
Hubert Van De Walle
2024-03-11 11:55:08 +00:00
parent c3a9173048
commit bc326fa21e
@@ -19970,4 +19970,37 @@ QUnit.module("Views", (hooks) => {
assert.verifySteps(["switch to form - resId: 5 activeIds: 5,1,2,3,4"]);
}
);
QUnit.test("onchange should only be called once after pressing enter on a field", async function (assert) {
serverData.models.foo.onchanges = {
foo(record) {
if (record.foo) {
record.int_field = 1;
}
},
};
await makeView({
type: "list",
resModel: "foo",
serverData,
arch: `
<tree editable="top">
<field name="foo"/>
<field name="int_field"/>
</tree>`,
async mockRPC(_, { method }) {
if (method === "onchange") {
assert.step(method);
}
},
});
await click(target.querySelector(".o_data_cell"));
target.querySelector(".o_field_widget[name=foo] input").value = "1";
await triggerEvents(target, ".o_field_widget[name=foo] input", [
["keydown", { key: "Enter" }],
["change"],
]);
await nextTick();
assert.verifySteps(["onchange"], "There should only be one onchange call");
});
});