Skip to content

Commit 67031f4

Browse files
committed
[FIX] functions: fix LINEST error massage
The functions using the helper `tryCastAsNumberMatrix` had a wrong error message: - the two arguments in the translated string were inverted - an argument of `_t` was `typeof cell`, which isn't translated - the other argument of the `_t` was something like `the first argument (data_y)`, which wasn't translated either closes #7299 Task: 5059375 X-original-commit: b796c32 Signed-off-by: Rémi Rahir (rar) <rar@odoo.com> Signed-off-by: Adrien Minne (adrm) <adrm@odoo.com>
1 parent 0de6c33 commit 67031f4

File tree

4 files changed

+48
-30
lines changed

4 files changed

+48
-30
lines changed

src/functions/helpers.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,24 @@ export function toNumberMatrix(data: Arg, argName: string): Matrix<number> {
119119
return toMatrix(data).map((row) => {
120120
return row.map((cell) => {
121121
if (typeof cell.value !== "number") {
122-
throw new EvaluationError(
123-
_t(
124-
"Function [[FUNCTION_NAME]] expects number values for %s, but got a %s.",
125-
argName,
126-
typeof cell.value
127-
)
128-
);
122+
let message = "";
123+
if (typeof cell === "object") {
124+
message = _t(
125+
"Function [[FUNCTION_NAME]] expects number values for %s, but got an empty value.",
126+
argName
127+
);
128+
} else if (typeof cell === "string") {
129+
message = _t(
130+
"Function [[FUNCTION_NAME]] expects number values for %s, but got a string.",
131+
argName
132+
);
133+
} else if (typeof cell === "boolean") {
134+
message = _t(
135+
"Function [[FUNCTION_NAME]] expects number values for %s, but got a boolean.",
136+
argName
137+
);
138+
}
139+
throw new EvaluationError(message);
129140
}
130141
return cell.value;
131142
});

src/functions/module_statistical.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -573,9 +573,9 @@ export const GROWTH: AddFunctionDescription = {
573573
assertNonEmptyMatrix(knownDataY, "known_data_y");
574574
return expM(
575575
predictLinearValues(
576-
logM(toNumberMatrix(knownDataY, "the first argument (known_data_y)")),
577-
toNumberMatrix(knownDataX, "the second argument (known_data_x)"),
578-
toNumberMatrix(newDataX, "the third argument (new_data_y)"),
576+
logM(toNumberMatrix(knownDataY, "known_data_y")),
577+
toNumberMatrix(knownDataX, "known_data_x"),
578+
toNumberMatrix(newDataX, "new_data_y"),
579579
toBoolean(b)
580580
)
581581
);
@@ -687,8 +687,8 @@ export const LINEST: AddFunctionDescription = {
687687
): (number | string)[][] {
688688
assertNonEmptyMatrix(dataY, "data_y");
689689
return fullLinearRegression(
690-
toNumberMatrix(dataX, "the first argument (data_y)"),
691-
toNumberMatrix(dataY, "the second argument (data_x)"),
690+
toNumberMatrix(dataX, "data_x"),
691+
toNumberMatrix(dataY, "data_y"),
692692
toBoolean(calculateB),
693693
toBoolean(verbose)
694694
);
@@ -731,8 +731,8 @@ export const LOGEST: AddFunctionDescription = {
731731
): (number | string)[][] {
732732
assertNonEmptyMatrix(dataY, "data_y");
733733
const coeffs = fullLinearRegression(
734-
toNumberMatrix(dataX, "the second argument (data_x)"),
735-
logM(toNumberMatrix(dataY, "the first argument (data_y)")),
734+
toNumberMatrix(dataX, "data_x"),
735+
logM(toNumberMatrix(dataY, "data_y")),
736736
toBoolean(calculateB),
737737
toBoolean(verbose)
738738
);
@@ -1596,9 +1596,9 @@ export const TREND: AddFunctionDescription = {
15961596
): Matrix<number> {
15971597
assertNonEmptyMatrix(knownDataY, "known_data_y");
15981598
return predictLinearValues(
1599-
toNumberMatrix(knownDataY, "the first argument (known_data_y)"),
1600-
toNumberMatrix(knownDataX, "the second argument (known_data_x)"),
1601-
toNumberMatrix(newDataX, "the third argument (new_data_y)"),
1599+
toNumberMatrix(knownDataY, "known_data_y"),
1600+
toNumberMatrix(knownDataX, "known_data_x"),
1601+
toNumberMatrix(newDataX, "new_data_y"),
16021602
toBoolean(b)
16031603
);
16041604
},

tests/functions/module_array.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ describe("MDETERM function", () => {
829829
setCellContent(model, "D1", "=MDETERM(A1:C3)");
830830
expect(getEvaluatedCell(model, "D1").value).toBe("#ERROR");
831831
expect((getEvaluatedCell(model, "D1") as ErrorCell).message).toBe(
832-
"Function MDETERM expects number values for square_matrix, but got a object."
832+
"Function MDETERM expects number values for square_matrix, but got an empty value."
833833
);
834834
});
835835
});
@@ -871,7 +871,7 @@ describe("MINVERSE function", () => {
871871
setCellContent(model, "D1", "=MINVERSE(A1:C3)");
872872
expect(getEvaluatedCell(model, "D1").value).toBe("#ERROR");
873873
expect((getEvaluatedCell(model, "D1") as ErrorCell).message).toBe(
874-
"Function MINVERSE expects number values for square_matrix, but got a object."
874+
"Function MINVERSE expects number values for square_matrix, but got an empty value."
875875
);
876876
});
877877

tests/functions/module_statistical.test.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ describe("AVERAGEA formula", () => {
438438
// prettier-ignore
439439
const grid = {
440440
A1: "40", B1: "42",
441-
A2: "41", B2: "=KABOUM",
441+
A2: "41", B2: "=KABOUM",
442442
};
443443
expect(evaluateCell("A3", { A3: "=AVERAGEA(A1:A2, B1:B2)", ...grid })).toBe("#BAD_EXPR");
444444
});
@@ -488,8 +488,8 @@ describe("AVERAGEIF formula", () => {
488488
// prettier-ignore
489489
const grid = {
490490
A1: "=KABOUM", B1: "42",
491-
A2: "41", B2: "43",
492-
A3: "44", B3: "45",
491+
A2: "41", B2: "43",
492+
A3: "44", B3: "45",
493493
};
494494
expect(evaluateCell("A4", { A4: "=AVERAGEIF(A1:A3, KABOUM, B1:B3)", ...grid })).toBe(
495495
"#BAD_EXPR"
@@ -542,8 +542,8 @@ describe("AVERAGEIFS formula", () => {
542542
// prettier-ignore
543543
const grid = {
544544
A1: "=KABOUM", B1: "42",
545-
A2: "41", B2: "43",
546-
A3: "44", B3: "45",
545+
A2: "41", B2: "43",
546+
A3: "44", B3: "45",
547547
};
548548
expect(evaluateCell("A4", { A4: "=AVERAGEIFS(B1:B3, A1:A3, KABOUM)", ...grid })).toBe(
549549
"#BAD_EXPR"
@@ -620,7 +620,7 @@ describe("COUNT formula", () => {
620620
// prettier-ignore
621621
const grid = {
622622
A1: "=KABOUM", B1: "42",
623-
A2: "42", B2: "=1/0",
623+
A2: "42", B2: "=1/0",
624624
};
625625
expect(evaluateCell("A3", { A3: "=COUNT(A1:B2)", ...grid })).toBe(2);
626626
});
@@ -694,7 +694,7 @@ describe("COUNTA formula", () => {
694694
// prettier-ignore
695695
const grid = {
696696
A1: "=KABOUM", B1: "42",
697-
A2: "42", B2: "=1/0",
697+
A2: "42", B2: "=1/0",
698698
};
699699
expect(evaluateCell("A3", { A3: "=COUNTA(A1:B2)", ...grid })).toBe(4);
700700
});
@@ -737,8 +737,8 @@ describe("COVAR formula", () => {
737737
// prettier-ignore
738738
const grid = {
739739
A1: "=KABOUM", B1: "42",
740-
A2: "42", B2: "1",
741-
A3: "44", B3: "2",
740+
A2: "42", B2: "1",
741+
A3: "44", B3: "2",
742742
};
743743
expect(evaluateCell("A4", { A4: "=COVAR(A1:A3, B1:B3)", ...grid })).toBe("#BAD_EXPR");
744744
});
@@ -781,8 +781,8 @@ describe("COVARIANCE.P formula", () => {
781781
// prettier-ignore
782782
const grid = {
783783
A1: "=KABOUM", B1: "42",
784-
A2: "42", B2: "1",
785-
A3: "44", B3: "2",
784+
A2: "42", B2: "1",
785+
A3: "44", B3: "2",
786786
};
787787
expect(evaluateCell("A4", { A4: "=COVARIANCE.P(A1:A3, B1:B3)", ...grid })).toBe("#BAD_EXPR");
788788
});
@@ -3883,6 +3883,13 @@ describe("LINEST formula", () => {
38833883
const model = createModelFromGrid(grid);
38843884
expect(getEvaluatedCell(model, "A10").value).toBe("#ERROR");
38853885
});
3886+
3887+
test("Error message with empty values is correct", () => {
3888+
const model = createModelFromGrid({ A1: "=LINEST(C1:C2)" });
3889+
expect((getEvaluatedCell(model, "A1") as ErrorCell).message).toBe(
3890+
"Function LINEST expects number values for data_y, but got an empty value."
3891+
);
3892+
});
38863893
});
38873894

38883895
describe("LOGEST formula", () => {

0 commit comments

Comments
 (0)