diff --git a/addons/web/static/src/js/control_panel/control_panel_model.js b/addons/web/static/src/js/control_panel/control_panel_model.js
index 67b9c999f74..a9500999793 100644
--- a/addons/web/static/src/js/control_panel/control_panel_model.js
+++ b/addons/web/static/src/js/control_panel/control_panel_model.js
@@ -544,23 +544,13 @@ odoo.define('web.ControlPanelModel', function (require) {
* @private
*/
_activateDefaultFilters() {
- const defaultFilters = [];
- const defaultFavorites = [];
- for (const fId in this.state.filters) {
- if (this.state.filters[fId].isDefault) {
- if (this.state.filters[fId].type === 'favorite') {
- defaultFavorites.push(this.state.filters[fId]);
- } else {
- defaultFilters.push(this.state.filters[fId]);
- }
- }
- }
- if (this.activateDefaultFavorite && defaultFavorites.length) {
+ if (this.defaultFavoriteId) {
// Activate default favorite
- this.toggleFilter(defaultFavorites[0].id);
+ this.toggleFilter(this.defaultFavoriteId);
} else {
// Activate default filters
- defaultFilters
+ Object.values(this.state.filters)
+ .filter((f) => f.isDefault && f.type !== 'favorite')
.sort((f1, f2) => (f1.defaultRank || 100) - (f2.defaultRank || 100))
.forEach(f => {
if (f.hasOptions) {
@@ -589,9 +579,9 @@ odoo.define('web.ControlPanelModel', function (require) {
* @private
*/
_addFilters() {
+ this._createGroupOfFavorites();
this._createGroupOfFiltersFromArch();
this._createGroupOfDynamicFilters();
- this._createGroupOfFavorites();
}
/**
@@ -707,6 +697,9 @@ odoo.define('web.ControlPanelModel', function (require) {
this.favoriteFilters.forEach(irFilter => {
const favorite = this._irFilterToFavorite(irFilter);
this._createGroupOfFilters([favorite]);
+ if (this.activateDefaultFavorite && favorite.isDefault) {
+ this.defaultFavoriteId = favorite.id;
+ }
});
}
@@ -721,7 +714,7 @@ odoo.define('web.ControlPanelModel', function (require) {
pregroup.forEach(preFilter => {
const filter = Object.assign(preFilter, { groupId, id: filterId });
this.state.filters[filterId] = filter;
- if (filter.isDefault && filter.type === 'field') {
+ if (!this.defaultFavoriteId && filter.isDefault && filter.type === 'field') {
this._prepareDefaultLabel(filter);
}
filterId++;
diff --git a/addons/web/static/tests/control_panel/control_panel_model_tests.js b/addons/web/static/tests/control_panel/control_panel_model_tests.js
index fb73a58dce6..211912d8ac2 100644
--- a/addons/web/static/tests/control_panel/control_panel_model_tests.js
+++ b/addons/web/static/tests/control_panel/control_panel_model_tests.js
@@ -4,9 +4,9 @@ odoo.define('web.control_panel_model_tests', function (require) {
const ControlPanelModel = require('web.ControlPanelModel');
const makeTestEnvironment = require('web.test_env');
- function createControlPanelModel(config = {}) {
+ function createControlPanelModel(config = {}, env, rpc) {
return new ControlPanelModel(Object.assign(
- { env: makeTestEnvironment() },
+ { env: makeTestEnvironment(env, rpc) },
config
));
}
@@ -356,5 +356,72 @@ odoo.define('web.control_panel_model_tests', function (require) {
});
+ QUnit.test('search default field many2one with filter domain', async function (assert) {
+ assert.expect(3);
+
+ const actionContext = {
+ search_default_bar: 20,
+ };
+ const arch = `
+
+
+ `;
+ const fields = this.fields;
+ const model = createControlPanelModel(
+ { viewInfo: { arch, fields }, actionContext }, {},
+ async function mockRPC(route, params) {
+ assert.deepEqual(params, {
+ args: [20],
+ kwargs: {},
+ method: "name_get",
+ model: "partner",
+ });
+ return [[20, "Gandalf"]];
+ }
+ );
+
+ // Labels not fetched: self = undefined
+ assert.throws(() => model.getQuery());
+
+ await model.isReady;
+
+ // Labels fetched: domain should be ready
+ assert.deepEqual(model.getQuery().domain, [["bar", "ilike", "Gandalf"]]);
+ });
+
+ QUnit.test('search default field many2one with filter domain and default favorite', async function (assert) {
+ assert.expect(2);
+
+ const actionContext = {
+ search_default_bar: 20,
+ };
+ const arch = `
+
+
+ `;
+ const favoriteFilters = [{
+ domain: "[('user_id', '=', uid)]",
+ id: 5,
+ is_default: true,
+ name: 'Sorted filter',
+ user_id: [2, "Mitchell Admin"],
+ }];
+ const fields = this.fields;
+ const model = createControlPanelModel(
+ { viewInfo: { arch, favoriteFilters, fields }, actionContext },
+ { session: { user_context: { uid: 2 } } },
+ async function mockRPC() {
+ throw new Error("There should be no name_get");
+ }
+ );
+
+ // Labels not fetched, but favorite overrides search_default
+ assert.deepEqual(model.getQuery().domain, [["user_id", "=", 2]]);
+
+ await model.isReady;
+
+ // domain should be the same
+ assert.deepEqual(model.getQuery().domain, [["user_id", "=", 2]]);
+ });
});
});