[IMP] web: conserves record order in the search panel

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) <aku@odoo.com>
This commit is contained in:
Thanh Dodeur
2019-05-21 10:33:52 +00:00
parent 42c41052de
commit 923701851e
2 changed files with 38 additions and 6 deletions
@@ -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
@@ -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: '<kanban>' +
'<templates><t t-name="kanban-box">' +
'<div>' +
'<field name="foo"/>' +
'</div>' +
'</t></templates>' +
'<searchpanel>' +
'<field name="company_id"/>' +
'<field select="multi" name="category_id"/>' +
'</searchpanel>' +
'</kanban>',
});
var $firstSection = kanban.$('.o_search_panel_section:first');
assert.strictEqual($firstSection.find('.o_search_panel_category_value').text().replace(/\s/g, ''),
'AllasustekagrolaithighIDlowID');
kanban.destroy();
});
});
});