summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorJulien Mougenot <jum@odoo.com>2020-08-10 12:10:01 +0000
committerJulien Mougenot <jum@odoo.com>2020-08-11 10:12:15 +0000
commitc00e76b67c424498e29c4a82f6536084c3539b13 (patch)
treeb22f0a573b4e09b9c73b6af53c435bfefd68adce /addons
parent2f0bf44c7a1ef2354fa6a0b87b1f380fa161305b (diff)
[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>
Diffstat (limited to 'addons')
-rw-r--r--addons/web/static/src/js/views/search_panel_model_extension.js22
-rw-r--r--addons/web/static/tests/views/search_panel_tests.js31
2 files changed, 53 insertions, 0 deletions
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: '<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();
+ });
});
});