From d84cfbf9a8be9ddc5f470096bf60da9e848ea96a Mon Sep 17 00:00:00 2001 From: FrancoisGe Date: Tue, 17 Jan 2023 09:23:44 +0000 Subject: [PATCH] [FIX] web: click on "Search More..." with a search_default_... MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, in a form view, from the second opening of a selection dialog by clicking on the "Search More..." button of a many2one with a "search_default_..." in its context opened the selection view without the filter corresponding to the "search_default_...". Why: The search model removes the "search_default_..." keys from the context it is given. Solution: Clone the received context so as not to modify it. How to reproduce: - Go to a form view with a many2one field having in its context "search_default_..." - Click on the m2o - Click on "Search More..." The search dialog opens with the filter corresponding to "search_more_..." - Close the dialog - Click on the m2o - Click on "Search More..." Before this commit: The search dialog opens without the filter corresponding to "search_more_..." After this commit: The search dialog opens with the filter corresponding to "search_more_..." closes odoo/odoo#110342 X-original-commit: 82293c5f4d0955c4688a619bf69e3f0049f10fb6 Signed-off-by: Mathieu Duckerts-Antoine Signed-off-by: Georis François (fge) --- addons/web/static/src/search/search_model.js | 4 +- .../views/fields/many2one_field_tests.js | 66 ++++++++++++++++--- 2 files changed, 60 insertions(+), 10 deletions(-) diff --git a/addons/web/static/src/search/search_model.js b/addons/web/static/src/search/search_model.js index 58e0998953c..2473901accb 100644 --- a/addons/web/static/src/search/search_model.js +++ b/addons/web/static/src/search/search_model.js @@ -215,7 +215,7 @@ export class SearchModel extends EventBus { const { comparison, context, domain, groupBy, hideCustomGroupBy, orderBy } = config; this.globalComparison = comparison; - this.globalContext = toRaw(context || {}); + this.globalContext = toRaw(Object.assign({}, context)); this.globalDomain = domain || []; this.globalGroupBy = groupBy || []; this.globalOrderBy = orderBy || []; @@ -383,7 +383,7 @@ export class SearchModel extends EventBus { const { comparison, context, domain, groupBy, orderBy } = config; - this.globalContext = context || {}; + this.globalContext = Object.assign({}, context); this.globalDomain = domain || []; this.globalComparison = comparison; this.globalGroupBy = groupBy || []; diff --git a/addons/web/static/tests/views/fields/many2one_field_tests.js b/addons/web/static/tests/views/fields/many2one_field_tests.js index 81286693fbf..468520b5a59 100644 --- a/addons/web/static/tests/views/fields/many2one_field_tests.js +++ b/addons/web/static/tests/views/fields/many2one_field_tests.js @@ -1,13 +1,7 @@ /** @odoo-module **/ -import { browser } from "@web/core/browser/browser"; -import { errorService } from "@web/core/errors/error_service"; -import { RPCError } from "@web/core/network/rpc_service"; -import { registry } from "@web/core/registry"; -import { session } from "@web/session"; -import { Field } from "@web/views/fields/field"; -import { Record } from "@web/views/record"; import { registerCleanup } from "@web/../tests/helpers/cleanup"; +import { makeTestEnv } from "@web/../tests/helpers/mock_env"; import { addRow, click, @@ -32,6 +26,7 @@ import { import { applyFilter, editSearch, + getFacetTexts, toggleAddCustomFilter, toggleFilterMenu, toggleGroupByMenu, @@ -39,8 +34,14 @@ import { validateSearch, } from "@web/../tests/search/helpers"; import { makeView, setupViewRegistries } from "@web/../tests/views/helpers"; -import { makeTestEnv } from "@web/../tests/helpers/mock_env"; import { createWebClient, doAction } from "@web/../tests/webclient/helpers"; +import { browser } from "@web/core/browser/browser"; +import { errorService } from "@web/core/errors/error_service"; +import { RPCError } from "@web/core/network/rpc_service"; +import { registry } from "@web/core/registry"; +import { session } from "@web/session"; +import { Field } from "@web/views/fields/field"; +import { Record } from "@web/views/record"; const serviceRegistry = registry.category("services"); @@ -648,6 +649,55 @@ QUnit.module("Fields", (hooks) => { assert.strictEqual($("tr.o_data_row").length, 0, "should display 0 records"); }); + QUnit.test( + "many2ones: Open the selection dialog several times using the 'Search More...' button with a context containing 'search_default_...'", + async function (assert) { + for (let i = 5; i < 11; i++) { + serverData.models.partner.records.push({ id: i, display_name: `Partner ${i}` }); + } + serverData.models.partner.fields.display_name.searchable = true; + serverData.views = { + "partner,false,search": ` + + + `, + "partner,false,list": ` + + + `, + }; + + await makeView({ + type: "form", + resModel: "partner", + resId: 1, + serverData, + arch: ` +
+ + + + + +
`, + }); + + await selectDropdownItem(target, "trululu", "Search More..."); + + let modal = target.querySelector(".modal"); + assert.containsOnce(modal, ".o_data_row", "should display 1 records"); + assert.deepEqual(getFacetTexts(modal), ["Displayed name\nPartner 10"]); + + await click(modal, ".btn-close"); + assert.containsNone(modal, ".modal"); + + await selectDropdownItem(target, "trululu", "Search More..."); + modal = target.querySelector(".modal"); + assert.containsOnce(modal, ".o_data_row", "should display 1 records"); + assert.deepEqual(getFacetTexts(modal), ["Displayed name\nPartner 10"]); + } + ); + QUnit.test( "many2ones in list views: create in dialog keeps the input", async function (assert) {