[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.
This commit is contained in:
Julien Mougenot
2019-09-18 08:24:32 +00:00
parent 28e52c605d
commit ca4e158a8e
2 changed files with 36 additions and 3 deletions
@@ -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
+13 -3
View File
@@ -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: '<tree editable="bottom">' +
'<field name="foo" required="1"/>' +
'<field name="int_field"/>' +
'</tree>',
});
@@ -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();