[FIX] web: mockWebRead respect the spec of a many2one field

Before this commit, the mockServer didn't respect the unity specification
for many2one fields. When you do a mockWebRead and you want to read other fields
than "id" and "display_name" for a many2one field, the mockServeur ignores
this part of the specification.

The goal of this commit is to ensure that the mockWebRead respects
the full specification for many2one fields.

closes odoo/odoo#148483

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
FrancoisGe
2024-01-10 06:12:20 +00:00
parent 457561aaa0
commit 3e37dc21d5
2 changed files with 25 additions and 5 deletions
@@ -2503,11 +2503,14 @@ export class MockServer {
if (!relatedFields) {
record[fieldName] = record[fieldName][0];
} else {
const displayName = record[fieldName][1];
record[fieldName] = { id: record[fieldName][0] };
if ("display_name" in relatedFields) {
record[fieldName].display_name = displayName;
}
record[fieldName] = this.mockWebRead(
field.relation,
[record[fieldName][0]],
{
specification: relatedFields,
context: spec[fieldName].context,
}
)[0];
}
}
}
@@ -1373,6 +1373,23 @@ QUnit.module("MockServer", (hooks) => {
mockServer.mockWrite("foo", [[2], { many2one_reference: false }]);
assert.deepEqual(mockServer.models.bar.records[0].one2many_field, []);
});
QUnit.test("webRead sub-fields of a many2one field", async function (assert) {
data.models.partner.fields.test_name = { string: "Test Name", type: "char" };
data.models.partner.fields.test_number = { string: "Number", type: "integer" };
data.models.partner.records = [{ id: 1, test_name: "Jean-Michel", test_number: 5 }];
data.models.bar.records = [{ id: 1, partner_id: 1 }];
const mockServer = new MockServer(data);
const result = mockServer.mockWebRead("bar", [[1]], {
specification: { partner_id: { fields: { test_name: {}, test_number: {} } } },
});
assert.deepEqual(result, [
{ id: 1, partner_id: { id: 1, test_name: "Jean-Michel", test_number: 5 } },
]);
});
QUnit.test("List View: invisible on processed Arch", async function (assert) {
data.views = {
"bar,10001,list": `