From 8b6e86927941dce2018ea93f191b59856ea67e4b Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Fri, 12 Feb 2021 10:49:34 +0000 Subject: [FIX] web: multiedit in a grouped list view: enable fetchBatchedM2O and References Have grouped list with reference a m2o or a reference field Select some records, edit them Before this commit: the names of the reference fields and m2o disappeared That was because the saveRecords function did not take into account a grouped list manual forward port of #65999 After this commit: it works as expected closes odoo/odoo#66043 closes odoo/odoo#66140 Signed-off-by: Lucas Perais (lpe) --- addons/web/static/src/js/views/list/list_model.js | 15 +++-- addons/web/static/tests/views/list_tests.js | 76 +++++++++++++++++++++++ 2 files changed, 87 insertions(+), 4 deletions(-) (limited to 'addons/web') diff --git a/addons/web/static/src/js/views/list/list_model.js b/addons/web/static/src/js/views/list/list_model.js index 5d40343ef8d..5a8771c0da3 100644 --- a/addons/web/static/src/js/views/list/list_model.js +++ b/addons/web/static/src/js/views/list/list_model.js @@ -82,10 +82,17 @@ odoo.define('web.ListModel', function (require) { self._parseServerData(fieldNames, record, record.data); }); }).then(function () { - return Promise.all([ - self._fetchX2ManysBatched(list), - self._fetchReferencesBatched(list) - ]); + if (!list.groupedBy.length) { + return Promise.all([ + self._fetchX2ManysBatched(list), + self._fetchReferencesBatched(list) + ]); + } else { + return Promise.all([ + self._fetchX2ManysSingleBatch(list), + self._fetchReferencesSingleBatch(list) + ]); + } }); }, diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js index 5c30d59593c..481ec86a6e8 100644 --- a/addons/web/static/tests/views/list_tests.js +++ b/addons/web/static/tests/views/list_tests.js @@ -7250,6 +7250,82 @@ QUnit.module('Views', { list.destroy(); }); + QUnit.test('multi edit reference field batched in grouped list', async function (assert) { + assert.expect(18); + + this.data.foo.records= [ + // group 1 + {id: 1, foo: '1', reference: 'bar,1'}, + {id: 2, foo: '1', reference: 'bar,2'}, + //group 2 + {id: 3, foo: '2', reference: 'res_currency,1'}, + {id: 4, foo: '2', reference: 'bar,2'}, + {id: 5, foo: '2', reference: 'bar,3'}, + ]; + // Field boolean_toggle just to simplify the test flow + let nameGetCount = 0; + const list = await createView({ + View: ListView, + model: 'foo', + data: this.data, + arch: ` + + + + `, + groupBy: ['foo'], + mockRPC: function (route, args) { + assert.step(args.method || route); + if (args.method === 'write') { + assert.deepEqual(args.args, [[1,2,3], {bar: true}]); + } + if (args.method === 'name_get') { + if (nameGetCount === 2) { + assert.strictEqual(args.model, 'bar'); + assert.deepEqual(args.args[0], [1,2]); + } + if (nameGetCount === 3) { + assert.strictEqual(args.model, 'res_currency'); + assert.deepEqual(args.args[0], [1]); + } + nameGetCount++; + } + return this._super.apply(this, arguments); + }, + }); + + assert.verifySteps([ + 'web_read_group', + 'name_get', + 'name_get', + ]); + await testUtils.dom.click(list.$('.o_data_row .o_list_record_selector input')[0]); + await testUtils.dom.click(list.$('.o_data_row .o_list_record_selector input')[1]); + await testUtils.dom.click(list.$('.o_data_row .o_list_record_selector input')[2]); + await testUtils.dom.click(list.$('.o_data_row .o_field_boolean')[0]); + assert.containsOnce(document.body, '.modal'); + await testUtils.dom.click($('.modal .modal-footer .btn-primary')); + assert.containsNone(document.body, '.modal'); + assert.verifySteps([ + 'write', + 'read', + 'name_get', + 'name_get', + ]); + assert.containsN(list, '.o_group_header', 2); + + const allNames = Array.from(list.el.querySelectorAll('.o_data_cell')) + .filter(node => !node.children.length).map(n=>n.textContent); + assert.deepEqual(allNames, [ + 'Value 1', + 'Value 2', + 'USD', + 'Value 2', + 'Value 3', + ]); + list.destroy(); + }); + QUnit.test('editable list view: contexts are correctly sent', async function (assert) { assert.expect(6); -- cgit v1.2.3