From 6d2f4222e4ce6fed001b36bc546c9b6a0ad6b3e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Lef=C3=A8vre=20=28lul=29?= Date: Wed, 24 Apr 2024 09:03:36 -0400 Subject: [PATCH] [FIX] spreadsheet_account: take correct date period Steps to reproduce: - in A1, type '02/2024' - in A2, type '=ODOO.BALANCE("100", A1)' - right click on A2 - click the menu item "See record" => you end up with wrong records in the list view The value of A1 is detected as a number (first of february 2024) When that number is given as the argument of ODOO.BALANCE, the number falls back as being interpreted as a single day, instead of a month period. opw-3872445 Part-of: odoo/odoo#163156 --- .../spreadsheet_account/static/src/index.js | 13 +++++- .../tests/ui/accounting_drilldown_tests.js | 41 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/addons/spreadsheet_account/static/src/index.js b/addons/spreadsheet_account/static/src/index.js index a0cf5ccf8c4..ba962cc9076 100644 --- a/addons/spreadsheet_account/static/src/index.js +++ b/addons/spreadsheet_account/static/src/index.js @@ -9,7 +9,7 @@ import { camelToSnakeObject } from "@spreadsheet/helpers/helpers"; const { cellMenuRegistry, featurePluginRegistry } = spreadsheet.registries; const { astToFormula } = spreadsheet; -const { toString, toBoolean } = spreadsheet.helpers; +const { toString, toBoolean, formatValue } = spreadsheet.helpers; featurePluginRegistry.add("odooAccountingAggregates", AccountingPlugin); @@ -26,6 +26,17 @@ cellMenuRegistry.add("move_lines_see_records", { .map((arg) => env.model.getters.evaluateFormula(sheetId, arg)); codes = toString(codes).split(","); const locale = env.model.getters.getLocale(); + if (args[1]?.type === "REFERENCE") { + const range = env.model.getters.getRangeFromSheetXC(sheetId, args[1].value); + const cell = env.model.getters.getEvaluatedCell({ + sheetId: range.sheetId, + col: range.zone.left, + row: range.zone.top, + }); + if (cell?.format) { + date_range = formatValue(date_range, { format: cell.format, locale }); + } + } const dateRange = parseAccountingDate(date_range, locale); offset = parseInt(offset) || 0; dateRange.year += offset || 0; diff --git a/addons/spreadsheet_account/static/tests/ui/accounting_drilldown_tests.js b/addons/spreadsheet_account/static/tests/ui/accounting_drilldown_tests.js index c804805bb09..efeaede85dd 100644 --- a/addons/spreadsheet_account/static/tests/ui/accounting_drilldown_tests.js +++ b/addons/spreadsheet_account/static/tests/ui/accounting_drilldown_tests.js @@ -8,6 +8,7 @@ import { waitForDataSourcesLoaded, } from "@spreadsheet/../tests/utils/model"; import { registry } from "@web/core/registry"; +import { doMenuAction } from "@spreadsheet/../tests/utils/ui"; const { cellMenuRegistry } = spreadsheet.registries; @@ -91,4 +92,44 @@ QUnit.module("spreadsheet_account > Accounting Drill down", { beforeEach }, () = selectCell(model, "A5"); assert.equal(root.isVisible(env), false); }); + + QUnit.test("Create drill down domain when month date is a reference", async (assert) => { + const actionService = { + start() { + return { + doAction(args) {}, + }; + }, + }; + registry.category("services").add("action", actionService, { force: true }); + const model = await createModelWithDataSource({ + serverData, + mockRPC: async function (route, args) { + if (args.method === "spreadsheet_move_line_action") { + assert.step("spreadsheet_move_line_action"); + assert.deepEqual(args.args, [ + { + codes: ["100"], + company_id: null, + include_unposted: false, + date_range: { + month: 2, + range_type: "month", + year: 2024, + }, + }, + ]); + return {}; + } + }, + }); + const env = model.config.custom.env; + env.model = model; + setCellContent(model, "A1", "02/2024"); + setCellContent(model, "A2", '=ODOO.BALANCE("100", A1)'); + await waitForDataSourcesLoaded(model); + selectCell(model, "A2"); + await doMenuAction(cellMenuRegistry, ["move_lines_see_records"], env); + assert.verifySteps(["spreadsheet_move_line_action"]); + }); });