diff --git a/addons/point_of_sale/__manifest__.py b/addons/point_of_sale/__manifest__.py index 432676e06e1..4141441a938 100644 --- a/addons/point_of_sale/__manifest__.py +++ b/addons/point_of_sale/__manifest__.py @@ -206,8 +206,7 @@ 'web/static/lib/ace/mode-js.js', 'web/static/lib/ace/mode-qweb.js', 'web/static/lib/stacktracejs/stacktrace.js', - 'web/static/lib/Chart/Chart.js', - 'web/static/lib/chartjs-adapter-luxon/chartjs-adapter-luxon.js', + ('include', "web.chartjs_lib"), # 'web/static/tests/legacy/main_tests.js', 'web/static/tests/helpers/**/*.js', diff --git a/addons/spreadsheet/static/src/assets_backend/helpers.js b/addons/spreadsheet/static/src/assets_backend/helpers.js index ec4de4ad5f0..56b3a64276c 100644 --- a/addons/spreadsheet/static/src/assets_backend/helpers.js +++ b/addons/spreadsheet/static/src/assets_backend/helpers.js @@ -1,12 +1,11 @@ /** @odoo-module */ -import { loadJS } from "@web/core/assets"; +import { loadBundle } from "@web/core/assets"; /** * Load external libraries required for o-spreadsheet * @returns {Promise} */ export async function loadSpreadsheetDependencies() { - await loadJS("/web/static/lib/Chart/Chart.js"); - await loadJS("/web/static/lib/chartjs-adapter-luxon/chartjs-adapter-luxon.js"); + await loadBundle("web.chartjs_lib"); } diff --git a/addons/spreadsheet/static/src/helpers/model.js b/addons/spreadsheet/static/src/helpers/model.js index c9678853b69..319ec95a452 100644 --- a/addons/spreadsheet/static/src/helpers/model.js +++ b/addons/spreadsheet/static/src/helpers/model.js @@ -3,7 +3,7 @@ import { DataSources } from "@spreadsheet/data_sources/data_sources"; import { Model, parse, helpers, iterateAstNodes } from "@odoo/o-spreadsheet"; import { migrate } from "@spreadsheet/o_spreadsheet/migration"; import { _t } from "@web/core/l10n/translation"; -import { loadJS } from "@web/core/assets"; +import { loadBundle } from "@web/core/assets"; const { toCartesian, UuidGenerator, createEmptySheet } = helpers; const uuidGenerator = new UuidGenerator(); @@ -67,8 +67,7 @@ export async function freezeOdooData(model) { } for (const figure of sheet.figures) { if (figure.tag === "chart" && figure.data.type.startsWith("odoo_")) { - await loadJS("/web/static/lib/Chart/Chart.js"); - await loadJS("/web/static/lib/chartjs-adapter-luxon/chartjs-adapter-luxon.js"); + await loadBundle("web.chartjs_lib"); const img = odooChartToImage(model, figure); figure.tag = "image"; figure.data = { diff --git a/addons/spreadsheet/static/tests/utils/ui.js b/addons/spreadsheet/static/tests/utils/ui.js index f4bd459b1be..649a0016ec3 100644 --- a/addons/spreadsheet/static/tests/utils/ui.js +++ b/addons/spreadsheet/static/tests/utils/ui.js @@ -4,7 +4,7 @@ import { Spreadsheet } from "@odoo/o-spreadsheet"; import { registerCleanup } from "@web/../tests/helpers/cleanup"; import { makeTestEnv } from "@web/../tests/helpers/mock_env"; import { getFixture, nextTick } from "@web/../tests/helpers/utils"; -import { loadJS, templates } from "@web/core/assets"; +import { loadBundle, templates } from "@web/core/assets"; import { PublicReadonlySpreadsheet } from "@spreadsheet/public_readonly_app/public_readonly"; import { App } from "@odoo/owl"; @@ -18,8 +18,7 @@ import { registry } from "@web/core/registry"; * @returns {Promise} */ export async function mountSpreadsheet(model) { - await loadJS("/web/static/lib/Chart/Chart.js"); - await loadJS("/web/static/lib/chartjs-adapter-luxon/chartjs-adapter-luxon.js"); + await loadBundle("web.chartjs_lib"); const app = new App(Spreadsheet, { props: { model }, templates: templates, diff --git a/addons/survey/__manifest__.py b/addons/survey/__manifest__.py index 0f605cdc68f..00ae4f3a3e1 100644 --- a/addons/survey/__manifest__.py +++ b/addons/survey/__manifest__.py @@ -61,8 +61,7 @@ sent mails with personal token for the invitation of the survey. 'sequence': 220, 'assets': { 'survey.survey_assets': [ - 'web/static/lib/Chart/Chart.js', - 'web/static/lib/chartjs-adapter-luxon/chartjs-adapter-luxon.js', + ('include', "web.chartjs_lib"), 'survey/static/src/js/survey_image_zoomer.js', '/survey/static/src/xml/survey_image_zoomer_templates.xml', 'survey/static/src/js/survey_quick_access.js', diff --git a/addons/survey/static/src/js/survey_result.js b/addons/survey/static/src/js/survey_result.js index e4a055a3273..e6a8905c209 100644 --- a/addons/survey/static/src/js/survey_result.js +++ b/addons/survey/static/src/js/survey_result.js @@ -1,7 +1,7 @@ /** @odoo-module **/ import { _t } from "@web/core/l10n/translation"; -import { loadJS } from "@web/core/assets"; +import { loadBundle, loadJS } from "@web/core/assets"; import { SurveyImageZoomer } from "@survey/js/survey_image_zoomer"; import publicWidget from "@web/legacy/js/public/public_widget"; @@ -90,10 +90,6 @@ publicWidget.registry.SurveyResultPagination = publicWidget.Widget.extend({ * */ publicWidget.registry.SurveyResultChart = publicWidget.Widget.extend({ - jsLibs: [ - '/web/static/lib/Chart/Chart.js', - '/web/static/lib/chartjs-adapter-luxon/chartjs-adapter-luxon.js', - ], //-------------------------------------------------------------------------- // Widget @@ -136,6 +132,10 @@ publicWidget.registry.SurveyResultChart = publicWidget.Widget.extend({ }); }, + willStart: async function () { + await loadBundle("web.chartjs_lib"); + }, + // ------------------------------------------------------------------------- // Handlers // ------------------------------------------------------------------------- diff --git a/addons/web/__manifest__.py b/addons/web/__manifest__.py index 5e89180fe18..aee3c669aeb 100644 --- a/addons/web/__manifest__.py +++ b/addons/web/__manifest__.py @@ -426,8 +426,7 @@ This module provides the core of the Odoo Web Client. 'web/static/lib/ace/mode-qweb.js', 'web/static/lib/ace/theme-monokai.js', 'web/static/lib/stacktracejs/stacktrace.js', - 'web/static/lib/Chart/Chart.js', - 'web/static/lib/chartjs-adapter-luxon/chartjs-adapter-luxon.js', + ('include', "web.chartjs_lib"), 'web/static/lib/jSignature/jSignatureCustom.js', 'web/static/src/libs/jSignatureCustom.js', @@ -467,6 +466,10 @@ This module provides the core of the Odoo Web Client. 'web.assets_clickbot': [ 'web/static/src/webclient/clickbot/clickbot.js', ], + "web.chartjs_lib" : [ + '/web/static/lib/Chart/Chart.js', + '/web/static/lib/chartjs-adapter-luxon/chartjs-adapter-luxon.js', + ] }, 'bootstrap': True, # load translations for login screen, 'license': 'LGPL-3', diff --git a/addons/web/static/src/views/fields/gauge/gauge_field.js b/addons/web/static/src/views/fields/gauge/gauge_field.js index 23574355e10..f1a63a944e3 100644 --- a/addons/web/static/src/views/fields/gauge/gauge_field.js +++ b/addons/web/static/src/views/fields/gauge/gauge_field.js @@ -1,7 +1,7 @@ /** @odoo-module **/ import { _t } from "@web/core/l10n/translation"; -import { loadJS } from "@web/core/assets"; +import { loadBundle } from "@web/core/assets"; import { registry } from "@web/core/registry"; import { formatFloat } from "@web/core/utils/numbers"; import { standardFieldProps } from "@web/views/fields/standard_field_props"; @@ -13,7 +13,7 @@ export class GaugeField extends Component { this.chart = null; this.canvasRef = useRef("canvas"); - onWillStart(() => loadJS("/web/static/lib/Chart/Chart.js")); + onWillStart(async () => await loadBundle("web.chartjs_lib")); useEffect(() => { this.renderChart(); diff --git a/addons/web/static/src/views/fields/journal_dashboard_graph/journal_dashboard_graph_field.js b/addons/web/static/src/views/fields/journal_dashboard_graph/journal_dashboard_graph_field.js index eeec2237fc4..c380286118f 100644 --- a/addons/web/static/src/views/fields/journal_dashboard_graph/journal_dashboard_graph_field.js +++ b/addons/web/static/src/views/fields/journal_dashboard_graph/journal_dashboard_graph_field.js @@ -1,6 +1,6 @@ /** @odoo-module **/ -import { loadJS } from "@web/core/assets"; +import { loadBundle } from "@web/core/assets"; import { registry } from "@web/core/registry"; import { getColor, hexToRGBA } from "@web/core/colors/colors"; import { standardFieldProps } from "../standard_field_props"; @@ -20,7 +20,7 @@ export class JournalDashboardGraphField extends Component { this.canvasRef = useRef("canvas"); this.data = JSON.parse(this.props.record.data[this.props.name]); - onWillStart(() => loadJS("/web/static/lib/Chart/Chart.js")); + onWillStart(async () => await loadBundle("web.chartjs_lib")); useEffect(() => { this.renderChart(); diff --git a/addons/web/static/src/views/graph/graph_renderer.js b/addons/web/static/src/views/graph/graph_renderer.js index 2a83db22b98..5e8f4fe02c6 100644 --- a/addons/web/static/src/views/graph/graph_renderer.js +++ b/addons/web/static/src/views/graph/graph_renderer.js @@ -5,7 +5,7 @@ import { getBorderWhite, DEFAULT_BG, getColor, hexToRGBA } from "@web/core/color import { formatFloat } from "@web/views/fields/formatters"; import { SEP } from "./graph_model"; import { sortBy } from "@web/core/utils/arrays"; -import { loadJS } from "@web/core/assets"; +import { loadBundle } from "@web/core/assets"; import { renderToString } from "@web/core/utils/render"; import { useService } from "@web/core/utils/hooks"; @@ -58,8 +58,7 @@ export class GraphRenderer extends Component { this.legendTooltip = null; onWillStart(async () => { - await loadJS("/web/static/lib/Chart/Chart.js"); - await loadJS("/web/static/lib/chartjs-adapter-luxon/chartjs-adapter-luxon.js"); + await loadBundle("web.chartjs_lib"); }); useEffect(() => this.renderChart()); diff --git a/addons/website/static/src/snippets/s_chart/000.js b/addons/website/static/src/snippets/s_chart/000.js index bcf7e0d963b..ec846718447 100644 --- a/addons/website/static/src/snippets/s_chart/000.js +++ b/addons/website/static/src/snippets/s_chart/000.js @@ -1,15 +1,12 @@ /** @odoo-module **/ +import { loadBundle } from "@web/core/assets"; import publicWidget from "@web/legacy/js/public/public_widget"; import weUtils from "@web_editor/js/common/utils"; const ChartWidget = publicWidget.Widget.extend({ selector: '.s_chart', disabledInEditableMode: false, - jsLibs: [ - '/web/static/lib/Chart/Chart.js', - '/web/static/lib/chartjs-adapter-luxon/chartjs-adapter-luxon.js', - ], /** * @override @@ -123,6 +120,10 @@ const ChartWidget = publicWidget.Widget.extend({ this.chart = new window.Chart(canvas, chartData); return this._super.apply(this, arguments); }, + + willStart: async function () { + await loadBundle("web.chartjs_lib"); + }, /** * @override * Discard all library changes to reset the state of the Html. diff --git a/addons/website_links/static/src/js/website_links_charts.js b/addons/website_links/static/src/js/website_links_charts.js index bd2d2270277..5db29d16fcb 100644 --- a/addons/website_links/static/src/js/website_links_charts.js +++ b/addons/website_links/static/src/js/website_links_charts.js @@ -1,14 +1,11 @@ /** @odoo-module **/ +import { loadBundle } from "@web/core/assets"; import { _t } from "@web/core/l10n/translation"; import publicWidget from "@web/legacy/js/public/public_widget"; const { DateTime } = luxon; var BarChart = publicWidget.Widget.extend({ - jsLibs: [ - '/web/static/lib/Chart/Chart.js', - '/web/static/lib/chartjs-adapter-luxon/chartjs-adapter-luxon.js', - ], /** * @constructor * @param {Object} parent @@ -67,13 +64,12 @@ var BarChart = publicWidget.Widget.extend({ var context = canvas.getContext('2d'); new Chart(context, config); }, + willStart: async function () { + await loadBundle("web.chartjs_lib"); + }, }); var PieChart = publicWidget.Widget.extend({ - jsLibs: [ - '/web/static/lib/Chart/Chart.js', - '/web/static/lib/chartjs-adapter-luxon/chartjs-adapter-luxon.js', - ], /** * @override * @param {Object} parent @@ -118,6 +114,9 @@ var PieChart = publicWidget.Widget.extend({ var context = canvas.getContext('2d'); new Chart(context, config); }, + willStart: async function () { + await loadBundle("web.chartjs_lib"); + }, }); publicWidget.registry.websiteLinksCharts = publicWidget.Widget.extend({