From cac91731221b5ac122ad745ac408b406d335e5c7 Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Tue, 13 Nov 2018 16:21:18 +0000 Subject: [FIX] web: m2o+o2m in o2m onchange no lose data Steps: - open a modal form view from tree view first line and make a change - open a modal from the second line and make a change - open the second line back: the change were lost In a given number of conditions (a many2one inside the form view, there is a one2many in the form view not inside the tree view, ....) this happened because: - when we save the first line, we get onchange data for the second one - this onchange data can't be applied before second line is loaded, but it is saved so it can be applied if second line is ever opened - when the second line is opened the saved change is applied => OK - when the second line is opened a second time the saved change is applied again, possibly overwriting posterious change => BAD With this changeset, when the record with unapplied onchange is loaded for the first time, the unapplied onchange is applied only once. Added test without the change failed with: - only 1 turtle for second partner (result: 0 not 1) - second partner turtle is Michelangelo (result: "" not "Michelangelo") opw-1846820 closes #28644 --- .../static/tests/fields/relational_fields_tests.js | 89 ++++++++++++++++++++++ 1 file changed, 89 insertions(+) (limited to 'addons/web/static/tests/fields/relational_fields_tests.js') diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js index fda7c1b7394..61f2e8f0369 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -9752,6 +9752,95 @@ QUnit.module('relational_fields', { form.destroy(); }); + QUnit.test('onchange on unloaded record clearing posterious change', function (assert) { + // when we got onchange result for fields of record that were not + // already available because they were in a inline view not already + // opened, in a given configuration the change were applied ignoring + // posteriously changed data, thus an added/removed/modified line could + // be reset to the original onchange data + assert.expect(5); + + var numUserOnchange = 0; + + this.data.user.onchanges = { + partner_ids: function (obj) { + // simulate actual server onchange after save of modal with new record + if (numUserOnchange === 0) { + obj.partner_ids = _.clone(obj.partner_ids); + obj.partner_ids.unshift([5]); + obj.partner_ids[1][2].turtles.unshift([5]); + obj.partner_ids[2] = [1, 2, { + display_name: 'second record', + trululu: 1, + turtles: [[5]], + }]; + } else if (numUserOnchange === 1) { + obj.partner_ids = _.clone(obj.partner_ids); + obj.partner_ids.unshift([5]); + obj.partner_ids[1][2].turtles.unshift([5]); + obj.partner_ids[2][2].turtles.unshift([5]); + } + numUserOnchange++; + }, + }; + + var form = createView({ + View: FormView, + model: 'user', + data: this.data, + arch: '
' + + '' + + ''+ + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
', + res_id: 17, + }); + + // open first partner and change turtle name + form.$buttons.find('.o_form_button_edit').click(); + form.$('.o_data_row:eq(0)').click(); + $('.modal .o_data_cell:eq(0)').click(); + $('.modal input[name="display_name"]').val('Donatello').change(); + $('.modal .btn-primary').click(); + + // open second partner and add a turtle + form.$('.o_data_row:eq(1)').click(); + $('.modal .o_field_x2many_list_row_add a').click(); + $('.modal input[name="display_name"]').val('Michelangelo').change(); + $('.modal .btn-primary').click(); + + assert.strictEqual(numUserOnchange, 2, + 'there should 2 and only 2 onchange from closing the partner modal'); + + // check first record still has change + form.$('.o_data_row:eq(0)').click(); + assert.strictEqual($('.modal .o_data_row').length, 1, + 'only 1 turtle for first partner'); + assert.strictEqual($('.modal .o_data_row').text(), 'Donatello', + 'first partner turtle is Donatello'); + $('.modal .o_form_button_cancel').click(); + + // check second record still has changes + form.$('.o_data_row:eq(1)').click(); + assert.strictEqual($('.modal .o_data_row').length, 1, + 'only 1 turtle for second partner'); + assert.strictEqual($('.modal .o_data_row').text(), 'Michelangelo', + 'second partner turtle is Michelangelo'); + $('.modal .o_form_button_cancel').click(); + + form.destroy(); + }); + QUnit.test('click on URL should not open the record', function (assert) { assert.expect(2); -- cgit v1.2.3