diff --git a/addons/crm/static/src/views/forecast_search_model.js b/addons/crm/static/src/views/forecast_search_model.js index 1bc76c64820..2b160f67fe7 100644 --- a/addons/crm/static/src/views/forecast_search_model.js +++ b/addons/crm/static/src/views/forecast_search_model.js @@ -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; } /** diff --git a/addons/crm/static/tests/forecast_view_tests.js b/addons/crm/static/tests/forecast_view_tests.js index a139d69428d..c9e3fedd78e 100644 --- a/addons/crm/static/tests/forecast_view_tests.js +++ b/addons/crm/static/tests/forecast_view_tests.js @@ -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"] = ` - - + + + + `; @@ -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(); } );