From c6b0248b5fbfaf081616d3cea2601b6e38df996e Mon Sep 17 00:00:00 2001 From: Carlos Roca Date: Tue, 23 Apr 2024 08:28:31 +0000 Subject: [PATCH] [FIX] web: SearchView of many2one is not getting the form domain Steps to reproduce the problem: 1. Add a many2one field to lines of a model, example: sale.order.line 2. Add it to form view of the lines with a domain 3. Click on Search more... option 4. You will see results out of the scope of the domain In the getDomain is passed an object that has only the key fieldName but for knew in what view is the field placed it needs to be provided the key viewType, this both are placed on the class object this.recordParams builded at: https://github.com/odoo/odoo/blob/b8a5175b6c92749bd3bb7b9f869b1ecff78e133f/addons/web/static/src/legacy/js/fields/relational_fields.js#L129 If this key is not provided the viewType is beeing filled with the element viewType, this element is the record opened placed in the parent view, so by default if will be kanban or list. So if the domain is filled just in the form view, the search panel will get the domain [], so all the entries will be displayed and they will be able to be selected. If we see the next line: https://github.com/odoo/odoo/blob/b8a5175b6c92749bd3bb7b9f869b1ecff78e133f/addons/web/static/src/legacy/js/fields/relational_fields.js#L431 We will see that getContext is getting this.recordParams as argument, for the same reason that the domain should have it. With this changes the getDomain method is getting the viewType to take the domain instead of the viewType of the lines displayed on the parent view. closes odoo/odoo#163513 X-original-commit: 1eef2e8711124df9cbe7373ef6056b51f1b2617c Signed-off-by: Aaron Bohy (aab) Co-authored-by: Aaron Bohy --- .../views/fields/many2one_field_tests.js | 102 ++++++++++++++---- 1 file changed, 81 insertions(+), 21 deletions(-) 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 2271a69564c..93e40efe5e6 100644 --- a/addons/web/static/tests/views/fields/many2one_field_tests.js +++ b/addons/web/static/tests/views/fields/many2one_field_tests.js @@ -1128,14 +1128,16 @@ QUnit.module("Fields", (hooks) => { ); }); - QUnit.test("many2one with no_create_edit and no_quick_create options should show no records when no result match", async function (assert) { - assert.expect(2); + QUnit.test( + "many2one with no_create_edit and no_quick_create options should show no records when no result match", + async function (assert) { + assert.expect(2); - await makeView({ - type: "form", - resModel: "partner", - serverData, - arch: ` + await makeView({ + type: "form", + resModel: "partner", + serverData, + arch: `
@@ -1143,21 +1145,22 @@ QUnit.module("Fields", (hooks) => {
`, - }); + }); - await click(target, ".o_field_many2one[name='product_id'] input"); - assert.containsNone( - target.querySelector(".o_field_many2one[name='product_id'] .dropdown-menu"), - "li.o_m2o_no_result", - "autocomplete should not contain the no records option" - ); - await editInput(target, ".o_field_many2one[name='product_id'] input", "aze"); - assert.containsOnce( - target.querySelector(".o_field_many2one[name='product_id'] .dropdown-menu"), - "li.o_m2o_no_result", - "autocomplete should contain the no records option" - ); - }); + await click(target, ".o_field_many2one[name='product_id'] input"); + assert.containsNone( + target.querySelector(".o_field_many2one[name='product_id'] .dropdown-menu"), + "li.o_m2o_no_result", + "autocomplete should not contain the no records option" + ); + await editInput(target, ".o_field_many2one[name='product_id'] input", "aze"); + assert.containsOnce( + target.querySelector(".o_field_many2one[name='product_id'] .dropdown-menu"), + "li.o_m2o_no_result", + "autocomplete should contain the no records option" + ); + } + ); QUnit.test("many2one in edit mode", async function (assert) { assert.expect(17); @@ -1879,6 +1882,63 @@ QUnit.module("Fields", (hooks) => { assert.verifySteps(["name_create"]); }); + QUnit.test("many2one inside one2many form view, with domain", async function (assert) { + assert.expect(4); + + serverData.models.partner.fields.trululu.domain = "[['id', '<', 1000]]"; + serverData.models.partner.records = [ + { id: 1, display_name: "a1", p: [1] }, + { id: 2, display_name: "a2" }, + { id: 3, display_name: "a3" }, + { id: 4, display_name: "a4" }, + { id: 5, display_name: "a5" }, + { id: 6, display_name: "a6" }, + { id: 7, display_name: "a7" }, + { id: 8, display_name: "a8" }, + { id: 9, display_name: "a9" }, + ]; + serverData.views = { + "partner,false,list": '', + "partner,false,search": "", + }; + + await makeView({ + serverData, + type: "form", + resModel: "partner", + arch: ` +
+ + + + + + + + + + +
+ `, + resId: 1, + mockRPC(route, args) { + if (args.method === "name_search") { + assert.deepEqual(args.kwargs.args, [["id", ">", 1]]); + } + if (args.method === "web_search_read") { + assert.deepEqual(args.kwargs.domain, [["id", ">", 1]]); + } + }, + }); + + await click(target.querySelector(".o_data_row .o_data_cell")); + await editInput(target, ".o_field_widget[name=trululu] input", ""); + await clickOpenedDropdownItem(target, "trululu", "Search More..."); + + assert.containsOnce(document.body, ".modal .o_list_view"); + assert.containsN(document.body, ".modal .o_data_row", 8); + }); + QUnit.test("list in form: quick create then add a new line directly", async function (assert) { // required many2one inside a one2many list: directly after quick creating // a new many2one value (before the name_create returns), click on add an item: