[IMP] web: searchpanel: use child_of operator for categories
When a category value is selected, we search for records matching this category OR one of its children categories task-1974632 closes: #33701 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com> Co-authored-by: Aaron Bohy <aab@odoo.com>
This commit is contained in:
committed by
Aaron Bohy
co-authored by
Aaron Bohy
parent
8385dc49d4
commit
e264eca71a
@@ -320,7 +320,9 @@ var SearchPanel = Widget.extend({
|
|||||||
function categoryToDomain(domain, categoryId) {
|
function categoryToDomain(domain, categoryId) {
|
||||||
var category = self.categories[categoryId];
|
var category = self.categories[categoryId];
|
||||||
if (category.activeValueId) {
|
if (category.activeValueId) {
|
||||||
domain.push([category.fieldName, '=', category.activeValueId]);
|
var field = self.fields[category.fieldName];
|
||||||
|
var op = field.type === 'many2one' ? 'child_of' : '=';
|
||||||
|
domain.push([category.fieldName, op, category.activeValueId]);
|
||||||
}
|
}
|
||||||
return domain;
|
return domain;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -382,6 +382,24 @@ var MockServer = Class.extend({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (domain.length) {
|
if (domain.length) {
|
||||||
|
// 'child_of' operator isn't supported by domain.js, so we replace
|
||||||
|
// in by the 'in' operator (with the ids of children)
|
||||||
|
domain = domain.map(function (criterion) {
|
||||||
|
if (criterion[1] === 'child_of') {
|
||||||
|
var oldLength = 0;
|
||||||
|
var childIDs = [criterion[2]];
|
||||||
|
while (childIDs.length > oldLength) {
|
||||||
|
oldLength = childIDs.length;
|
||||||
|
_.each(records, function (r) {
|
||||||
|
if (childIDs.indexOf(r.parent_id) >= 0) {
|
||||||
|
childIDs.push(r.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
criterion = [criterion[0], 'in', childIDs];
|
||||||
|
}
|
||||||
|
return criterion;
|
||||||
|
});
|
||||||
records = _.filter(records, function (record) {
|
records = _.filter(records, function (record) {
|
||||||
var fieldValues = _.mapObject(record, function (value) {
|
var fieldValues = _.mapObject(record, function (value) {
|
||||||
return value instanceof Array ? value[0] : value;
|
return value instanceof Array ? value[0] : value;
|
||||||
|
|||||||
@@ -298,8 +298,8 @@ QUnit.module('Views', {
|
|||||||
|
|
||||||
assert.verifySteps([
|
assert.verifySteps([
|
||||||
'[["bar","=",true]]',
|
'[["bar","=",true]]',
|
||||||
'[["bar","=",true],["company_id","=",3]]',
|
'[["bar","=",true],["company_id","child_of",3]]',
|
||||||
'[["bar","=",true],["company_id","=",5]]',
|
'[["bar","=",true],["company_id","child_of",5]]',
|
||||||
'[["bar","=",true]]',
|
'[["bar","=",true]]',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -399,7 +399,7 @@ QUnit.module('Views', {
|
|||||||
'</kanban>',
|
'</kanban>',
|
||||||
mockRPC: function (route, args) {
|
mockRPC: function (route, args) {
|
||||||
if (route === '/web/dataset/search_read') {
|
if (route === '/web/dataset/search_read') {
|
||||||
assert.deepEqual(args.domain, [['company_id', '=', expectedActiveId]]);
|
assert.deepEqual(args.domain, [['company_id', 'child_of', expectedActiveId]]);
|
||||||
}
|
}
|
||||||
return this._super.apply(this, arguments);
|
return this._super.apply(this, arguments);
|
||||||
},
|
},
|
||||||
@@ -523,9 +523,9 @@ QUnit.module('Views', {
|
|||||||
|
|
||||||
assert.verifySteps([
|
assert.verifySteps([
|
||||||
'[["bar","=",true]]',
|
'[["bar","=",true]]',
|
||||||
'[["bar","=",true],["company_id","=",3]]',
|
'[["bar","=",true],["company_id","child_of",3]]',
|
||||||
'[["bar","=",true],["company_id","=",3],["state","=","abc"]]',
|
'[["bar","=",true],["company_id","child_of",3],["state","=","abc"]]',
|
||||||
'[["bar","=",true],["company_id","=",3],["state","=","ghi"]]',
|
'[["bar","=",true],["company_id","child_of",3],["state","=","ghi"]]',
|
||||||
'[["bar","=",true],["state","=","ghi"]]',
|
'[["bar","=",true],["state","=","ghi"]]',
|
||||||
'[["bar","=",true]]',
|
'[["bar","=",true]]',
|
||||||
]);
|
]);
|
||||||
@@ -610,8 +610,8 @@ QUnit.module('Views', {
|
|||||||
|
|
||||||
assert.verifySteps([
|
assert.verifySteps([
|
||||||
'[]',
|
'[]',
|
||||||
'[["company_id","=",40]]',
|
'[["company_id","child_of",40]]',
|
||||||
'[["company_id","=",5]]',
|
'[["company_id","child_of",5]]',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
kanban.destroy();
|
kanban.destroy();
|
||||||
@@ -772,8 +772,8 @@ QUnit.module('Views', {
|
|||||||
|
|
||||||
assert.verifySteps([
|
assert.verifySteps([
|
||||||
'[["bar","=",true]]',
|
'[["bar","=",true]]',
|
||||||
'[["bar","=",true],["company_id","=",3]]',
|
'[["bar","=",true],["company_id","child_of",3]]',
|
||||||
'[["bar","=",true],["company_id","=",5]]',
|
'[["bar","=",true],["company_id","child_of",5]]',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
kanban.destroy();
|
kanban.destroy();
|
||||||
@@ -1438,9 +1438,9 @@ QUnit.module('Views', {
|
|||||||
assert.verifySteps([
|
assert.verifySteps([
|
||||||
'[]', // category_domain (All)
|
'[]', // category_domain (All)
|
||||||
'[["category_id","=",false]]', // comodel_domain (All)
|
'[["category_id","=",false]]', // comodel_domain (All)
|
||||||
'[["category_id","=",6]]', // category_domain ('gold')
|
'[["category_id","child_of",6]]', // category_domain ('gold')
|
||||||
'[["category_id","=",6]]', // comodel_domain ('gold')
|
'[["category_id","=",6]]', // comodel_domain ('gold')
|
||||||
'[["category_id","=",7]]', // category_domain ('silver')
|
'[["category_id","child_of",7]]', // category_domain ('silver')
|
||||||
'[["category_id","=",7]]', // comodel_domain ('silver')
|
'[["category_id","=",7]]', // comodel_domain ('silver')
|
||||||
'[]', // category_domain (All)
|
'[]', // category_domain (All)
|
||||||
'[["category_id","=",false]]', // comodel_domain (All)
|
'[["category_id","=",false]]', // comodel_domain (All)
|
||||||
|
|||||||
Reference in New Issue
Block a user