Skip to content

Commit

Permalink
[IMP] evaluation: addDependencies now evaluate cell
Browse files Browse the repository at this point in the history
Task Description

When adding a new dependency to a cell (like in the INDIRECT formula),
we have to make sure the dependency have been evaluated before
computing the formula result. To make sure it has at the first evaluation
cycle, we need to force the evaluation of the dependency. This was done
by triggering the evaluation of a new formula, by evaluating a string
containing only a reference to the dependency (the XC path).
This PR update the addDependency method to directly evaluate (if needed)
the new dependency when adding it, in the evaluator, instead of using
the hack of triggering an evaluation after.

closes #4176

Task: 3916213
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
  • Loading branch information
anhe-odoo authored and LucasLefevre committed May 7, 2024
1 parent 853c266 commit 43f4fdd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
12 changes: 2 additions & 10 deletions src/functions/module_lookup.ts
@@ -1,6 +1,6 @@
import { getFullReference, range, toXC, toZone } from "../helpers/index";
import { _t } from "../translation";
import { AddFunctionDescription, CellPosition, CellValue, FPayload, Matrix, Maybe } from "../types";
import { AddFunctionDescription, CellPosition, FPayload, Matrix, Maybe } from "../types";
import { CellErrorType, EvaluationError, InvalidReferenceError } from "../types/errors";
import { arg } from "./arguments";
import {
Expand Down Expand Up @@ -312,15 +312,7 @@ export const INDIRECT: AddFunctionDescription = {
const colValues: FPayload[] = [];
for (let row = range.zone.top; row <= range.zone.bottom; row++) {
const position = { sheetId: range.sheetId, col, row };
// The below 'value' is typed as CellValue because the evaluateFormula will have to
// evaluate a string containing the A1 reference of a single cell, so this will
// return a CellValue.
const value = this.getters.evaluateFormula(range.sheetId, toXC(col, row)) as CellValue;
const evaluatedCell = this.getters.getEvaluatedCell(position);
colValues.push({
...evaluatedCell,
value,
});
colValues.push(this.getters.getEvaluatedCell(position));
}
values.push(colValues);
}
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/ui_core_views/cell_evaluation/evaluator.ts
Expand Up @@ -89,8 +89,9 @@ export class Evaluator {
this.formulaDependencies().addDependencies(position, dependencies);
}

addDependencies(position: CellPosition, dependencies: Range[]) {
private addDependencies(position: CellPosition, dependencies: Range[]) {
this.formulaDependencies().addDependencies(position, dependencies);
this.computeAndSave(position);
}

private updateCompilationParameters() {
Expand Down

0 comments on commit 43f4fdd

Please sign in to comment.