[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) <aab@odoo.com>
Co-authored-by: Aaron Bohy <aab@odoo.com>
This commit is contained in:
Carlos Roca
2024-04-26 18:54:33 +00:00
committed by Aaron Bohy
co-authored by Aaron Bohy
parent eb7ea22ea0
commit c6b0248b5f
@@ -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: `
<form>
<sheet>
<group>
@@ -1143,21 +1145,22 @@ QUnit.module("Fields", (hooks) => {
</group>
</sheet>
</form>`,
});
});
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": '<list><field name="display_name"/></list>',
"partner,false,search": "<search></search>",
};
await makeView({
serverData,
type: "form",
resModel: "partner",
arch: `
<form>
<sheet>
<field name="p">
<tree>
<field name="display_name"/>
<field name="trululu" domain="[]"/>
</tree>
<form>
<field name="trululu" domain="[['id', '>', 1]]"/>
</form>
</field>
</sheet>
</form>`,
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: