[FIX] web: Filter with domain disables category counters
Before this commit, the search panel was subject to some inconsistencies when dealing with a category having enabled counters and with a filter defining a "domain" attribute. Indeed, the counters could be in an incorrect state if the right filters/categories were not loaded first, with no simple way in doing so. The search panel being complex enough as it is, we decided to disable all categories' counters in the presence of a filter having a "domain" attribute regardless of said domain. closes odoo/odoo#55734 X-original-commit: e78f777bd8ccb314b85451cbc8d1dd9109997d7a Related: odoo/enterprise#12341 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
@@ -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.",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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: '<tree><field name="foo"/></tree>',
|
||||
archs: {
|
||||
'partner,false,search': `
|
||||
<search>
|
||||
<searchpanel>
|
||||
<field name="category_id" enable_counters="1"/>
|
||||
<field name="company_id" select="multi" domain="[['category_id', '=', category_id]]"/>
|
||||
</searchpanel>
|
||||
</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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user