From 923701851e61755a2d0a4df6121fe9b684e13df2 Mon Sep 17 00:00:00 2001 From: Thanh Dodeur Date: Tue, 30 Apr 2019 10:43:24 +0000 Subject: [PATCH] [IMP] web: conserves record order in the search panel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After this commit, the order of the elements of the search panel categories follow the original order received from the back-end. This is achieved by getting the order from the Array received from the backend instead of the dictionary used to store the record data. Task: #1972698 closes odoo/odoo#33358 Signed-off-by: Alexandre Kühn (aku) --- .../src/js/views/kanban/search_panel.js | 14 +++++---- .../static/tests/views/search_panel_tests.js | 30 +++++++++++++++++++ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/addons/web/static/src/js/views/kanban/search_panel.js b/addons/web/static/src/js/views/kanban/search_panel.js index c3e67032d73..0372d7743a8 100644 --- a/addons/web/static/src/js/views/kanban/search_panel.js +++ b/addons/web/static/src/js/views/kanban/search_panel.js @@ -131,22 +131,24 @@ var SearchPanel = Widget.extend({ var parentField = category.parentField; category.values = {}; - values.forEach(function (value) { + _.each(values, function (value) { category.values[value.id] = _.extend({}, value, { childrenIds: [], folded: true, parentId: value[parentField] && value[parentField][0] || false, }); }); - Object.keys(category.values).forEach(function (valueId) { - var value = category.values[valueId]; + _.map(values, function (value) { + var value = category.values[value.id]; if (value.parentId) { category.values[value.parentId].childrenIds.push(value.id); } }); - category.rootIds = Object.keys(category.values).filter(function (valueId) { - var value = category.values[valueId]; - return value.parentId === false; + category.rootIds = _.filter(_.map(values, function (value) { + return value.id; + }), function (valueId) { + var value = category.values[valueId]; + return value.parentId === false; }); // set active value diff --git a/addons/web/static/tests/views/search_panel_tests.js b/addons/web/static/tests/views/search_panel_tests.js index f564ccc0d6b..5676ab72a95 100644 --- a/addons/web/static/tests/views/search_panel_tests.js +++ b/addons/web/static/tests/views/search_panel_tests.js @@ -1556,6 +1556,36 @@ QUnit.module('Views', { kanban.destroy(); }); + + QUnit.test('tests conservation of category record order', async function (assert) { + assert.expect(1); + + this.data.company.records.push({id: 56, name: 'highID', category_id: 6}); + this.data.company.records.push({id: 2, name: 'lowID', category_id: 6}); + + var kanban = await createView({ + View: KanbanView, + model: 'partner', + data: this.data, + services: this.services, + arch: '' + + '' + + '
' + + '' + + '
' + + '
' + + '' + + '' + + '' + + '' + + '
', + }); + + var $firstSection = kanban.$('.o_search_panel_section:first'); + assert.strictEqual($firstSection.find('.o_search_panel_category_value').text().replace(/\s/g, ''), + 'AllasustekagrolaithighIDlowID'); + kanban.destroy(); + }); }); });