Skip to content

Commit b796c32

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 #7290 Task: 5059375 X-original-commit: 03fc65a Signed-off-by: Rémi Rahir (rar) <rar@odoo.com> Signed-off-by: Adrien Minne (adrm) <adrm@odoo.com>
1 parent ff8bba9 commit b796c32

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
@@ -105,13 +105,24 @@ export function toNumberMatrix(data: Arg, argName: string): Matrix<number> {
105105
return toMatrix(data).map((row) => {
106106
return row.map((cell) => {
107107
if (typeof cell.value !== "number") {
108-
throw new EvaluationError(
109-
_t(
110-
"Function [[FUNCTION_NAME]] expects number values for %s, but got a %s.",
111-
argName,
112-
typeof cell.value
113-
)
114-
);
108+
let message = "";
109+
if (typeof cell === "object") {
110+
message = _t(
111+
"Function [[FUNCTION_NAME]] expects number values for %s, but got an empty value.",
112+
argName
113+
);
114+
} else if (typeof cell === "string") {
115+
message = _t(
116+
"Function [[FUNCTION_NAME]] expects number values for %s, but got a string.",
117+
argName
118+
);
119+
} else if (typeof cell === "boolean") {
120+
message = _t(
121+
"Function [[FUNCTION_NAME]] expects number values for %s, but got a boolean.",
122+
argName
123+
);
124+
}
125+
throw new EvaluationError(message);
115126
}
116127
return cell.value;
117128
});

src/functions/module_statistical.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -574,9 +574,9 @@ export const GROWTH: AddFunctionDescription = {
574574
assertNonEmptyMatrix(knownDataY, "known_data_y");
575575
return expM(
576576
predictLinearValues(
577-
logM(toNumberMatrix(knownDataY, "the first argument (known_data_y)")),
578-
toNumberMatrix(knownDataX, "the second argument (known_data_x)"),
579-
toNumberMatrix(newDataX, "the third argument (new_data_y)"),
577+
logM(toNumberMatrix(knownDataY, "known_data_y")),
578+
toNumberMatrix(knownDataX, "known_data_x"),
579+
toNumberMatrix(newDataX, "new_data_y"),
580580
toBoolean(b)
581581
)
582582
);
@@ -688,8 +688,8 @@ export const LINEST: AddFunctionDescription = {
688688
): (number | string)[][] {
689689
assertNonEmptyMatrix(dataY, "data_y");
690690
return fullLinearRegression(
691-
toNumberMatrix(dataX, "the first argument (data_y)"),
692-
toNumberMatrix(dataY, "the second argument (data_x)"),
691+
toNumberMatrix(dataX, "data_x"),
692+
toNumberMatrix(dataY, "data_y"),
693693
toBoolean(calculateB),
694694
toBoolean(verbose)
695695
);
@@ -732,8 +732,8 @@ export const LOGEST: AddFunctionDescription = {
732732
): (number | string)[][] {
733733
assertNonEmptyMatrix(dataY, "data_y");
734734
const coeffs = fullLinearRegression(
735-
toNumberMatrix(dataX, "the second argument (data_x)"),
736-
logM(toNumberMatrix(dataY, "the first argument (data_y)")),
735+
toNumberMatrix(dataX, "data_x"),
736+
logM(toNumberMatrix(dataY, "data_y")),
737737
toBoolean(calculateB),
738738
toBoolean(verbose)
739739
);
@@ -1597,9 +1597,9 @@ export const TREND: AddFunctionDescription = {
15971597
): Matrix<number> {
15981598
assertNonEmptyMatrix(knownDataY, "known_data_y");
15991599
return predictLinearValues(
1600-
toNumberMatrix(knownDataY, "the first argument (known_data_y)"),
1601-
toNumberMatrix(knownDataX, "the second argument (known_data_x)"),
1602-
toNumberMatrix(newDataX, "the third argument (new_data_y)"),
1600+
toNumberMatrix(knownDataY, "known_data_y"),
1601+
toNumberMatrix(knownDataX, "known_data_x"),
1602+
toNumberMatrix(newDataX, "new_data_y"),
16031603
toBoolean(b)
16041604
);
16051605
},

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)