diff --git a/addons/spreadsheet/static/src/data_sources/display_name_repository.js b/addons/spreadsheet/static/src/data_sources/display_name_repository.js index 755fe2cbad1..101689890ce 100644 --- a/addons/spreadsheet/static/src/data_sources/display_name_repository.js +++ b/addons/spreadsheet/static/src/data_sources/display_name_repository.js @@ -1,6 +1,5 @@ /** @odoo-module */ -import { Deferred } from "@web/core/utils/concurrency"; import { LoadingDataError } from "../o_spreadsheet/errors"; import BatchEndpoint, { Request } from "./server_data"; @@ -45,8 +44,8 @@ export class DisplayNameRepository { * { * "res.country": { * 1: { + * "state": "COMPLETED" * "value": "Belgium", - * "deferred": Deferred<"Belgium">, * }, * } */ @@ -56,21 +55,6 @@ export class DisplayNameRepository { this._endpoints = {}; } - /** - * Get the display name of the given record. - * - * @param {string} model - * @param {number} id - * @returns {Promise} - */ - async getDisplayNameAsync(model, id) { - const displayNameResult = this._displayNames[model] && this._displayNames[model][id]; - if (!displayNameResult) { - return this._fetchDisplayName(model, id); - } - return displayNameResult.deferred; - } - /** * Set the display name of the given record. This will prevent the display name * from being fetched in the background. @@ -83,11 +67,8 @@ export class DisplayNameRepository { if (!this._displayNames[model]) { this._displayNames[model] = {}; } - const deferred = new Deferred(); - deferred.resolve(displayName); this._displayNames[model][id] = { state: "COMPLETED", - deferred, value: displayName, }; } @@ -101,11 +82,11 @@ export class DisplayNameRepository { * @returns {string} */ getDisplayName(model, id) { - const displayNameResult = this._displayNames[model] && this._displayNames[model][id]; + const displayNameResult = this._displayNames[model]?.[id]; if (!displayNameResult) { // Catch the error to prevent the error from being thrown in the // background. - this._fetchDisplayName(model, id).catch(() => {}); + this._fetchDisplayName(model, id); throw new LoadingDataError(); } switch (displayNameResult.state) { @@ -146,11 +127,8 @@ export class DisplayNameRepository { * @private */ _assignResult(request, result) { - const deferred = this._displayNames[request.resModel][request.args[0]].deferred; - deferred.resolve(result && result[1]); this._displayNames[request.resModel][request.args[0]] = { state: "COMPLETED", - deferred, value: result && result[1], }; } @@ -165,13 +143,7 @@ export class DisplayNameRepository { * @private */ _assignError(request, error) { - const deferred = this._displayNames[request.resModel][request.args[0]].deferred; - deferred.reject(error); - this._displayNames[request.resModel][request.args[0]] = { - state: "ERROR", - deferred, - error, - }; + this._displayNames[request.resModel][request.args[0]] = { state: "ERROR", error }; } /** @@ -185,18 +157,13 @@ export class DisplayNameRepository { * @private * @returns {Deferred} */ - async _fetchDisplayName(model, id) { - const deferred = new Deferred(); + _fetchDisplayName(model, id) { if (!this._displayNames[model]) { this._displayNames[model] = {}; } - this._displayNames[model][id] = { - state: "PENDING", - deferred, - }; + this._displayNames[model][id] = { state: "PENDING" }; const endpoint = this._getEndpoint(model); const request = new Request(model, "name_get", [id]); endpoint.call(request); - return deferred; } }