From 2d7ed635e5239178e268654b7556b0f5b3faa59a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Lef=C3=A8vre=20=28lul=29?= Date: Wed, 13 Mar 2024 19:25:54 +0100 Subject: [PATCH] [FIX] spreadsheet: fetch currency field Get to a list view where there's a monetary field AND the related currency field in the same list. Then insert the list in a spreadsheet. => Either the currency format is not fetched or the currency name, depending on the order in the list. Bug introduced by 8777973e opw-3770057 closes odoo/odoo#157623 Signed-off-by: Pierre Rousseau (pro) --- .../static/src/list/list_data_source.js | 8 +++++- .../static/tests/lists/list_plugin_test.js | 28 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/addons/spreadsheet/static/src/list/list_data_source.js b/addons/spreadsheet/static/src/list/list_data_source.js index 217afcd58dc..9b587e7d528 100644 --- a/addons/spreadsheet/static/src/list/list_data_source.js +++ b/addons/spreadsheet/static/src/list/list_data_source.js @@ -85,6 +85,7 @@ export class ListDataSource extends OdooViewsDataSource { spec[field.name] = {}; spec[field.currency_field] = { fields: { + ...spec[field.currency_field]?.fields, name: {}, // currency code symbol: {}, decimal_places: {}, @@ -95,7 +96,12 @@ export class ListDataSource extends OdooViewsDataSource { case "many2one": case "many2many": case "one2many": - spec[field.name] = { fields: { display_name: {} } }; + spec[field.name] = { + fields: { + display_name: {}, + ...spec[field.name]?.fields, + }, + }; break; default: spec[field.name] = field; diff --git a/addons/spreadsheet/static/tests/lists/list_plugin_test.js b/addons/spreadsheet/static/tests/lists/list_plugin_test.js index 26c5f61385d..a0cb9363edb 100644 --- a/addons/spreadsheet/static/tests/lists/list_plugin_test.js +++ b/addons/spreadsheet/static/tests/lists/list_plugin_test.js @@ -549,6 +549,34 @@ QUnit.module("spreadsheet > list plugin", {}, () => { }); }); + QUnit.test( + "list with both a monetary field and the related currency field", + async function (assert) { + const { model } = await createSpreadsheetWithList({ + columns: ["pognon", "currency_id"], + }); + setCellContent(model, "A1", '=ODOO.LIST(1, 1, "pognon")'); + setCellContent(model, "A2", '=ODOO.LIST(1, 1, "currency_id")'); + await waitForDataSourcesLoaded(model); + assert.strictEqual(getEvaluatedCell(model, "A1").formattedValue, "74.40€"); + assert.strictEqual(getEvaluatedCell(model, "A2").value, "EUR"); + } + ); + + QUnit.test( + "list with both a monetary field and the related currency field", + async function (assert) { + const { model } = await createSpreadsheetWithList({ + columns: ["currency_id", "pognon"], + }); + setCellContent(model, "A1", '=ODOO.LIST(1, 1, "pognon")'); + setCellContent(model, "A2", '=ODOO.LIST(1, 1, "currency_id")'); + await waitForDataSourcesLoaded(model); + assert.strictEqual(getEvaluatedCell(model, "A1").formattedValue, "74.40€"); + assert.strictEqual(getEvaluatedCell(model, "A2").value, "EUR"); + } + ); + QUnit.test( "List record limit is computed during the import and UPDATE_CELL", async function (assert) {