From 37dfb6d12e3a5f679ae9834ebb2de9ccccd8fe14 Mon Sep 17 00:00:00 2001 From: "Thomas Lefebvre (thle)" Date: Fri, 21 Oct 2022 13:31:20 +0000 Subject: [PATCH] [FIX] web: placing the domain in the kwargs of an rpc call Steps to reproduce: - go to Contacts app; - add a reporting view (Graph, Pivot or Dashboard) (with studio for example) - tape any character in the search bar; - on "search related company for" field either use the arrow keys to go down to this and then click the right arrow key or click on the triangle to the left of this field. Issue: An error occurs. Cause: There is a mismatch between the parameters that are sent by the rpc call and those processed by the logic part. Specifically, the domain must be part of the kwargs and not the args of the params key in the rpc call. The problem occurs with a filter that looks like: `` Solution: Move domain in kwargs under key named args in the params of the rpc call. opw-3031096 closes odoo/odoo#106074 X-original-commit: 8a9b418b27dcc9b904413f14cd0443f9a5b10d17 Signed-off-by: Mathieu Duckerts-Antoine Signed-off-by: Lefebvre Thomas (thle) --- .../src/search/search_bar/search_bar.js | 3 +- .../static/tests/search/search_bar_tests.js | 55 ++++++++++++++++++- 2 files changed, 55 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 0196f63af3d..16a2426a081 100644 --- a/addons/web/static/src/search/search_bar/search_bar.js +++ b/addons/web/static/src/search/search_bar/search_bar.js @@ -189,7 +189,8 @@ export class SearchBar extends Component { // Pass } } - const options = await this.orm.call(field.relation, "name_search", domain, { + const options = await this.orm.call(field.relation, "name_search", [], { + args: domain, context: field.context, limit: 8, name: query.trim(), diff --git a/addons/web/static/tests/search/search_bar_tests.js b/addons/web/static/tests/search/search_bar_tests.js index 9c0d06df15b..239f54679f2 100644 --- a/addons/web/static/tests/search/search_bar_tests.js +++ b/addons/web/static/tests/search/search_bar_tests.js @@ -38,6 +38,7 @@ QUnit.module("Search", (hooks) => { birth_datetime: { string: "Birth DateTime", type: "datetime" }, foo: { string: "Foo", type: "char" }, bool: { string: "Bool", type: "boolean" }, + company: { string: "Company", type: "many2one", relation: "partner" }, }, records: [ { @@ -57,6 +58,7 @@ QUnit.module("Search", (hooks) => { bool: false, birthday: "1982-06-04", birth_datetime: "1982-06-04 02:00:00", + company: 1, }, { id: 3, @@ -66,6 +68,7 @@ QUnit.module("Search", (hooks) => { bool: false, birthday: "1985-09-13", birth_datetime: "1985-09-13 03:00:00", + company: 5, }, { id: 4, @@ -96,6 +99,7 @@ QUnit.module("Search", (hooks) => { + @@ -315,8 +319,8 @@ QUnit.module("Search", (hooks) => { assert.containsN( target, ".o_searchview_autocomplete li", - 2, - "there should be 2 result for 'a' in search bar autocomplete" + 3, + "there should be 3 result for 'a' in search bar autocomplete" ); const searchInput = target.querySelector(".o_searchview input"); @@ -947,4 +951,51 @@ QUnit.module("Search", (hooks) => { await validateSearch(target); assert.deepEqual(getDomain(controlPanel), [["foo", "ilike", "1a"]]); }); + + QUnit.test("check kwargs of a rpc call with a domain", async function (assert) { + assert.expect(3); + + const mockRPC = async (route, args) => { + if (route.includes("/partner/name_search")) { + assert.deepEqual(args, { + model: "partner", + method: "name_search", + args: [], + kwargs: { + args: [["bool", "=", true]], + context: { lang: "en", uid: 7, tz: "taht" }, + limit: 8, + name: "F", + }, + }); + } + }; + + const controlPanel = await makeWithSearch({ + serverData, + mockRPC, + resModel: "partner", + Component: ControlPanel, + searchMenuTypes: [], + searchViewId: false, + }); + + await editSearch(target, "F"); + assert.containsN( + target, + ".o_searchview_autocomplete li", + 3, + "there should be 3 result for 'F' in search bar autocomplete" + ); + + const searchInput = target.querySelector(".o_searchview input"); + await triggerEvent(searchInput, null, "keydown", { key: "ArrowDown" }); + await triggerEvent(searchInput, null, "keydown", { key: "ArrowDown" }); + await triggerEvent(searchInput, null, "keydown", { key: "ArrowRight" }); + await triggerEvent(searchInput, null, "keydown", { key: "ArrowDown" }); + await triggerEvent(searchInput, null, "keydown", { key: "ArrowDown" }); + await triggerEvent(searchInput, null, "keydown", { key: "ArrowDown" }); + await triggerEvent(searchInput, null, "keydown", { key: "Enter" }); + assert.deepEqual(getDomain(controlPanel), [["company", "=", 5]]); + }); });