diff --git a/addons/spreadsheet_account/static/src/accounting_functions.js b/addons/spreadsheet_account/static/src/accounting_functions.js index 552ad74abd4..c34e02cc91d 100644 --- a/addons/spreadsheet_account/static/src/accounting_functions.js +++ b/addons/spreadsheet_account/static/src/accounting_functions.js @@ -5,7 +5,7 @@ import { sprintf } from "@web/core/utils/strings"; import * as spreadsheet from "@odoo/o-spreadsheet"; const { functionRegistry } = spreadsheet.registries; -const { arg, toBoolean, toString, toNumber, toJsDate } = spreadsheet.helpers; +const { arg, toBoolean, toString, toNumber, toJsDate, formatValue } = spreadsheet.helpers; const QuarterRegexp = /^q([1-4])\/(\d{4})$/i; const MonthRegexp = /^0?([1-9]|1[0-2])\/(\d{4})$/i; @@ -159,6 +159,12 @@ functionRegistry.add("ODOO.CREDIT", { .map((code) => code.trim()) .sort(); offset = toNumber(offset.value, this.locale); + if (dateRange?.format) { + dateRange.value = formatValue(dateRange.value, { + format: dateRange.format, + locale: this.locale, + }); + } dateRange = parseAccountingDate(dateRange?.value, this.locale); includeUnposted = toBoolean(includeUnposted.value); const value = this.getters.getAccountPrefixCredit( @@ -190,6 +196,12 @@ functionRegistry.add("ODOO.DEBIT", { .map((code) => code.trim()) .sort(); offset = toNumber(offset.value, this.locale); + if (dateRange?.format) { + dateRange.value = formatValue(dateRange.value, { + format: dateRange.format, + locale: this.locale, + }); + } dateRange = parseAccountingDate(dateRange?.value, this.locale); includeUnposted = toBoolean(includeUnposted.value); const value = this.getters.getAccountPrefixDebit( @@ -221,6 +233,12 @@ functionRegistry.add("ODOO.BALANCE", { .map((code) => code.trim()) .sort(); offset = toNumber(offset.value, this.locale); + if (dateRange?.format) { + dateRange.value = formatValue(dateRange.value, { + format: dateRange.format, + locale: this.locale, + }); + } dateRange = parseAccountingDate(dateRange?.value, this.locale); includeUnposted = toBoolean(includeUnposted.value); const value = diff --git a/addons/spreadsheet_account/static/tests/model/accounting_tests.js b/addons/spreadsheet_account/static/tests/model/accounting_tests.js index 0b124225ecd..59fa8aba77b 100644 --- a/addons/spreadsheet_account/static/tests/model/accounting_tests.js +++ b/addons/spreadsheet_account/static/tests/model/accounting_tests.js @@ -41,6 +41,38 @@ QUnit.module("spreadsheet_account > Accounting", { beforeEach }, () => { assert.verifySteps(["spreadsheet_fetch_debit_credit"]); }); + QUnit.test("evaluation with reference to a month period", async (assert) => { + const model = await createModelWithDataSource({ + mockRPC: async function (route, args) { + if (args.method === "spreadsheet_fetch_debit_credit") { + assert.deepEqual(args.args[0], [ + { + codes: ["100"], + company_id: null, + date_range: { + month: 2, + range_type: "month", + year: 2022, + }, + include_unposted: false, + }, + ]); + assert.step("spreadsheet_fetch_debit_credit"); + return [{ debit: 42, credit: 16 }]; + } + }, + }); + setCellContent(model, "B1", "02/2022"); + setCellContent(model, "A1", `=ODOO.CREDIT("100", B1)`); + setCellContent(model, "A2", `=ODOO.DEBIT("100", B1)`); + setCellContent(model, "A3", `=ODOO.BALANCE("100", B1)`); + await waitForDataSourcesLoaded(model); + assert.equal(getCellValue(model, "A1"), 16); + assert.equal(getCellValue(model, "A2"), 42); + assert.equal(getCellValue(model, "A3"), 26); + assert.verifySteps(["spreadsheet_fetch_debit_credit"]); + }); + QUnit.test("Functions are correctly formatted", async (assert) => { const model = await createModelWithDataSource(); setCellContent(model, "A1", `=ODOO.CREDIT("100", "2022")`);