[FIX] spreadsheet: export shared non formatted value

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) <rar@odoo.com>
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
This commit is contained in:
Lucas Lefèvre (lul)
2024-02-21 12:59:07 +00:00
parent 25cda065dc
commit 73892f1d16
2 changed files with 27 additions and 5 deletions
@@ -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);
}
@@ -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) {