[FIX] web: search model: one2many search default labels

When a one2many is used as a search default, its label has to be fetch
via a name_get in order to get a correct display of the facet
corresponding to that field in the search bar. It turns out that the
search model did not wait properly the return of the name_gets before to
start to compute the facets.

closes odoo/odoo#106624

X-original-commit: 50f58212410b321c1c4ad3d42a91cd1d23567308
Signed-off-by: Mathieu Duckerts-Antoine <dam@odoo.com>
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Mathieu Duckerts-Antoine
2022-11-28 13:20:44 +01:00
parent fc080b960d
commit 84a0d31ca7
2 changed files with 32 additions and 1 deletions
@@ -160,7 +160,7 @@ export class SearchArchParser extends XMLParser {
preField.defaultAutocompleteValue.label = option[1];
} else if (fieldType === "many2one") {
this.labels.push((orm) => {
orm.call(relation, "name_get", [value], { context }).then((results) => {
return orm.call(relation, "name_get", [value], { context }).then((results) => {
preField.defaultAutocompleteValue.label = results[0][1];
});
});
@@ -998,4 +998,35 @@ QUnit.module("Search", (hooks) => {
await triggerEvent(searchInput, null, "keydown", { key: "Enter" });
assert.deepEqual(getDomain(controlPanel), [["company", "=", 5]]);
});
QUnit.test("should wait label promises for one2many search defaults", async function (assert) {
assert.expect(3);
const target = getFixture();
const def = makeDeferred();
const mockRPC = async (_, args) => {
if (args.method === "name_get") {
await def;
}
};
makeWithSearch({
serverData,
mockRPC,
resModel: "partner",
Component: ControlPanel,
searchMenuTypes: [],
searchViewId: false,
context: { search_default_company: 1 },
});
await nextTick();
assert.containsNone(target, ".o_control_panel");
def.resolve();
await nextTick();
assert.containsOnce(target, ".o_control_panel");
assert.strictEqual(getFacetTexts(target)[0].replace("\n", ""), "CompanyFirst record");
});
});