From 73892f1d165f7f6b2cb5413cd4a445fd1e4617f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Lef=C3=A8vre=20=28lul=29?= Date: Mon, 12 Feb 2024 15:15:41 +0000 Subject: [PATCH] [FIX] spreadsheet: export shared non formatted value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Turn your odoo user's language to "French (BE) / Français (BE)". Now, let's say you have a pivot function returning an amount in the one million (e.g. 1 230 000). It's formatted to "1.230.000,00" Reference that cell with `FORMAT.LARGE.NUMBER`. The result is "1.230k" Now hit the share button and open the share link in an incognito tab. => the cell is now "123m" That's because the string "1.230.000,00" is wrongly parsed to 123000000 (to fix in o-spreadsheet). Besides that, the formatted value may not necessarily be parsable. With this commit, we export the raw value, stringified. opw 3720586 closes odoo/odoo#154712 X-original-commit: 7f8d705b216b392ce1249793a0b44dcec0ac536c Signed-off-by: Rémi Rahir (rar) Signed-off-by: Lucas Lefèvre (lul) --- .../spreadsheet/static/src/helpers/model.js | 2 +- .../tests/public_spreadsheet/freeze_test.js | 30 ++++++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/addons/spreadsheet/static/src/helpers/model.js b/addons/spreadsheet/static/src/helpers/model.js index 383b77defc4..ab9474f1c90 100644 --- a/addons/spreadsheet/static/src/helpers/model.js +++ b/addons/spreadsheet/static/src/helpers/model.js @@ -58,7 +58,7 @@ export async function freezeOdooData(model) { col, row, }); - cell.content = evaluatedCell.formattedValue; + cell.content = evaluatedCell.value.toString(); if (evaluatedCell.format) { cell.format = getItemId(evaluatedCell.format, data.formats); } diff --git a/addons/spreadsheet/static/tests/public_spreadsheet/freeze_test.js b/addons/spreadsheet/static/tests/public_spreadsheet/freeze_test.js index 94848343bec..65343a5cdbe 100644 --- a/addons/spreadsheet/static/tests/public_spreadsheet/freeze_test.js +++ b/addons/spreadsheet/static/tests/public_spreadsheet/freeze_test.js @@ -2,7 +2,7 @@ import { freezeOdooData } from "../../src/helpers/model"; import { createSpreadsheetWithChart } from "../utils/chart"; -import { setCellContent, setGlobalFilterValue } from "../utils/commands"; +import { setCellContent, setCellFormat, setGlobalFilterValue } from "../utils/commands"; import { getCell, getEvaluatedCell } from "../utils/getters"; import { createSpreadsheetWithPivot } from "../utils/pivot"; import { createModelWithDataSource } from "@spreadsheet/../tests/utils/model"; @@ -22,7 +22,29 @@ QUnit.module("freezing spreadsheet", {}, function () { const data = await freezeOdooData(model); const cells = data.sheets[0].cells; assert.strictEqual(cells.A3.content, "No", "the content is replaced with the value"); - assert.strictEqual(cells.C3.content, "15.00", "the content is replaced with the value"); + assert.strictEqual(cells.C3.content, "15", "the content is replaced with the value"); + assert.strictEqual(data.formats[cells.C3.format], "#,##0.00"); + }); + + QUnit.test("values are not exported formatted", async function (assert) { + const { model } = await createSpreadsheetWithPivot(); + assert.strictEqual(getCell(model, "A3").content, '=ODOO.PIVOT.HEADER(1,"bar","false")'); + assert.strictEqual( + getCell(model, "C3").content, + '=ODOO.PIVOT(1,"probability","bar","false","foo",2)' + ); + setCellFormat(model, "C3", "mmmm yyyy"); + setCellContent(model, "C4", "=C3+31"); + assert.strictEqual(getEvaluatedCell(model, "C3").value, 15); + assert.strictEqual(getEvaluatedCell(model, "C3").formattedValue, "January 1900"); + assert.strictEqual(getEvaluatedCell(model, "C4").value, 46); + assert.strictEqual(getEvaluatedCell(model, "C4").formattedValue, "February 1900"); + const data = await freezeOdooData(model); + const sharedModel = await createModelWithDataSource({ spreadsheetData: data }); + assert.strictEqual(getEvaluatedCell(sharedModel, "C3").value, 15); + assert.strictEqual(getEvaluatedCell(sharedModel, "C3").formattedValue, "January 1900"); + assert.strictEqual(getEvaluatedCell(sharedModel, "C4").value, 46); + assert.strictEqual(getEvaluatedCell(sharedModel, "C4").formattedValue, "February 1900"); }); QUnit.test("invalid expression with pivot function", async function (assert) { @@ -45,8 +67,8 @@ QUnit.module("freezing spreadsheet", {}, function () { const data = await freezeOdooData(model); const A1 = data.sheets[0].cells.A1; const A2 = data.sheets[0].cells.A2; - assert.strictEqual(A1.content, "131.00", "the content is replaced with the value"); - assert.strictEqual(A2.content, "131.00", "the content is replaced with the value"); + assert.strictEqual(A1.content, "131", "the content is replaced with the value"); + assert.strictEqual(A2.content, "131", "the content is replaced with the value"); }); QUnit.test("computed format is exported", async function (assert) {