[FIX] web: boolean field toggle in editable list

Before this commit, in an editable list view (or in x2many), you need
to click twice on a boolean field to change its value. The first to set
the record to edit and the second to toggle the value.
The purpose of this commit is to simplify this flow by only requiring one click.

How to reproduce:
- Go to a form view with an x2many in editable list mode that contains a boolean field.
- Click on the boolean field of the first record

Before this commit:
    The record goes to edition and the value of the field has not changed.

After this commit;
    The record goes to edition and the value of the field has changed.

closes odoo/odoo#141153

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
FrancoisGe
2023-11-13 14:38:33 +00:00
parent a2e823858b
commit ad7be43149
3 changed files with 44 additions and 4 deletions
@@ -1119,6 +1119,17 @@ export class ListRenderer extends Component {
await recordAfterResequence();
await this.props.list.enterEditMode(record);
this.cellToFocus = { column, record };
if (
record.fields[column.name].type === "boolean" &&
(!column.widget || column.widget === "boolean")
) {
if (
!this.isCellReadonly(column, record) &&
!this.evalInvisible(column.invisible, record)
) {
await record.update({ [column.name]: !record.data[column.name] });
}
}
}
} else if (this.props.list.editedRecord && this.props.list.editedRecord !== record) {
this.props.list.leaveEditMode();
@@ -190,9 +190,10 @@ QUnit.module("Fields", (hooks) => {
"the row is now selected, in edition"
);
assert.ok(
!cell.querySelector(".o-checkbox input:checked").disabled,
"input should now be enabled"
!cell.querySelector(".o-checkbox input:not(:checked)").disabled,
"input should now be enabled and unchecked"
);
await click(cell, ".o-checkbox");
await click(cell);
assert.notOk(
cell.querySelector(".o-checkbox input:checked").disabled,
@@ -220,10 +221,9 @@ QUnit.module("Fields", (hooks) => {
"should now have only 3 checked input"
);
// Re-Edit the line and fake-check the checkbox
// Fake-check the checkbox
await click(cell);
await click(cell, ".o-checkbox");
await click(cell, ".o-checkbox");
// Save
await clickSave(target);
@@ -3759,6 +3759,35 @@ QUnit.module("Fields", (hooks) => {
assert.containsNone(target, "td.o_list_record_remove button");
});
QUnit.test("boolean field in a one2many must be directly editable", 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="top">
<field name="bar"/>
<field name="name"/>
</tree>
</field>
</form>`,
resId: 1,
});
assert.deepEqual(
[...target.querySelectorAll(".o_data_cell[name='bar'] input")].map((el) => el.checked),
[true, false]
);
await click(target.querySelector('[name="bar"] .o-checkbox'));
assert.deepEqual(
[...target.querySelectorAll(".o_data_cell[name='bar'] input")].map((el) => el.checked),
[false, false]
);
});
QUnit.test("many2many list: unlink two records", async function (assert) {
assert.expect(4);
serverData.models.partner.records[0].p = [1, 2, 4];