Skip to content

Commit

Permalink
[REF] web: remove orm service nameGet
Browse files Browse the repository at this point in the history
This commit removes all usages of the nameGet method of the orm service
following changes introduced by odoo#122085

task-3377209
  • Loading branch information
juliusc2066 committed Oct 25, 2023
1 parent 8cec29f commit 09d4c09
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 43 deletions.
16 changes: 0 additions & 16 deletions addons/web/static/src/core/orm_service.js
Expand Up @@ -143,22 +143,6 @@ export class ORM {
return this.call(model, "create", [records], kwargs);
}

/**
* @param {string} model
* @param {number[]} ids
* @param {any} [kwargs={}]
* @returns {Promise<[number, string][]>}
*/
nameGet(model, ids, kwargs = {}) {
validatePrimitiveList("ids", "number", ids);
if (!ids.length) {
return Promise.resolve([]);
}
return this.call(model, "read", [ids, ["display_name"]], kwargs).then(
(data) => data && data.map(({ id, display_name }) => [id, display_name])
);
}

/**
* @param {string} model
* @param {number[]} ids
Expand Down
Expand Up @@ -323,10 +323,10 @@ export class PropertyValue extends Component {
* @returns {array} [record id, record name]
*/
async _nameGet(recordId) {
const result = await this.orm.nameGet(this.props.comodel, [recordId], {
const result = await this.orm.read(this.props.comodel, [recordId], ["display_name"], {
context: this.props.context,
});
return result[0];
return [result[0].id, result[0].display_name];
}
}

Expand Down
Expand Up @@ -179,13 +179,13 @@ export class ReferenceField extends Component {
const { specialDataCaches, orm } = props.record.model;
const key = `__reference__name_get-${recordData}`;
if (!specialDataCaches[key]) {
specialDataCaches[key] = orm.nameGet(resModel, [resId]);
specialDataCaches[key] = orm.read(resModel, [resId], ["display_name"]);
}
const result = await specialDataCaches[key];
return {
resId,
resModel,
displayName: result[0][1],
displayName: result[0].display_name,
};
}
return false;
Expand Down
26 changes: 3 additions & 23 deletions addons/web/static/tests/core/orm_service_tests.js
Expand Up @@ -146,28 +146,6 @@ QUnit.test("create method: several records", async (assert) => {
});
});

QUnit.test("nameGet method", async (assert) => {
const [query, rpc] = makeFakeRPC();
serviceRegistry.add("rpc", rpc);
const env = await makeTestEnv();
const context = { complete: true };
await env.services.orm.nameGet("sale.order", [2, 5], { context });
assert.strictEqual(query.route, "/web/dataset/call_kw/sale.order/read");
assert.deepEqual(query.params, {
args: [[2, 5], ["display_name"]],
kwargs: {
context: {
complete: true,
lang: "en",
tz: "taht",
uid: 7,
},
},
method: "read",
model: "sale.order",
});
});

QUnit.test("read method", async (assert) => {
const [query, rpc] = makeFakeRPC();
serviceRegistry.add("rpc", rpc);
Expand Down Expand Up @@ -309,7 +287,9 @@ QUnit.test("test readGroup method removes duplicate values from groupby", async
{ offset: 1 }
);
assert.strictEqual(query.route, "/web/dataset/call_kw/sale.order/read_group");
assert.deepEqual(query.params.kwargs.groupby, ["date_order:month"],
assert.deepEqual(
query.params.kwargs.groupby,
["date_order:month"],
"Duplicate values should be removed from groupby"
);
});
Expand Down

0 comments on commit 09d4c09

Please sign in to comment.