[FIX] web: SampleServer: properly mock unity_web_search_read
Before this commit, many2one values were still returned as pairs of id and display_name by unity read, whereas they should be objects with keys id and display_name. Part-of: odoo/odoo#133617
This commit is contained in:
@@ -608,9 +608,19 @@ export class SampleServer {
|
||||
} else {
|
||||
result = this._mockWebSearchRead({ ...params, fields });
|
||||
}
|
||||
// populate x2many values
|
||||
// populate many2one and x2many values
|
||||
for (const fieldName in params.specification) {
|
||||
const field = this.data[params.model].fields[fieldName];
|
||||
if (field.type === "many2one") {
|
||||
for (const record of result.records) {
|
||||
record[fieldName] = record[fieldName]
|
||||
? {
|
||||
id: record[fieldName][0],
|
||||
display_name: record[fieldName][1],
|
||||
}
|
||||
: false;
|
||||
}
|
||||
}
|
||||
if (field.type === "one2many" || field.type === "many2many") {
|
||||
const relFields = Object.keys(params.specification[fieldName].fields || {});
|
||||
if (relFields.length) {
|
||||
|
||||
@@ -261,6 +261,24 @@ QUnit.module(
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("Send 'search_read' RPC: many2one fields", async function (assert) {
|
||||
const server = new DeterministicSampleServer("res.users", fields["res.users"]);
|
||||
|
||||
const result = await server.mockRpc({
|
||||
method: "unity_web_search_read",
|
||||
model: "res.users",
|
||||
specification: {
|
||||
manager_id: {
|
||||
fields: { display_name: {} },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
assert.deepEqual(Object.keys(result.records[0]), ["id", "manager_id"]);
|
||||
assert.ok(result.records[0].manager_id.id);
|
||||
assert.ok(/\w+/.test(result.records[0].manager_id.display_name));
|
||||
});
|
||||
|
||||
QUnit.test("Send 'web_read_group' RPC: no group", async function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user