From 23fcaeda6830f2dc0de17337f9c3da8faf0338ce Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Fri, 12 Feb 2021 15:16:39 +0000 Subject: [FIX] web: list multi edit: prevent force save Have a list with multi_edit enabled Have a widget boolean_toggle displayed on some field Select some records to be in multi edit mode Before this commit, the record on which the boolean toggle button was clicked was written and then the multi edit feature was triggered and wrote on all the records The first write is unnecessary and counter intuitive After this commit, only the write with all the multi edited records is done --- .../static/src/js/views/basic/basic_controller.js | 2 +- .../static/src/js/views/list/list_controller.js | 3 ++ addons/web/static/tests/views/list_tests.js | 38 ++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) (limited to 'addons/web') diff --git a/addons/web/static/src/js/views/basic/basic_controller.js b/addons/web/static/src/js/views/basic/basic_controller.js index b58a4154e1f..001154d29b4 100644 --- a/addons/web/static/src/js/views/basic/basic_controller.js +++ b/addons/web/static/src/js/views/basic/basic_controller.js @@ -706,7 +706,7 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { * @param {OdooEvent} ev */ _onFieldChanged: function (ev) { - if (this.mode === 'readonly') { + if (this.mode === 'readonly' && !('force_save' in ev.data)) { ev.data.force_save = true; } FieldManagerMixin._onFieldChanged.apply(this, arguments); diff --git a/addons/web/static/src/js/views/list/list_controller.js b/addons/web/static/src/js/views/list/list_controller.js index 5a8bb698942..0e1921883ff 100644 --- a/addons/web/static/src/js/views/list/list_controller.js +++ b/addons/web/static/src/js/views/list/list_controller.js @@ -835,6 +835,9 @@ var ListController = BasicController.extend({ ev.data.onFailure = saveMulti; // will show the appropriate dialog // disable onchanges as we'll save directly ev.data.notifyChange = false; + // In multi edit mode, we will be asked if we want to write on the selected + // records, so the force_save for readonly is not necessary. + ev.data.force_save = false; } this._super.apply(this, arguments); }, diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js index b9b747dbc7d..5c30d59593c 100644 --- a/addons/web/static/tests/views/list_tests.js +++ b/addons/web/static/tests/views/list_tests.js @@ -7709,6 +7709,44 @@ QUnit.module('Views', { list.destroy(); }); + QUnit.test('editable list view (multi edition): writable fields in readonly (force save)', async function (assert) { + assert.expect(7); + + // boolean toogle widget allows for writing on the record even in readonly mode + const list = await createView({ + arch: ` + + + `, + data: this.data, + model: 'foo', + View: ListView, + mockRPC(route, args) { + assert.step(args.method || route); + if (args.method === 'write') { + assert.deepEqual(args.args, [[1,3], {bar: false}]); + } + return this._super(...arguments); + } + }); + + assert.verifySteps(['/web/dataset/search_read']); + // select two records + await testUtils.dom.click(list.$('.o_data_row:eq(0) .o_list_record_selector input')); + await testUtils.dom.click(list.$('.o_data_row:eq(2) .o_list_record_selector input')); + + await testUtils.dom.click(list.$('.o_data_row .o_field_boolean')[0]); + + assert.ok($('.modal').text().includes("Confirmation"), "Modal should ask to save changes"); + await testUtils.dom.click($('.modal .btn-primary')); + assert.verifySteps([ + 'write', + 'read', + ]); + + list.destroy(); + }); + QUnit.test('editable list view: multi edition with readonly modifiers', async function (assert) { assert.expect(5); -- cgit v1.2.3