From 0ef57decc20215b1f04b336435f9760b209eae68 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#4164 Task: 3895465 X-original-commit: e8d14442c49d2402443d244f7a6d3c841a29bb15 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 c3c202b69c..5f6f23656e 100644 --- a/src/plugins/ui_core_views/cell_evaluation/evaluation_plugin.ts +++ b/src/plugins/ui_core_views/cell_evaluation/evaluation_plugin.ts @@ -316,8 +316,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 772d43dba9..716126993e 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 { createEmptyExcelWorkbookData } from "../../src/migrations/data"; import { Model } from "../../src/model"; @@ -742,7 +742,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%" }; @@ -751,10 +751,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%");