[FIX] web: visual separation of search items
Since the refactoring of the views aeb8e49972f871b0c9b07c507987ee77cf5e8abbd, the filters and date filters, the groupbys and date groupbys are now always separated visually even if no separator/group tag has been set in the search arch. We restablish the previous behavior that only seperates them when a separator/group is set. closes odoo/odoo#82418 X-original-commit: e281bd0850e935ce0d97226366114da4f5406c4d Signed-off-by: Samuel Degueldre <sad@odoo.com>
This commit is contained in:
@@ -25,6 +25,16 @@ const getContextGroubBy = (context) => {
|
||||
}
|
||||
};
|
||||
|
||||
function reduceType(type) {
|
||||
if (type === "dateFilter") {
|
||||
return "filter";
|
||||
}
|
||||
if (type === "dateGroupBy") {
|
||||
return "groupBy";
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
export class SearchArchParser extends XMLParser {
|
||||
constructor(searchViewDescription, searchDefaults = {}, searchPanelDefaults = {}) {
|
||||
super();
|
||||
@@ -86,7 +96,7 @@ export class SearchArchParser extends XMLParser {
|
||||
|
||||
pushGroup(tag = null) {
|
||||
if (this.currentGroup.length) {
|
||||
if (this.currentTag && ["groupBy", "dateGroupBy"].includes(this.currentTag)) {
|
||||
if (this.currentTag === "groupBy") {
|
||||
this.pregroupOfGroupBys.push(...this.currentGroup);
|
||||
} else {
|
||||
this.preSearchItems.push(this.currentGroup);
|
||||
@@ -189,8 +199,8 @@ export class SearchArchParser extends XMLParser {
|
||||
preSearchItem.context = context;
|
||||
}
|
||||
}
|
||||
if (preSearchItem.type !== this.currentTag) {
|
||||
this.pushGroup(preSearchItem.type);
|
||||
if (reduceType(preSearchItem.type) !== this.currentTag) {
|
||||
this.pushGroup(reduceType(preSearchItem.type));
|
||||
}
|
||||
if (preSearchItem.type === "filter") {
|
||||
if (node.hasAttribute("date")) {
|
||||
|
||||
@@ -530,6 +530,66 @@ QUnit.module("Search", (hooks) => {
|
||||
]);
|
||||
});
|
||||
|
||||
QUnit.test("parsing a filter and a dateFilter", async function (assert) {
|
||||
assert.expect(1);
|
||||
const model = await makeSearchModel({
|
||||
serverData,
|
||||
searchViewArch: `
|
||||
<search>
|
||||
<filter name="filter" string="Filter" domain="[['foo', '=', 'a']]"/>
|
||||
<filter name="date_filter" string="Date" date="date_field"/>
|
||||
</search>
|
||||
`,
|
||||
});
|
||||
const groupNumbers = model.getSearchItems(() => true).map((i) => i.groupNumber);
|
||||
assert.deepEqual(groupNumbers, [1, 1]);
|
||||
});
|
||||
|
||||
QUnit.test("parsing a groupBy and a dateGroupBy", async function (assert) {
|
||||
assert.expect(1);
|
||||
const model = await makeSearchModel({
|
||||
serverData,
|
||||
searchViewArch: `
|
||||
<search>
|
||||
<filter name="group_by" context="{ 'group_by': 'foo'}"/>
|
||||
<filter name="date_groupBy" string="DateGroupBy" context="{'group_by': 'date_field:day'}"/>
|
||||
</search>
|
||||
`,
|
||||
});
|
||||
const groupNumbers = model.getSearchItems(() => true).map((i) => i.groupNumber);
|
||||
assert.deepEqual(groupNumbers, [1, 1]);
|
||||
});
|
||||
|
||||
QUnit.test("parsing a filter and a groupBy", async function (assert) {
|
||||
assert.expect(1);
|
||||
const model = await makeSearchModel({
|
||||
serverData,
|
||||
searchViewArch: `
|
||||
<search>
|
||||
<filter name="filter" string="Filter" domain="[['foo', '=', 'a']]"/>
|
||||
<filter name="group_by" context="{ 'group_by': 'foo'}"/>
|
||||
</search>
|
||||
`,
|
||||
});
|
||||
const groupNumbers = model.getSearchItems(() => true).map((i) => i.groupNumber);
|
||||
assert.deepEqual(groupNumbers, [1, 2]);
|
||||
});
|
||||
|
||||
QUnit.test("parsing a groupBy and a filter", async function (assert) {
|
||||
assert.expect(1);
|
||||
const model = await makeSearchModel({
|
||||
serverData,
|
||||
searchViewArch: `
|
||||
<search>
|
||||
<filter name="group_by" context="{ 'group_by': 'foo'}"/>
|
||||
<filter name="filter" string="Filter" domain="[['foo', '=', 'a']]"/>
|
||||
</search>
|
||||
`,
|
||||
});
|
||||
const groupNumbers = model.getSearchItems(() => true).map((i) => i.groupNumber);
|
||||
assert.deepEqual(groupNumbers, [2, 1]);
|
||||
});
|
||||
|
||||
QUnit.test("process search default group by", async function (assert) {
|
||||
assert.expect(1);
|
||||
const model = await makeSearchModel({
|
||||
|
||||
Reference in New Issue
Block a user