diff --git a/addons/web/static/src/js/views/search_panel_model_extension.js b/addons/web/static/src/js/views/search_panel_model_extension.js index a5103f97447..48466f8d9e7 100644 --- a/addons/web/static/src/js/views/search_panel_model_extension.js +++ b/addons/web/static/src/js/views/search_panel_model_extension.js @@ -410,6 +410,8 @@ odoo.define("web/static/src/js/views/search_panel_model_extension.js", function * @private */ _createSectionsFromArch() { + let hasCategoryWithCounters = false; + let hasFilterWithDomain = false; this.config.archNodes.forEach(({ attrs, tag }, index) => { if (tag !== "field" || attrs.invisible === "1") { return; @@ -444,13 +446,33 @@ odoo.define("web/static/src/js/views/search_panel_model_extension.js", function bold: true, parentId: false, }); + hasCategoryWithCounters = hasCategoryWithCounters || section.enableCounters; } else { section.domain = attrs.domain || "[]"; section.groupBy = attrs.groupby; section.icon = section.icon || "fa-filter"; + hasFilterWithDomain = hasFilterWithDomain || section.domain !== "[]"; } this.state.sections.set(section.id, section); }); + /** + * Category counters are automatically disabled if a filter domain is found + * to avoid inconsistencies with the counters. The underlying problem could + * actually be solved by reworking the search panel and the way the + * counters are computed, though this is not the current priority + * considering the time it would take, hence this quick "fix". + */ + if (hasCategoryWithCounters && hasFilterWithDomain) { + // If incompatibilities are found -> disables all category counters + for (const category of this.categories) { + category.enableCounters = false; + } + // ... and triggers a warning + console.warn( + "Warning: categories with counters are incompatible with filters having a domain attribute.", + "All category counters have been disabled to avoid inconsistencies.", + ); + } } /** diff --git a/addons/web/static/tests/views/search_panel_tests.js b/addons/web/static/tests/views/search_panel_tests.js index 6adc4797491..123271d1151 100644 --- a/addons/web/static/tests/views/search_panel_tests.js +++ b/addons/web/static/tests/views/search_panel_tests.js @@ -3,6 +3,7 @@ odoo.define("web/static/tests/views/search_panel_tests.js", function (require) { const FormView = require('web.FormView'); const KanbanView = require('web.KanbanView'); +const ListView = require('web.ListView'); const testUtils = require('web.test_utils'); const SearchPanel = require("web/static/src/js/views/search_panel.js"); @@ -4136,5 +4137,35 @@ QUnit.module('Views', { kanban.destroy(); }); + + QUnit.test("Category with counters and filter with domain", async function (assert) { + assert.expect(2); + + const list = await createView({ + arch: '', + archs: { + 'partner,false,search': ` + + + + + + `, + }, + data: this.data, + model: "partner", + services: this.services, + View: ListView, + }); + + assert.containsN(list, ".o_data_row", 4); + assert.strictEqual( + list.$(".o_search_panel_category_value").text().replace(/\s/g, ""), + "Allgoldsilver", + "Category counters should be empty if a filter has a domain attribute" + ); + + list.destroy(); + }); }); }); diff --git a/doc/reference/views.rst b/doc/reference/views.rst index ba23941bbe9..d2e4be8ffad 100644 --- a/doc/reference/views.rst +++ b/doc/reference/views.rst @@ -2038,6 +2038,8 @@ Possible children elements of the search view are: A domain might be used to express a dependency on another field (with select="one") of the search panel. Consider + /!\ This attribute is incompatible with a select="one" with enabled counters; if a select="multi" + has a `domain` attribute, all select="one" will have their counters disabled. .. code-block:: xml