Skip to content

Commit

Permalink
[FIX] pivot: deactivate support for exploded pivot
Browse files Browse the repository at this point in the history
For now, the spreadsheet pivot does not fully support PIVOT.VALUE and
PIVOT.HEADER functions, so we prefer to disable it. It will be reactivate
later.

List of features that are not supported:
- Normalization of arguments, especially with the dates
- Positional arguments (with #)

closes #4025

Task: 3748717
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
  • Loading branch information
pro-odoo committed May 15, 2024
1 parent 6e447f0 commit 2800874
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 12 deletions.
13 changes: 13 additions & 0 deletions src/functions/module_lookup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getFullReference, range, toXC, toZone } from "../helpers/index";
import { supportedPivotExplodedFormulaRegistry } from "../helpers/pivot/pivot_exploded_formula_registry";
import { _t } from "../translation";
import { AddFunctionDescription, CellPosition, FPayload, Matrix, Maybe } from "../types";
import { CellErrorType, EvaluationError, InvalidReferenceError } from "../types/errors";
Expand Down Expand Up @@ -721,6 +722,12 @@ export const PIVOT_VALUE = {
assertDomainLength(domainArgs);
const pivot = this.getters.getPivot(pivotId);
const coreDefinition = this.getters.getPivotCoreDefinition(pivotId);
if (!supportedPivotExplodedFormulaRegistry.get(coreDefinition.type)) {
return {
value: CellErrorType.GenericError,
message: _t("This pivot does not support PIVOT.VALUE formula"),
};
}
addPivotDependencies(this, coreDefinition);
const error = pivot.assertIsValid({ throwOnError: false });
if (error) {
Expand Down Expand Up @@ -752,6 +759,12 @@ export const PIVOT_HEADER = {
assertDomainLength(domainArgs);
const pivot = this.getters.getPivot(_pivotId);
const coreDefinition = this.getters.getPivotCoreDefinition(_pivotId);
if (!supportedPivotExplodedFormulaRegistry.get(coreDefinition.type)) {
return {
value: CellErrorType.GenericError,
message: _t("This pivot does not support PIVOT.VALUE formula"),
};
}
addPivotDependencies(this, coreDefinition);
const error = pivot.assertIsValid({ throwOnError: false });
if (error) {
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/pivot/pivot_exploded_formula_registry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Registry } from "../../registries/registry";
//TODO This registry is only used to disable the support of exploded pivot for spreadsheet
export const supportedPivotExplodedFormulaRegistry = new Registry<boolean>();
supportedPivotExplodedFormulaRegistry.add("SPREADSHEET", false);
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ import {
unquote,
} from "./helpers/index";
import { openLink, urlRegistry, urlRepresentation } from "./helpers/links";
import { supportedPivotExplodedFormulaRegistry } from "./helpers/pivot/pivot_exploded_formula_registry";
import {
getFirstPivotFunction,
getMaxObjectId,
Expand Down Expand Up @@ -256,6 +257,7 @@ export const registries = {
pivotRegistry,
pivotTimeAdapterRegistry,
pivotSidePanelRegistry,
supportedPivotExplodedFormulaRegistry,
};
export const helpers = {
arg,
Expand Down
44 changes: 32 additions & 12 deletions src/registries/auto_completes/pivot_auto_complete.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { tokenColors } from "../../components/composer/composer/composer";
import { EnrichedToken } from "../../formulas/composer_tokenizer";
import { isDefined } from "../../helpers";
import { supportedPivotExplodedFormulaRegistry } from "../../helpers/pivot/pivot_exploded_formula_registry";
import {
extractFormulaIdFromToken,
insertTokenAfterArgSeparator,
Expand All @@ -27,17 +28,25 @@ autoCompleteProviders.add("pivot_ids", {
if (pivotIds.includes(tokenAtCursor.value)) {
return;
}
return pivotIds.map((pivotId) => {
const definition = this.getters.getPivotCoreDefinition(pivotId);
const formulaId = this.getters.getPivotFormulaId(pivotId);
const str = `${formulaId}`;
return {
text: str,
description: definition.name,
htmlContent: [{ value: str, color: tokenColors.NUMBER }],
fuzzySearchKey: str + definition.name,
};
});
return pivotIds
.map((pivotId) => {
const definition = this.getters.getPivotCoreDefinition(pivotId);
if (
functionContext.parent.toUpperCase() !== "PIVOT" &&
!supportedPivotExplodedFormulaRegistry.get(definition.type)
) {
return undefined;
}
const formulaId = this.getters.getPivotFormulaId(pivotId);
const str = `${formulaId}`;
return {
text: str,
description: definition.name,
htmlContent: [{ value: str, color: tokenColors.NUMBER }],
fuzzySearchKey: str + definition.name,
};
})
.filter(isDefined);
},
selectProposal: insertTokenAfterLeftParenthesis,
});
Expand All @@ -64,6 +73,9 @@ autoCompleteProviders.add("pivot_measures", {
return [];
}
const definition = this.getters.getPivotCoreDefinition(pivotId);
if (!supportedPivotExplodedFormulaRegistry.get(definition.type)) {
return [];
}
return definition.measures
.map((measure) => {
if (measure.name === "__count") {
Expand Down Expand Up @@ -107,6 +119,10 @@ autoCompleteProviders.add("pivot_group_fields", {
if (!fields) {
return;
}
const { columns, rows, type } = this.getters.getPivotCoreDefinition(pivotId);
if (!supportedPivotExplodedFormulaRegistry.get(type)) {
return [];
}
let args = functionContext.args;
if (functionContext?.parent.toUpperCase() === "PIVOT.VALUE") {
args = args.filter((ast, index) => index % 2 === 0); // keep only the field names
Expand All @@ -115,7 +131,6 @@ autoCompleteProviders.add("pivot_group_fields", {
args = args.filter((ast, index) => index % 2 === 1); // keep only the field names
}
const argGroupBys = args.map((ast) => ast?.value).filter(isDefined);
const { columns, rows } = this.getters.getPivotCoreDefinition(pivotId);
const colFields = columns.map((groupBy) => groupBy.name);
const rowFields = rows.map((groupBy) => groupBy.name);

Expand Down Expand Up @@ -200,6 +215,11 @@ autoCompleteProviders.add("pivot_group_values", {
if (!pivotId || !this.getters.isExistingPivot(pivotId)) {
return;
}
const { type } = this.getters.getPivotCoreDefinition(pivotId);
if (!supportedPivotExplodedFormulaRegistry.get(type)) {
return [];
}

const dataSource = this.getters.getPivot(pivotId);
if (!dataSource.isValid()) {
return;
Expand Down

0 comments on commit 2800874

Please sign in to comment.