From ad7be4314925bac2f4f02b69e2c7abbba820d003 Mon Sep 17 00:00:00 2001 From: FrancoisGe Date: Mon, 6 Nov 2023 11:24:55 +0100 Subject: [PATCH] [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) --- .../static/src/views/list/list_renderer.js | 11 +++++++ .../tests/views/fields/boolean_field_tests.js | 8 ++--- .../views/fields/one2many_field_tests.js | 29 +++++++++++++++++++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/addons/web/static/src/views/list/list_renderer.js b/addons/web/static/src/views/list/list_renderer.js index 29bc25129b8..c90410a7494 100644 --- a/addons/web/static/src/views/list/list_renderer.js +++ b/addons/web/static/src/views/list/list_renderer.js @@ -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(); diff --git a/addons/web/static/tests/views/fields/boolean_field_tests.js b/addons/web/static/tests/views/fields/boolean_field_tests.js index b424d7048ae..54c20f64ece 100644 --- a/addons/web/static/tests/views/fields/boolean_field_tests.js +++ b/addons/web/static/tests/views/fields/boolean_field_tests.js @@ -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); diff --git a/addons/web/static/tests/views/fields/one2many_field_tests.js b/addons/web/static/tests/views/fields/one2many_field_tests.js index 8c7d4739c79..57a0400d7f4 100644 --- a/addons/web/static/tests/views/fields/one2many_field_tests.js +++ b/addons/web/static/tests/views/fields/one2many_field_tests.js @@ -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: ` +
+ + + + + + +
`, + 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];