From 876a82b29974e83105dc7bbbe2c52de214a4aa7a Mon Sep 17 00:00:00 2001 From: Mathieu Duckerts-Antoine Date: Tue, 13 Jun 2023 09:22:44 +0000 Subject: [PATCH] [FIX] web: distribute ! or not MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the domain selector is in debug mode (props.isDebugMode = true), the operator ! (not) is not distributed in the leaves in the domain selector. That is a domain like ["!", "|", ("foo", "=", 1 ), ("id", "=", 2)] will be visualized in the domain selector as Match records with none of the following rules: Foo = 1 ID = 2 The problem we fix is that when such a domain is added via "Add Custom Filter" (for instance), the search bar facet produced has a representation of the domain where ! has been distributed even if the debug mode is active. With the previous example: ------------ ----------- | Foo != 1 | | ID != 2 | ------------ ----------- This makes the user think that the domain she sees is not the domain she has created. In the present commit, we make sure that the ! operator is distributed or not uniformly within the scope of the search model. closes odoo/odoo#125967 X-original-commit: d15d7e13be0ca6f7705c3bb6f992b45949bccef0 Signed-off-by: Michaƫl Mattiello (mcm) Signed-off-by: Mathieu Duckerts-Antoine (dam) --- .../src/search/search_bar/search_bar.js | 2 +- .../search/search_bar_menu/search_bar_menu.js | 2 +- addons/web/static/src/search/search_model.js | 5 +++- .../tests/search/search_bar_menu_tests.js | 29 +++++++++++++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/search/search_bar/search_bar.js b/addons/web/static/src/search/search_bar/search_bar.js index 0e4cc03372e..708743ffa99 100644 --- a/addons/web/static/src/search/search_bar/search_bar.js +++ b/addons/web/static/src/search/search_bar/search_bar.js @@ -379,7 +379,7 @@ export class SearchBar extends Component { onConfirm: (domain) => this.env.searchModel.splitAndAddDomain(domain, groupId), disableConfirmButton: (domain) => domain === `[]`, title: _t("Modify Condition"), - isDebugMode: !!this.env.debug, + isDebugMode: this.env.searchModel.isDebugMode, }); } diff --git a/addons/web/static/src/search/search_bar_menu/search_bar_menu.js b/addons/web/static/src/search/search_bar_menu/search_bar_menu.js index 79f2363e12b..020b70d87e3 100644 --- a/addons/web/static/src/search/search_bar_menu/search_bar_menu.js +++ b/addons/web/static/src/search/search_bar_menu/search_bar_menu.js @@ -75,7 +75,7 @@ export class SearchBarMenu extends Component { title: _t("Add Custom Filter"), confirmButtonText: _t("Add"), discardButtonText: _t("Cancel"), - isDebugMode: !!this.env.debug, + isDebugMode: this.env.searchModel.isDebugMode, }); } diff --git a/addons/web/static/src/search/search_model.js b/addons/web/static/src/search/search_model.js index 4e868591ed1..710f70fd835 100644 --- a/addons/web/static/src/search/search_model.js +++ b/addons/web/static/src/search/search_model.js @@ -677,6 +677,9 @@ export class SearchModel extends EventBus { return deepCopy(this._orderBy); } + get isDebugMode() { + return !!this.env.debug; + } //-------------------------------------------------------------------------- // Public //-------------------------------------------------------------------------- @@ -983,7 +986,7 @@ export class SearchModel extends EventBus { context = makeContext(contexts); } - const tree = toTree(domain); + const tree = toTree(domain, { distributeNot: !this.isDebugMode }); const trees = !tree.negate && tree.value === "&" ? tree.children : [tree]; const promises = trees.map(async (tree) => { const description = await this.getDomainTreeDescription(this.resModel, tree); diff --git a/addons/web/static/tests/search/search_bar_menu_tests.js b/addons/web/static/tests/search/search_bar_menu_tests.js index 048b5bd894c..1039b324fd8 100644 --- a/addons/web/static/tests/search/search_bar_menu_tests.js +++ b/addons/web/static/tests/search/search_bar_menu_tests.js @@ -1703,5 +1703,34 @@ QUnit.module("Search", (hooks) => { assert.deepEqual(getFacetTexts(target), [`ID is between 0 and 10`]); assert.deepEqual(getDomain(controlPanel), ["&", ["id", ">=", 0], ["id", "<=", 10]]); }); + + QUnit.test("consistent display of ! in debug mode", async function (assert) { + patchWithCleanup(odoo, { debug: true }); + + const controlPanel = await makeWithSearch({ + serverData, + resModel: "foo", + Component: SearchBar, + searchMenuTypes: ["filter"], + searchViewId: false, + searchViewArch: ``, + }); + await toggleSearchBarMenu(target); + await openAddCustomFilterDialog(target); + await editInput( + target, + ".o_domain_debug_input", + `["!", "|", ("foo", "=", 1 ), ("id", "=", 2)]` + ); + assert.strictEqual( + target.querySelector(".o_domain_tree_connector_caret").textContent, + "none" + ); + + await click(target.querySelector(".modal footer button")); + + assert.deepEqual(getFacetTexts(target), [`! ( Foo = 1 or ID = 2 )`]); + assert.deepEqual(getDomain(controlPanel), ["!", "|", ["foo", "=", 1], ["id", "=", 2]]); + }); }); });