From 0a19ea1b3564eee1b4e83b057c9d4b36ff387500 Mon Sep 17 00:00:00 2001 From: "Habib (ayh)" Date: Mon, 14 Aug 2023 10:12:22 +0000 Subject: [PATCH] [FIX] web: currency reload The currency service is responsible for reloading currencies from the session_info, however it does not retrieve the correct key/value. The issue can be reproduced in saas-16.4: - Activate a currency - Accounting Dashboard > Reconcile x items - Client stack trace (after hard refresh the correct currencies are loaded) closes odoo/odoo#132375 Cause: the `reloadCurrencies` method is assigning the entire session_info response object to the session's currencies X-original-commit: bbbf836f99b0271442e5e3a7ec03f108de69ec78 Signed-off-by: Francois Georis (fge) Signed-off-by: Habib Ayob (ayh) --- addons/web/static/src/webclient/currency_service.js | 2 +- .../static/tests/webclient/currency_service_tests.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/webclient/currency_service.js b/addons/web/static/src/webclient/currency_service.js index 44fff595fad..55575fd0286 100644 --- a/addons/web/static/src/webclient/currency_service.js +++ b/addons/web/static/src/webclient/currency_service.js @@ -15,7 +15,7 @@ export const currencyService = { for (const k in currencies) { delete currencies[k]; } - Object.assign(currencies, result); + Object.assign(currencies, result?.currencies); } env.bus.addEventListener("RPC:RESPONSE", (ev) => { const { data, error } = ev.detail; diff --git a/addons/web/static/tests/webclient/currency_service_tests.js b/addons/web/static/tests/webclient/currency_service_tests.js index 221b442e904..8aaa5b7a616 100644 --- a/addons/web/static/tests/webclient/currency_service_tests.js +++ b/addons/web/static/tests/webclient/currency_service_tests.js @@ -2,6 +2,7 @@ import { ormService } from "@web/core/orm_service"; import { registry } from "@web/core/registry"; +import { currencies } from "@web/core/currency"; import { currencyService } from "@web/webclient/currency_service"; import { makeTestEnv } from "../helpers/mock_env"; import { makeFakeRPCService } from "../helpers/mock_services"; @@ -15,6 +16,14 @@ QUnit.test("reload currencies when updating a res.currency", async (assert) => { serviceRegistry.add("orm", ormService); const fakeRpc = makeFakeRPCService((route) => { assert.step(route); + if (route === "/web/session/get_session_info") { + return { + uid: 1, + currencies: { + 7: { symbol: "$", position: "before", digits: 2 }, + }, + }; + } }); serviceRegistry.add("rpc", fakeRpc); const env = await makeTestEnv(); @@ -28,6 +37,7 @@ QUnit.test("reload currencies when updating a res.currency", async (assert) => { ]); await env.services.orm.unlink("notcurrency", [32]); assert.verifySteps(["/web/dataset/call_kw/notcurrency/unlink"]); + assert.deepEqual(Object.keys(currencies), ["7"]); }); QUnit.test(