[FIX] spreadsheet: remove filter matching when chart is deleted
If you insert an odoo chart, match a filter with one of the chart field, then delete the chart => the field matching is not removed and is still exported The same goes for pivot and list matching when they are removed closes odoo/odoo#100390 Signed-off-by: Pierre Rousseau (pro) <pro@odoo.com>
This commit is contained in:
@@ -26,7 +26,6 @@ import spreadsheet from "@spreadsheet/o_spreadsheet/o_spreadsheet_extended";
|
||||
import CommandResult from "@spreadsheet/o_spreadsheet/cancelled_reason";
|
||||
import { checkFiltersTypeValueCombination } from "@spreadsheet/global_filters/helpers";
|
||||
|
||||
|
||||
export default class FiltersPlugin extends spreadsheet.CorePlugin {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
@@ -78,6 +77,15 @@ export default class FiltersPlugin extends spreadsheet.CorePlugin {
|
||||
case "REMOVE_GLOBAL_FILTER":
|
||||
this._removeGlobalFilter(cmd.id);
|
||||
break;
|
||||
case "REMOVE_PIVOT":
|
||||
this._removeMatchingField("pivot", cmd.pivotId);
|
||||
break;
|
||||
case "REMOVE_ODOO_LIST":
|
||||
this._removeMatchingField("list", cmd.listId);
|
||||
break;
|
||||
case "DELETE_FIGURE":
|
||||
this._removeMatchingField("graph", cmd.id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,6 +209,22 @@ export default class FiltersPlugin extends spreadsheet.CorePlugin {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {"pivot" | "list" | "graph"} dataSourceType
|
||||
* @param {string} dataSourceId
|
||||
*/
|
||||
_removeMatchingField(dataSourceType, dataSourceId) {
|
||||
for (const filter of this.getGlobalFilters()) {
|
||||
this.history.update(
|
||||
"globalFilters",
|
||||
filter.id,
|
||||
`${dataSourceType}Fields`,
|
||||
dataSourceId,
|
||||
undefined
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Import/Export
|
||||
// ---------------------------------------------------------------------
|
||||
@@ -240,8 +264,8 @@ export default class FiltersPlugin extends spreadsheet.CorePlugin {
|
||||
_updateFilterLabelInFormulas(currentLabel, newLabel) {
|
||||
const sheetIds = this.getters.getSheetIds();
|
||||
currentLabel = currentLabel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
for (let sheetId of sheetIds) {
|
||||
for (let cell of Object.values(this.getters.getCells(sheetId))) {
|
||||
for (const sheetId of sheetIds) {
|
||||
for (const cell of Object.values(this.getters.getCells(sheetId))) {
|
||||
if (cell.isFormula()) {
|
||||
const newContent = cell.content.replace(
|
||||
new RegExp(`FILTER\\.VALUE\\(\\s*"${currentLabel}"\\s*\\)`, "g"),
|
||||
|
||||
@@ -66,4 +66,29 @@ QUnit.module("spreadsheet > Global filters chart", {}, () => {
|
||||
assert.equal(computedDomain.length, 3);
|
||||
assert.equal(computedDomain[0], "&");
|
||||
});
|
||||
|
||||
QUnit.test("field matching is removed when chart is deleted", async function (assert) {
|
||||
const { model } = await createSpreadsheetWithGraph();
|
||||
await addChartGlobalFilter(model);
|
||||
const [filter] = model.getters.getGlobalFilters();
|
||||
const [chartId] = model.getters.getChartIds(model.getters.getActiveSheetId());
|
||||
const matching = {
|
||||
field: "date",
|
||||
type: "date",
|
||||
};
|
||||
assert.deepEqual(model.getters.getGlobalFilterFieldGraph(filter.id, chartId), matching);
|
||||
model.dispatch("DELETE_FIGURE", {
|
||||
sheetId: model.getters.getActiveSheetId(),
|
||||
id: chartId,
|
||||
});
|
||||
assert.strictEqual(
|
||||
model.getters.getGlobalFilterFieldGraph(filter.id, chartId),
|
||||
undefined,
|
||||
"it should have removed the field matching with the chart"
|
||||
);
|
||||
model.dispatch("REQUEST_UNDO");
|
||||
assert.deepEqual(model.getters.getGlobalFilterFieldGraph(filter.id, chartId), matching);
|
||||
model.dispatch("REQUEST_REDO");
|
||||
assert.strictEqual(model.getters.getGlobalFilterFieldGraph(filter.id, chartId), undefined);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1534,4 +1534,40 @@ QUnit.module("spreadsheet > Global filters model", {}, () => {
|
||||
assert.deepEqual(filters, [{ filterId: "42", value: [41] }]);
|
||||
}
|
||||
);
|
||||
|
||||
QUnit.test("field matching is removed when pivot is deleted", async function (assert) {
|
||||
const { model } = await createSpreadsheetWithPivot();
|
||||
await addGlobalFilter(model, LAST_YEAR_FILTER);
|
||||
const [pivotId] = model.getters.getPivotIds();
|
||||
const [filter] = model.getters.getGlobalFilters();
|
||||
const matching = {
|
||||
field: "date",
|
||||
type: "date",
|
||||
};
|
||||
assert.deepEqual(model.getters.getGlobalFilterFieldPivot(filter.id, pivotId), matching);
|
||||
model.dispatch("REMOVE_PIVOT", { pivotId });
|
||||
assert.strictEqual(model.getters.getGlobalFilterFieldPivot(filter.id, pivotId), undefined);
|
||||
model.dispatch("REQUEST_UNDO");
|
||||
assert.deepEqual(model.getters.getGlobalFilterFieldPivot(filter.id, pivotId), matching);
|
||||
model.dispatch("REQUEST_REDO");
|
||||
assert.strictEqual(model.getters.getGlobalFilterFieldPivot(filter.id, pivotId), undefined);
|
||||
});
|
||||
|
||||
QUnit.test("field matching is removed when list is deleted", async function (assert) {
|
||||
const { model } = await createSpreadsheetWithList();
|
||||
await addGlobalFilter(model, LAST_YEAR_FILTER);
|
||||
const [listId] = model.getters.getListIds();
|
||||
const [filter] = model.getters.getGlobalFilters();
|
||||
const matching = {
|
||||
field: "date",
|
||||
type: "date",
|
||||
};
|
||||
assert.deepEqual(model.getters.getGlobalFilterFieldList(filter.id, listId), matching);
|
||||
model.dispatch("REMOVE_ODOO_LIST", { listId });
|
||||
assert.strictEqual(model.getters.getGlobalFilterFieldList(filter.id, listId), undefined);
|
||||
model.dispatch("REQUEST_UNDO");
|
||||
assert.deepEqual(model.getters.getGlobalFilterFieldList(filter.id, listId), matching);
|
||||
model.dispatch("REQUEST_REDO");
|
||||
assert.strictEqual(model.getters.getGlobalFilterFieldList(filter.id, listId), undefined);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1997,11 +1997,6 @@
|
||||
}
|
||||
},
|
||||
"graphFields": {
|
||||
"0833ccd2-8b33-4840-a4b6-0dcad53fc86e": {
|
||||
"field": "invoice_date",
|
||||
"type": "date",
|
||||
"offset": 0
|
||||
},
|
||||
"5ea5dd7f-9f83-4482-a2bb-2ec72ab35912": {
|
||||
"field": "invoice_date",
|
||||
"type": "date",
|
||||
@@ -2055,10 +2050,6 @@
|
||||
}
|
||||
},
|
||||
"graphFields": {
|
||||
"0833ccd2-8b33-4840-a4b6-0dcad53fc86e": {
|
||||
"field": "country_id",
|
||||
"type": "many2one"
|
||||
},
|
||||
"5ea5dd7f-9f83-4482-a2bb-2ec72ab35912": {
|
||||
"field": "country_id",
|
||||
"type": "many2one"
|
||||
|
||||
Reference in New Issue
Block a user