[FIX] web: list: multi edition: disable onchanges

Onchanges make no sense in multi edition as they would be computed
on the 'reference' record (the one use to edit), but applied on all
selected records. This rev. simply disables them in that case.

Task 2068280
This commit is contained in:
Aaron Bohy
2019-09-18 11:31:43 +00:00
parent 4fba43c027
commit c7ec4bb39d
2 changed files with 58 additions and 0 deletions
@@ -778,6 +778,8 @@ var ListController = BasicController.extend({
this.multipleRecordsSavingPromise =
this._saveMultipleRecords(ev.data.dataPointID, ev.target.__node, ev.data.changes);
};
// disable onchanges as we'll save directly
ev.data.notifyChange = false;
}
this._super.apply(this, arguments);
},
@@ -5384,6 +5384,62 @@ QUnit.module('Views', {
list.destroy();
});
QUnit.test('editable list view: multi edition and onchanges', async function (assert) {
assert.expect(10);
this.data.foo.onchanges = {
foo: function (obj) {
obj.int_field = obj.foo.length;
},
};
var list = await createView({
View: ListView,
model: 'foo',
data: this.data,
arch: '<tree editable="bottom">' +
'<field name="foo"/>' +
'<field name="int_field"/>' +
'</tree>',
mockRPC: function (route, args) {
assert.step(args.method || route);
if (args.method === 'write') {
args.args[1].int_field = args.args[1].foo.length;
}
return this._super.apply(this, arguments);
},
});
// edit a single record to validate that onchanges work
await testUtils.dom.click(list.$('.o_data_row:eq(0) .o_data_cell:eq(0)'));
await testUtils.fields.editInput(list.$('.o_field_widget[name=foo]'), 'hi');
await testUtils.dom.click(list.$('.o_data_row:eq(0) .o_data_cell:eq(1)'));
await testUtils.dom.click(list.$('.o_list_button_discard'));
assert.containsOnce(document.body, '.modal'); // discard dialog
await testUtils.dom.click($('.modal .btn-primary'));
assert.verifySteps(['/web/dataset/search_read', 'onchange']);
// 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(1) .o_list_record_selector input'));
// edit foo, first row
await testUtils.dom.click(list.$('.o_data_row:eq(0) .o_data_cell:eq(0)'));
await testUtils.fields.editInput(list.$('.o_field_widget[name=foo]'), 'hello');
await testUtils.dom.click(list.$('.o_data_row:eq(0) .o_data_cell:eq(1)'));
assert.containsOnce(document.body, '.modal'); // save dialog
await testUtils.dom.click($('.modal .btn-primary'));
assert.strictEqual(list.$('.o_data_row:eq(0) .o_data_cell').text(), "hello5");
assert.strictEqual(list.$('.o_data_row:eq(1) .o_data_cell').text(), "hello5");
assert.verifySteps(['write', 'read'], "should not perform the onchange in multi edition");
list.destroy();
});
QUnit.test('editable list view: multi edition error and cancellation handling', async function (assert) {
assert.expect(8);