[FIX] spreadsheet: preload currency fields of list

Before this revision, the currency fields of monetary fields of a list
were not preloaded when the list was loaded. This was causing a double
rpc, a first one to get the list data, and a second one to get the
currency data.

With this revision, we preload the currency fields of monetary fields
of a list.

task-id 3095937

closes odoo/odoo#107591

X-original-commit: a2d5fc517d460ccf5c17611de023a219dfadf7ad
Signed-off-by: Pierre Rousseau (pro) <pro@odoo.com>
This commit is contained in:
Pierre Rousseau
2022-12-09 10:45:13 +01:00
parent 044231fb10
commit 092ca864db
2 changed files with 29 additions and 1 deletions
@@ -50,7 +50,7 @@ export default class ListDataSource extends OdooViewsDataSource {
this.data = await this._orm.searchRead(
this._metaData.resModel,
domain,
this._metaData.columns.filter((f) => this.getField(f)),
this._getFieldsToFetch(),
{
order: orderByToString(orderBy),
limit: this.limit,
@@ -59,6 +59,20 @@ export default class ListDataSource extends OdooViewsDataSource {
);
}
/**
* Get the fields to fetch from the server.
* Automatically add the currency field if the field is a monetary field.
*/
_getFieldsToFetch() {
const fields = this._metaData.columns.filter((f) => this.getField(f));
for (const field of fields) {
if (this.getField(field).type === "monetary") {
fields.push(this.getField(field).currency_field);
}
}
return fields;
}
/**
* @param {number} position
* @returns {number}
@@ -492,4 +492,18 @@ QUnit.module("spreadsheet > list plugin", {}, () => {
assert.deepEqual(model.getters.getListFieldMatching("1", filter.id), undefined);
assert.deepEqual(model.getters.getListDataSource("1").getComputedDomain(), []);
});
QUnit.test("Preload currency of monetary field", async function (assert) {
assert.expect(3);
await createSpreadsheetWithList({
columns: ["pognon"],
mockRPC: async function (route, args, performRPC) {
if (args.method === "search_read" && args.model === "partner") {
assert.strictEqual(args.kwargs.fields.length, 2);
assert.strictEqual(args.kwargs.fields[0], "pognon");
assert.strictEqual(args.kwargs.fields[1], "currency_id");
}
},
});
});
});