From d6678acc8fff98d4e4efdfe220e944023370b502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Rahir=20=28rar=29?= Date: Fri, 26 Apr 2024 15:13:22 +0000 Subject: [PATCH] [FIX] Export xlsx: export value for non-exportable formulas MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The recent fix in https://github.com/odoo/o-spreadsheet/pull/3622 combined with a slight refactoring of the export for Excel in https://github.com/odoo/o-spreadsheet/pull/2090 let to a situation where cells with non-exportable formulas containing references did not have their content replaced by the evaluated result. closes odoo/o-spreadsheet#4167 Task: 3895465 X-original-commit: 0ef57decc20215b1f04b336435f9760b209eae68 Signed-off-by: Lucas Lefèvre (lul) --- .../ui_core_views/cell_evaluation/evaluation_plugin.ts | 4 ++-- tests/xlsx/xlsx_export.test.ts | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/plugins/ui_core_views/cell_evaluation/evaluation_plugin.ts b/src/plugins/ui_core_views/cell_evaluation/evaluation_plugin.ts index 51cd50796..1a9d4049b 100644 --- a/src/plugins/ui_core_views/cell_evaluation/evaluation_plugin.ts +++ b/src/plugins/ui_core_views/cell_evaluation/evaluation_plugin.ts @@ -323,8 +323,8 @@ export class EvaluationPlugin extends UIPlugin { const format = newFormat ? getItemId(newFormat, data.formats) : exportedCellData.format; - let content; - if (isFormula && formulaCell instanceof FormulaCellWithDependencies) { + let content: string | undefined; + if (isExported && isFormula && formulaCell instanceof FormulaCellWithDependencies) { content = formulaCell.contentWithFixedReferences; } else { content = !isExported ? newContent : exportedCellData.content; diff --git a/tests/xlsx/xlsx_export.test.ts b/tests/xlsx/xlsx_export.test.ts index e442e78df..1bce779c3 100644 --- a/tests/xlsx/xlsx_export.test.ts +++ b/tests/xlsx/xlsx_export.test.ts @@ -1,4 +1,4 @@ -import { functionRegistry } from "../../src/functions"; +import { arg, functionRegistry } from "../../src/functions"; import { buildSheetLink, toXC } from "../../src/helpers"; import { DEFAULT_TABLE_CONFIG } from "../../src/helpers/table_presets"; import { Model } from "../../src/model"; @@ -751,7 +751,7 @@ describe("Test XLSX export", () => { functionRegistry.add("NON.EXPORTABLE", { description: "a non exportable formula", - args: [], + args: [arg('range (any, range, ,default="a")', "")], returns: ["NUMBER"], compute: function () { return { value: 42, format: "0.00%" }; @@ -760,10 +760,12 @@ describe("Test XLSX export", () => { }); setCellContent(model, "A1", "=1+NON.EXPORTABLE()"); + setCellContent(model, "A2", "=1+NON.EXPORTABLE(A1)"); const exported = getExportedExcelData(model); expect(exported.sheets[0].cells["A1"]?.content).toEqual("43"); + expect(exported.sheets[0].cells["A2"]?.content).toEqual("43"); const formatId = exported.sheets[0].cells["A1"]?.format; expect(formatId).toEqual(1); expect(exported.formats[formatId!]).toEqual("0.00%");