[FIX] spreadsheet_account: take correct date period
Steps to reproduce:
- in A1, type '02/2024'
- in A2, type '=ODOO.BALANCE("100", A1)'
=> the result you get come from account lines
for the day 2024/02/1 instead of the full
february month.
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
closes odoo/odoo#163156
Signed-off-by: Vincent Schippefilt (vsc) <vsc@odoo.com>
This commit is contained in:
@@ -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 =
|
||||
|
||||
@@ -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")`);
|
||||
|
||||
Reference in New Issue
Block a user