summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Mougenot <jum@odoo.com>2019-09-17 14:40:31 +0000
committerJulien Mougenot <jum@odoo.com>2019-09-18 08:24:32 +0000
commitca4e158a8e6de237a929d892910e2182d484c35d (patch)
tree11cccd1678862468e1b45fe0d6336c456ac14d3f
parent28e52c605d374c20c75b7ff733e08b59e3b7600d (diff)
[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.
-rw-r--r--addons/web/static/src/js/views/list/list_controller.js23
-rw-r--r--addons/web/static/tests/views/list_tests.js16
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
@@ -754,6 +754,29 @@ var ListController = BasicController.extend({
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
* rerender the view.
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: '<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();