[FIX] web: discard invalid row in list view

Before this commit, in a list view, if you clicked the discard button
for an invalid row, it would not be discarded and the discard button
would disappear.

Why did this happen?
Invalid fields in the record were not deleted.

How to reproduce?
- Go to a list view with a required char field
- Edit the char field of a record with an empty string
- Click outside the record (it becomes invalid)
- Click on the discard button

Before this commit:
The record is not discarded (its values do not change and it remains
in edit mode) and the discard button disappears

After this commit:
The record is correctly discarded and the discard button disappears

closes odoo/odoo#102763

X-original-commit: 73ba2217ec56819ff979020a43d0c13f8ff0b697
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
FrancoisGe
2022-10-08 18:57:10 +02:00
parent 35789f9ab4
commit 943e672d35
2 changed files with 26 additions and 0 deletions
@@ -657,6 +657,8 @@ export class Record extends DataPoint {
this.data[fieldName] = this._values[fieldName];
}
}
this._invalidFields.clear();
if (!this.isVirtual) {
this.switchMode("readonly");
}
@@ -13419,6 +13419,30 @@ QUnit.module("Views", (hooks) => {
}
);
QUnit.test("discard an invalid row in a list", async function (assert) {
await makeView({
type: "list",
resModel: "foo",
serverData,
arch: '<tree editable="top"><field name="foo" required="1"/></tree>',
});
await click(target.querySelector(".o_data_cell"));
assert.containsNone(target, ".o_field_invalid");
assert.containsOnce(target, ".o_selected_row");
await editInput(target, "[name='foo'] input", "");
await click(target, ".o_list_view");
assert.containsOnce(target, ".o_field_invalid");
assert.containsOnce(target, ".o_selected_row");
assert.strictEqual(target.querySelector("[name='foo'] input").value, "");
await clickDiscard(target);
assert.containsNone(target, ".o_field_invalid");
assert.containsNone(target, ".o_selected_row");
assert.strictEqual(target.querySelector("[name='foo']").textContent, "yop");
});
QUnit.test('editable grouped list with create="0"', async function (assert) {
await makeView({
type: "list",