From ca4e158a8e6de237a929d892910e2182d484c35d Mon Sep 17 00:00:00 2001 From: Julien Mougenot Date: Tue, 17 Sep 2019 14:40:31 +0000 Subject: [PATCH] [FIX] web: handling of invalid formats in list views Added handling of invalid format types in multiple edition in list views. Before this commit, in multiple edition, a field that was edited with an invalid value format (e.g. a numeric field receiving a string value) didn't trigger a field_changed and no prompt was shown; the record was simply idle with an dirty value. Now, the list controller also listents for set_dirty events and automatically triggers an error modal + discards all changes when receiving one. --- .../src/js/views/list/list_controller.js | 23 +++++++++++++++++++ addons/web/static/tests/views/list_tests.js | 16 ++++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) 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 e39c364de52..a74ed7f3dbc 100644 --- a/addons/web/static/src/js/views/list/list_controller.js +++ b/addons/web/static/src/js/views/list/list_controller.js @@ -753,6 +753,29 @@ var ListController = BasicController.extend({ this.selectedRecords = ev.data.selection; this._toggleSidebar(); }, + /** + * If the record is set as dirty while in multiple record edition, + * we want to immediatly discard the change. + * + * @private + * @override + * @param {OdooEvent} ev + */ + _onSetDirty: function (ev) { + var self = this; + var recordId = ev.data.dataPointID; + if (this.renderer.inMultipleRecordEdition(recordId)) { + ev.stopPropagation(); + Dialog.alert(this, _t("No valid record to save"), { + confirm_callback: function () { + self.model.discardChanges(recordId); + self._confirmSave(recordId); + }, + }); + } else { + this._super.apply(this, arguments); + } + }, /** * When the user clicks on one of the sortable column headers, we need to * tell the model to sort itself properly, to update the pager and to diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js index 7a5a1e3a317..4fea02ae3e9 100644 --- a/addons/web/static/tests/views/list_tests.js +++ b/addons/web/static/tests/views/list_tests.js @@ -4613,7 +4613,7 @@ QUnit.module('Views', { }); QUnit.test('editable list view: multi edition error and cancellation handling', async function (assert) { - assert.expect(8); + assert.expect(12); var list = await createView({ View: ListView, @@ -4621,6 +4621,7 @@ QUnit.module('Views', { data: this.data, arch: '' + '' + + '' + '', }); @@ -4635,7 +4636,16 @@ QUnit.module('Views', { assert.containsNone(list, '.o_list_record_selector input:enabled'); await testUtils.fields.editInput(list.$('.o_selected_row .o_field_widget[name=foo]'), "abc"); await testUtils.dom.click($('.modal .btn:contains("Cancel")')); - assert.strictEqual(list.$('.o_data_row:eq(0) .o_data_cell').text(), 'yop', "first cell should have discarded any change"); + assert.strictEqual(list.$('.o_data_row:eq(0) .o_data_cell').text(), 'yop10', "first cell should have discarded any change"); + assert.containsN(list, '.o_list_record_selector input:enabled', 5); + + // edit a line with an invalid format type + await testUtils.dom.click(list.$('.o_data_row:eq(0) .o_data_cell:eq(1)')); + assert.containsNone(list, '.o_list_record_selector input:enabled'); + await testUtils.fields.editInput(list.$('.o_selected_row .o_field_widget[name=int_field]'), "hahaha"); + assert.containsOnce(document.body, '.modal', "there should be an opened modal"); + await testUtils.dom.click($('.modal .btn-primary')); + assert.strictEqual(list.$('.o_data_row:eq(0) .o_data_cell').text(), 'yop10', "changes should be discarded"); assert.containsN(list, '.o_list_record_selector input:enabled', 5); // edit a line with an invalid value @@ -4644,7 +4654,7 @@ QUnit.module('Views', { await testUtils.fields.editInput(list.$('.o_selected_row .o_field_widget[name=foo]'), ""); assert.containsOnce(document.body, '.modal', "there should be an opened modal"); await testUtils.dom.click($('.modal .btn-primary')); - assert.strictEqual(list.$('.o_data_row:eq(0) .o_data_cell').text(), 'yop', "changes should be discarded"); + assert.strictEqual(list.$('.o_data_row:eq(0) .o_data_cell').text(), 'yop10', "changes should be discarded"); assert.containsN(list, '.o_list_record_selector input:enabled', 5); list.destroy();