[FIX] web: X2many in list mode with several records in edition

Before this commit, in an x2many in list mode, it was possible to switch
several records to edit mode.
Normally, it is not possible to have more than one record in edit mode
in a list mode X2many.

How to reproduce:
- Have an X2many with at least two record already.
- Modify a field of the first line and make it invalid
- Click on the second record

Result before the commit:
Both records will be in edit mode.

Result after the commit:
The invalid record stays in edit mode and the other record stays in
readonly mode.

Part-of: odoo/odoo#96101
This commit is contained in:
FrancoisGe
2022-07-28 01:29:58 +02:00
parent 5cb0bf528c
commit afa12b9f04
2 changed files with 44 additions and 2 deletions
@@ -790,8 +790,12 @@ export class StaticList extends DataPoint {
}
if (editedRecord) {
const isValid = editedRecord.checkValidity();
if (!isValid && editedRecord.canBeAbandoned) {
this.abandonRecord(editedRecord.id);
if (!isValid) {
if (editedRecord.canBeAbandoned) {
this.abandonRecord(editedRecord.id);
} else {
return false;
}
} else {
await editedRecord.switchMode("readonly");
}
@@ -7890,6 +7890,44 @@ QUnit.module("Fields", (hooks) => {
}
);
QUnit.test("one2many with invalid value and click on another row", async function (assert) {
serverData.models.partner.records[0].p = [2, 4];
await makeView({
type: "form",
resModel: "partner",
serverData,
arch: `
<form>
<field name="p">
<tree editable="bottom">
<field name="display_name"/>
<field name="int_field"/>
</tree>
</field>
</form>`,
resId: 1,
});
await clickEdit(target);
let rows = target.querySelectorAll(".o_data_row");
await click(rows[0].querySelector(".o_data_cell"));
assert.containsOnce(target, ".o_data_row.o_selected_row");
rows = target.querySelectorAll(".o_data_row");
assert.hasClass(rows[0], "o_selected_row");
assert.doesNotHaveClass(rows[1], "o_selected_row");
await editInput(target, ".o_data_row [name='int_field'] input", "abc");
rows = target.querySelectorAll(".o_data_row");
await click(rows[1].querySelector(".o_data_cell"));
// Stays on the invalid row
assert.containsOnce(target, ".o_data_row.o_selected_row");
rows = target.querySelectorAll(".o_data_row");
assert.hasClass(rows[0], "o_selected_row");
assert.containsOnce(rows[0], "[name='int_field'] .o_field_invalid");
assert.doesNotHaveClass(rows[1], "o_selected_row");
});
QUnit.test(
"default value for nested one2manys (coming from onchange)",
async function (assert) {