[FIX] web: search panel handles archived parent category
Have a model with a parent field Set his parents like Parent 0 | -- Parent 1 | -- Parent 2 Now, put the Parent 1 as inactive Open a view with a search panel, which will fetch the parent field as categories Before this commit, it crashed, because the inner record memory did not contain a reference to the parent of Parent 2 After this commit, it doesn't crash, and the search panel just doesn't display parents categories that are archived, nor any children of those OPW 2070266 closes odoo/odoo#36699 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
@@ -140,8 +140,9 @@ var SearchPanel = Widget.extend({
|
||||
});
|
||||
Object.keys(category.values).forEach(function (valueId) {
|
||||
var value = category.values[valueId];
|
||||
if (value.parentId) {
|
||||
category.values[value.parentId].childrenIds.push(value.id);
|
||||
var parentCategoryId = value.parentId;
|
||||
if (parentCategoryId && parentCategoryId in category.values) {
|
||||
category.values[parentCategoryId].childrenIds.push(value.id);
|
||||
}
|
||||
});
|
||||
category.rootIds = Object.keys(category.values).filter(function (valueId) {
|
||||
|
||||
@@ -470,6 +470,61 @@ QUnit.module('Views', {
|
||||
kanban.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('category has been archived', async function (assert) {
|
||||
assert.expect(2);
|
||||
|
||||
this.data.company.fields.active = {type: 'boolean', string: 'Archived'};
|
||||
this.data.company.records = [
|
||||
{
|
||||
name: 'Company 5',
|
||||
id: 5,
|
||||
active: true,
|
||||
}, {
|
||||
name: 'child of 5 archived',
|
||||
parent_id: 5,
|
||||
id: 666,
|
||||
active: false,
|
||||
}, {
|
||||
name: 'child of 666',
|
||||
parent_id: 666,
|
||||
id: 777,
|
||||
active: true,
|
||||
}
|
||||
];
|
||||
|
||||
var kanban = await createView({
|
||||
View: KanbanView,
|
||||
model: 'partner',
|
||||
data: this.data,
|
||||
arch: '<kanban>' +
|
||||
'<templates><t t-name="kanban-box">' +
|
||||
'<div>' +
|
||||
'<field name="foo"/>' +
|
||||
'</div>' +
|
||||
'</t></templates>' +
|
||||
'<searchpanel>' +
|
||||
'<field name="company_id"/>' +
|
||||
'</searchpanel>' +
|
||||
'</kanban>',
|
||||
mockRPC: async function (route, args) {
|
||||
if (route === '/web/dataset/call_kw/partner/search_panel_select_range') {
|
||||
var results = await this._super.apply(this, arguments);
|
||||
results.values = results.values.filter(rec => rec.active !== false);
|
||||
return Promise.resolve(results);
|
||||
}
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
});
|
||||
|
||||
assert.containsN(kanban, '.o_search_panel_category_value', 2,
|
||||
'The number of categories shold be 2: All and Company 5');
|
||||
|
||||
assert.containsNone(kanban, '.o_toggle_fold',
|
||||
'None of the categories should have children');
|
||||
|
||||
kanban.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('use two categories to refine search', async function (assert) {
|
||||
assert.expect(14);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user