From c7fc74fb791226dfbf30adfaacaf16e4e1b64953 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Wed, 3 May 2017 09:57:19 +0200 Subject: [FIX] web: BasicModel: fetch added x2many records Suppose that there is a many2many (list) field in a form view, and there is a many2many (e.g. many2many_tags) field inside the list. In edit mode, if the user adds a record in the relation, this record and its relational data should be fetched. Before this rev., the relational data wasn't fetched, so the many2many_tags couldn't be displayed correctly. --- .../static/tests/fields/relational_fields_tests.js | 73 ++++++++++++++++++++++ 1 file changed, 73 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 0629dfc4da1..4e455b290fa 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -3390,6 +3390,79 @@ QUnit.module('relational_fields', { form.destroy(); }); + QUnit.test('many2many list with x2many: add a record', function (assert) { + assert.expect(18); + + this.data.partner_type.fields.m2m = { + string: "M2M", type: "many2many", relation: 'turtle', + }; + this.data.partner_type.records[0].m2m = [1, 2]; + this.data.partner_type.records[1].m2m = [2, 3]; + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch:'
' + + '' + + '', + res_id: 1, + archs: { + 'partner_type,false,list': '' + + '' + + '' + + '', + 'partner_type,false,search': '' + + '' + + '', + }, + mockRPC: function (route, args) { + assert.step(_.last(route.split('/')) + ' on ' + args.model); + if (args.model === 'turtle') { + assert.step(args.args[0]); // the read ids + } + return this._super.apply(this, arguments); + }, + viewOptions: { + mode: 'edit', + }, + }); + + form.$('.o_form_field_x2many_list_row_add a').click(); + $('.modal .o_data_row:first').click(); // add a first record to the relation + + assert.strictEqual(form.$('.o_data_row').length, 1, + "the record should have been added to the relation"); + assert.strictEqual(form.$('.o_data_row:first .o_badge_text').text(), 'leonardodonatello', + "inner m2m should have been fetched and correctly displayed"); + + form.$('.o_form_field_x2many_list_row_add a').click(); + $('.modal .o_data_row:first').click(); // add a second record to the relation + + assert.strictEqual(form.$('.o_data_row').length, 2, + "the second record should have been added to the relation"); + assert.strictEqual(form.$('.o_data_row:nth(1) .o_badge_text').text(), 'donatelloraphael', + "inner m2m should have been fetched and correctly displayed"); + + assert.verifySteps([ + 'read on partner', + 'search_read on partner_type', + 'read on turtle', + [1, 2, 3], + 'read on partner_type', + 'read on turtle', + [1, 2], + 'search_read on partner_type', + 'read on turtle', + [2, 3], + 'read on partner_type', + 'read on turtle', + [2, 3], + ]); + + form.destroy(); + }); + QUnit.module('FieldStatus'); QUnit.test('static statusbar widget on many2one field', function (assert) { -- cgit v1.2.3