[FIX] spreadsheet*: fix o-spreadsheet dependencies

The recent upgrade to chart.js 4.3.0 has forced us to make our own
plugin to support gauge charts. The plugin was added inside the
o-spreadsheet library which means that we now require chart.js to be
loaded before o-spreadsheet.

Notice we created a `spreadsheet.dependencies` assets bundle but
we don't include it in `spreadsheet.o_spreadsheet` bundle not do we use
it in the webclient code.

That's because `Chart.js` cannot be reloaded after the spreadsheet bundle
is loaded and the plugin was added. Reloading it after would override
`Chart.js` and remove the plugin. To prevent such situation, we
use `loadJS("/web/static/lib/Chart/Chart.js");` which is memoized. The same
call elsewhere in the code base won't actually ovewrite `Chart.js`.

closes odoo/odoo#133369

Task: 3482480
Related: odoo/enterprise#46424
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
This commit is contained in:
Rémi Rahir (rar)
2023-08-31 09:04:56 +00:00
committed by Lucas Lefèvre (lul)
parent c111b9ac44
commit 83eaa9b37b
6 changed files with 20 additions and 14 deletions
+6
View File
@@ -13,6 +13,10 @@
'views/public_readonly_spreadsheet_templates.xml',
],
'assets': {
'spreadsheet.dependencies': [
'web/static/lib/Chart/Chart.js',
'web/static/lib/chartjs-adapter-luxon/chartjs-adapter-luxon.js',
],
'spreadsheet.o_spreadsheet': [
'spreadsheet/static/src/o_spreadsheet/o_spreadsheet.js',
'spreadsheet/static/src/**/*.js',
@@ -54,6 +58,7 @@
'web/static/src/core/user_service.js',
'web/static/src/core/l10n/**/*.js',
'web/static/src/core/network/download.js',
('include', 'spreadsheet.dependencies'),
'spreadsheet/static/src/o_spreadsheet/o_spreadsheet.js',
'spreadsheet/static/src/o_spreadsheet/o_spreadsheet.xml',
'spreadsheet/static/src/o_spreadsheet/o_spreadsheet_extended.scss',
@@ -74,6 +79,7 @@
'spreadsheet/static/src/**/*.dark.scss',
],
'web.qunit_suite_tests': [
('include', 'spreadsheet.dependencies'),
'spreadsheet/static/tests/**/*',
('include', 'spreadsheet.o_spreadsheet'),
'spreadsheet/static/src/public_readonly_app/**/*.xml',
@@ -0,0 +1,12 @@
/** @odoo-module */
import { loadJS } from "@web/core/assets";
/**
* Load external libraries required for o-spreadsheet
* @returns {Promise<void>}
*/
export async function loadSpreadsheetDependencies() {
await loadJS("/web/static/lib/Chart/Chart.js");
await loadJS("/web/static/lib/chartjs-adapter-luxon/chartjs-adapter-luxon.js");
}
@@ -4,6 +4,7 @@ import { _t } from "@web/core/l10n/translation";
import { registry } from "@web/core/registry";
import { getBundle, loadBundle } from "@web/core/assets";
import { sprintf } from "@web/core/utils/strings";
import { loadSpreadsheetDependencies } from "./helpers";
const actionRegistry = registry.category("actions");
@@ -14,6 +15,7 @@ const actionRegistry = registry.category("actions");
* @param {function} actionLazyLoader
*/
export async function loadSpreadsheetAction(env, actionName, actionLazyLoader) {
await loadSpreadsheetDependencies();
const desc = await getBundle("spreadsheet.o_spreadsheet");
await loadBundle(desc);
@@ -1,7 +1,6 @@
/** @odoo-module */
import { serializeDate } from "@web/core/l10n/dates";
import { loadJS } from "@web/core/assets";
const { DateTime } = luxon;
@@ -95,12 +94,3 @@ export function isEmpty(item) {
}
return false;
}
/**
* Load external libraries required for o-spreadsheet
* @returns {Promise<void>}
*/
export async function loadSpreadsheetDependencies() {
await loadJS("/web/static/lib/Chart/Chart.js");
await loadJS("/web/static/lib/chartjs-adapter-luxon/chartjs-adapter-luxon.js");
}
@@ -7,7 +7,6 @@ import { download } from "@web/core/network/download";
import * as spreadsheet from "@odoo/o-spreadsheet";
import { Spreadsheet, Model, registries } from "@odoo/o-spreadsheet";
import { _t } from "@web/core/l10n/translation";
import { loadSpreadsheetDependencies } from "../helpers/helpers";
import { migrate } from "../o_spreadsheet/migration";
registries.topbarMenuRegistry.addChild("download_public_excel", ["file"], {
@@ -35,7 +34,6 @@ export class PublicReadonlySpreadsheet extends Component {
data: {},
}),
});
onWillStart(loadSpreadsheetDependencies);
onWillStart(this.createModel.bind(this));
}
@@ -8,7 +8,6 @@ import { useSetupAction } from "@web/webclient/actions/action_hook";
import { DashboardMobileSearchPanel } from "./mobile_search_panel/mobile_search_panel";
import { MobileFigureContainer } from "./mobile_figure_container/mobile_figure_container";
import { FilterValue } from "@spreadsheet/global_filters/components/filter_value/filter_value";
import { loadSpreadsheetDependencies } from "@spreadsheet/helpers/helpers";
import { useService } from "@web/core/utils/hooks";
import { standardActionServiceProps } from "@web/webclient/actions/action_service";
import { SpreadsheetShareButton } from "@spreadsheet/components/share_button/share_button";
@@ -30,7 +29,6 @@ export class SpreadsheetDashboardAction extends Component {
new DashboardLoader(this.env, this.env.services.orm, this._fetchDashboardData)
);
onWillStart(async () => {
await loadSpreadsheetDependencies();
if (this.props.state && this.props.state.dashboardLoader) {
const { groups, dashboards } = this.props.state.dashboardLoader;
this.loader.restoreFromState(groups, dashboards);