[IMP] crm: correctly combine domains for lead forecast facets

The `forecast_filter` facet (aka Upcoming Closings) would have been combined
with other filters from the same group with a logical 'AND' while displaying an
'OR' combination. Fortunately it is currently the only item of its group so it
does not cause a problem.

This commit fix the inconsistency so that `forecast_filter` using the
forecast_search_model won't have this issue in the future.

Task-2657578

closes odoo/odoo#109996

Signed-off-by: Warnon Aurélien (awa) <awa@odoo.com>
This commit is contained in:
abd-msyukyu-odoo
2023-01-20 20:58:26 +01:00
parent 6df5488ecf
commit 14d68b775f
2 changed files with 38 additions and 34 deletions
@@ -28,34 +28,22 @@ export class ForecastSearchModel extends SearchModel {
/**
* @override
*/
_getDomain(params = {}) {
const domain = super._getDomain(...arguments);
const forecastField = this.globalContext.forecast_field;
if (!forecastField) {
return domain;
_getSearchItemDomain(activeItem) {
let domain = super._getSearchItemDomain(activeItem);
const { searchItemId } = activeItem;
const searchItem = this.searchItems[searchItemId];
const context = makeContext([searchItem.context || {}]);
if (context.forecast_filter) {
const forecastField = this.globalContext.forecast_field;
const forecastStart = this._getForecastStart(forecastField);
const forecastDomain = [
"|",
[forecastField, "=", false],
[forecastField, ">=", forecastStart],
];
domain = Domain.and([domain, forecastDomain]);
}
let forecastFilter = false;
for (const queryElem of this.query) {
const searchItem = this.searchItems[queryElem.searchItemId];
if (searchItem.type === "filter") {
const context = makeContext([searchItem.context || {}]);
if (context.forecast_filter) {
forecastFilter = true;
break;
}
}
}
if (!forecastFilter) {
return domain;
}
const forecastStart = this._getForecastStart(forecastField);
const forecastDomain = [
"|",
[forecastField, "=", false],
[forecastField, ">=", forecastStart],
];
const fullDomain = Domain.and([domain, forecastDomain]);
return params.raw ? fullDomain : fullDomain.toList();
return domain;
}
/**
+23 -7
View File
@@ -43,6 +43,18 @@ QUnit.module("Views", (hooks) => {
store: true,
sortable: true,
},
value: {
string: "Value",
type: "float",
store: true,
sortable: true,
},
number: {
string: "Number",
type: "integer",
store: true,
sortable: true,
}
},
records: [],
},
@@ -118,7 +130,7 @@ QUnit.module("Views", (hooks) => {
});
QUnit.test(
"forecast filter domain is combined with other domains with an AND",
"forecast filter domain is combined with other domains following the same rules as other filters (OR in same group, AND between groups)",
async function (assert) {
assert.expect(1);
@@ -126,8 +138,10 @@ QUnit.module("Views", (hooks) => {
serverData.views["foo,false,search"] = `
<search>
<filter name="other_filter" string="Other Filter" domain="[('bar', '=', 2)]"/>
<filter name="forecast_filter" string="Forecast Filter" context="{ 'forecast_filter': 1 }"/>
<filter name="other_group_filter" string="Other Group Filter" domain="[('number', '>', 2)]"/>
<separator/>
<filter name="same_group_filter" string="Same Group Filter" domain="[('bar', '=', 2)]"/>
<filter name="forecast_filter" string="Forecast Filter" context="{ 'forecast_filter': 1 }" domain="[('value', '>', 0.0)]"/>
</search>
`;
@@ -137,8 +151,9 @@ QUnit.module("Views", (hooks) => {
serverData,
searchViewId: false,
context: {
search_default_other_filter: 1,
search_default_same_group_filter: 1,
search_default_forecast_filter: 1,
search_default_other_group_filter: 1,
forecast_field: "date_field",
},
mockRPC(_, args) {
@@ -146,7 +161,11 @@ QUnit.module("Views", (hooks) => {
const { domain } = args.kwargs;
assert.deepEqual(domain, [
"&",
["number", ">", 2],
"|",
["bar", "=", 2],
"&",
["value", ">", 0.0],
"|",
["date_field", "=", false],
["date_field", ">=", "2021-09-01"],
@@ -155,9 +174,6 @@ QUnit.module("Views", (hooks) => {
},
});
// note that the facets of the two filters are combined with an OR.
// --> current behavior in legacy
unpatchDate();
}
);