Skip to content

Commit 6f2be3e

Browse files
committed
[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 odoo#154991 as part of the fix got lost in a conflict resolution for previous versions. opw-3726818 closes odoo#157260 X-original-commit: bc326fa Signed-off-by: Simon Genin (ges@odoo) <[email protected]> Signed-off-by: Hubert Van De Walle <[email protected]>
1 parent f24d152 commit 6f2be3e

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

addons/web/static/tests/legacy/views/list_view_tests.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20051,4 +20051,37 @@ QUnit.module("Views", (hooks) => {
2005120051
assert.verifySteps(["switch to form - resId: 5 activeIds: 5,1,2,3,4"]);
2005220052
}
2005320053
);
20054+
20055+
QUnit.test("onchange should only be called once after pressing enter on a field", async function (assert) {
20056+
serverData.models.foo.onchanges = {
20057+
foo(record) {
20058+
if (record.foo) {
20059+
record.int_field = 1;
20060+
}
20061+
},
20062+
};
20063+
await makeView({
20064+
type: "list",
20065+
resModel: "foo",
20066+
serverData,
20067+
arch: `
20068+
<tree editable="top">
20069+
<field name="foo"/>
20070+
<field name="int_field"/>
20071+
</tree>`,
20072+
async mockRPC(_, { method }) {
20073+
if (method === "onchange") {
20074+
assert.step(method);
20075+
}
20076+
},
20077+
});
20078+
await click(target.querySelector(".o_data_cell"));
20079+
target.querySelector(".o_field_widget[name=foo] input").value = "1";
20080+
await triggerEvents(target, ".o_field_widget[name=foo] input", [
20081+
["keydown", { key: "Enter" }],
20082+
["change"],
20083+
]);
20084+
await nextTick();
20085+
assert.verifySteps(["onchange"], "There should only be one onchange call");
20086+
});
2005420087
});

0 commit comments

Comments
 (0)