[FIX] spreadsheet: fix crash if odoo charts in removed sheet

__Current behavior before commit:__
When a sheet is deleted, `charts` from `OdooChartCorePlugin` are not
being updated.
Therefore, since the commit [`905d856`][1], `getOdooChartIds` returns
some chart ids that do not exist on any sheet anymore.

This induces a crash when opening a spreadsheet that contains such
charts.

__Description of the fix:__
Handle `DELETE_SHEET` event in `OdooChartCorePlugin` by removing Odoo
charts that don't belong to any sheet.

__Steps to reproduce the issue on runbot:__
- Insert a Odoo graph inside a spreadsheet (starting from any app)
- Add a sheet to it to the new spreadsheet
- Delete the sheet that contains the chart
- Leave the spreadsheet
- Go to Documents app and try to open the spreadsheet
-> Traceback

opw-3783745

[1]: https://github.com/odoo/odoo/commit/905d8565ad2fae3f7ff96606352ee3ab86ee78cb

closes odoo/odoo#157847

X-original-commit: d44c45234577d19a728e92368f224b0e0e59e853
Signed-off-by: Vincent Schippefilt (vsc) <vsc@odoo.com>
This commit is contained in:
Julien (jula)
2024-03-17 20:01:41 +00:00
committed by Vincent Schippefilt
parent c3fe38362c
commit 56d45bc015
@@ -579,4 +579,16 @@ QUnit.module("spreadsheet > odoo chart plugin", {}, () => {
insertChartInSpreadsheet(model);
assert.strictEqual(model.getters.getChartIds(sheetId).length, 1);
});
QUnit.test("Remove odoo chart when sheet is deleted", async (assert) => {
const { model } = await createSpreadsheetWithChart({ type: "odoo_line" });
const sheetId = model.getters.getActiveSheetId();
model.dispatch("CREATE_SHEET", {
sheetId: model.uuidGenerator.uuidv4(),
position: model.getters.getSheetIds().length,
});
assert.strictEqual(model.getters.getOdooChartIds().length, 1);
model.dispatch("DELETE_SHEET", { sheetId });
assert.strictEqual(model.getters.getOdooChartIds().length, 0);
});
});