From 08dcbc8f1def06476d025b110049ee596e906816 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Thu, 15 Sep 2022 15:52:52 +0000 Subject: [PATCH] [IMP] web, *: move assets_common files directly inside assets_frontend *: auth_password_policy, bus, calendar, event, mass_mailing, stock, survey, web_editor, web_tour, website, website_event, website_forum, website_mass_mailing, website_sale This commit is a first step towards a potential deletion of the assets_common bundle, although that step would need more work, specs and discussions as some layouts kinda only use the assets_common bundle (some take the full assets_common but parts of the assets_backend one for example). The main goal of this commit is to have the assets_frontend bundle directly include the "common" files we need. As a first step, this commit only blindly duplicates them all into assets_frontend (without removing the potentially useless ones). The goal is to have those advantages: - Reaching a frontend page only calls two main JS files (one normal and one lazy-loaded) instead of 4 (two normals and two lazy-loaded). This may help reach a better google page speed (which is becoming more and more strict). - The frontend CSS is built as one: the common SCSS which was using bootstrap variables, or even Odoo-based SCSS added by mistake in common instead of both backend and frontend is now computed with the right bootstrap customizations. E.g. the tempusdominus datetimepickers use bootstrap grays... after this PR, they use the right grays as customized by the user on the website. It was also chosen to not have a common "sub-asset" which is included in assets_frontend. Making assets_frontend completely independent makes sense (as it probably will for other "main" asset bundles): we can focus on adding the files each layout needs without the need of worrying if it impacts unrelated layouts. Sub-assets (when not strictly necessary) is also a source of errors: extending the "main" bundle instead of the right sub-asset it may use (like it was the case with the sub-assets of assets_common: _assets_common_scripts and _assets_common_styles as explained in the previous commit). So this is indeed a small drawback of not factorizing the code for the inclusion of "common" files in bundles but it seems more explicit and easier to maintain that way. Note that adding "common" file is not the most common usecase anyway, apps generally only need files in backend or frontend. The __manifest__ declaration will also likely evolve in more and more uses of wildcards to match entire directories. In the future, adding "common" web-app files in both backend, frontend and other "main" bundles could just be about one line duplicated into each bundle. closes odoo/odoo#100314 Related: odoo/enterprise#31394 Signed-off-by: Romain Derie (rde) --- addons/auth_password_policy/__manifest__.py | 4 + addons/bus/__manifest__.py | 6 + addons/calendar/views/calendar_templates.xml | 1 - addons/event/__manifest__.py | 3 + addons/mass_mailing/__manifest__.py | 3 + addons/mass_mailing/views/assets.xml | 1 - addons/stock/__manifest__.py | 3 + addons/survey/__manifest__.py | 3 + addons/web/__manifest__.py | 181 +++++++++++++++--- addons/web/views/webclient_templates.xml | 3 - addons/web_editor/__manifest__.py | 7 + addons/web_tour/__manifest__.py | 9 + addons/website/__manifest__.py | 1 + addons/website/controllers/main.py | 1 - addons/website/models/ir_qweb.py | 5 +- addons/website/tests/test_performance.py | 4 +- addons/website/views/website_templates.xml | 1 - addons/website_event/__manifest__.py | 1 + addons/website_forum/__manifest__.py | 1 + .../views/snippets_templates.xml | 1 - addons/website_sale/__manifest__.py | 1 + 21 files changed, 200 insertions(+), 40 deletions(-) diff --git a/addons/auth_password_policy/__manifest__.py b/addons/auth_password_policy/__manifest__.py index 7c89ae7d8a7..84a21dc8da6 100644 --- a/addons/auth_password_policy/__manifest__.py +++ b/addons/auth_password_policy/__manifest__.py @@ -13,6 +13,10 @@ 'auth_password_policy/static/src/password_meter.js', 'auth_password_policy/static/src/password_field.js', ], + 'web.assets_frontend': [ + 'auth_password_policy/static/src/css/password_field.css', + 'auth_password_policy/static/src/password_policy.js', + ], 'web.assets_common': [ 'auth_password_policy/static/src/css/password_field.css', 'auth_password_policy/static/src/password_policy.js', diff --git a/addons/bus/__manifest__.py b/addons/bus/__manifest__.py index 3d37706aa30..31676236bb0 100644 --- a/addons/bus/__manifest__.py +++ b/addons/bus/__manifest__.py @@ -16,6 +16,12 @@ 'bus/static/src/workers/websocket_worker.js', 'bus/static/src/workers/websocket_worker_utils.js', ], + 'web.assets_frontend': [ + 'bus/static/src/*.js', + 'bus/static/src/services/**/*.js', + 'bus/static/src/workers/websocket_worker.js', + 'bus/static/src/workers/websocket_worker_utils.js', + ], 'web.qunit_suite_tests': [ 'bus/static/tests/**/*.js', ], diff --git a/addons/calendar/views/calendar_templates.xml b/addons/calendar/views/calendar_templates.xml index e37a4c34141..cbdd3bf2ac1 100644 --- a/addons/calendar/views/calendar_templates.xml +++ b/addons/calendar/views/calendar_templates.xml @@ -4,7 +4,6 @@ diff --git a/addons/stock/__manifest__.py b/addons/stock/__manifest__.py index ded5696e231..81e84e0848c 100644 --- a/addons/stock/__manifest__.py +++ b/addons/stock/__manifest__.py @@ -114,6 +114,9 @@ 'stock/static/src/scss/stock_empty_screen.scss', 'stock/static/src/views/**/*', ], + 'web.assets_frontend': [ + 'stock/static/src/scss/stock_traceability_report.scss', + ], 'web.assets_tests': [ 'stock/static/tests/tours/stock_report_tests.js', ], diff --git a/addons/survey/__manifest__.py b/addons/survey/__manifest__.py index 7eb18c4ffb4..8217de7110c 100644 --- a/addons/survey/__manifest__.py +++ b/addons/survey/__manifest__.py @@ -108,6 +108,9 @@ sent mails with personal token for the invitation of the survey. 'web.assets_common': [ 'survey/static/src/js/tours/survey_tour.js', ], + 'web.assets_frontend': [ + 'survey/static/src/js/tours/survey_tour.js', + ], }, 'license': 'LGPL-3', } diff --git a/addons/web/__manifest__.py b/addons/web/__manifest__.py index 83aaf3a0865..ec635927228 100644 --- a/addons/web/__manifest__.py +++ b/addons/web/__manifest__.py @@ -35,16 +35,17 @@ This module provides the core of the Odoo Web Client. # 2) the prefix "assets_" # 3) an arbitrary name, relevant to the content of the bundle. # - # Exemples: - # > web.assets_common = assets common to both frontend and backend clients. + # Examples: + # > web.assets_common = assets common to backend clients and others + # (not frontend). # > web_editor.assets_wysiwyg = assets needed by components defined in the "web_editor" module. - 'web.assets_common_minimal': [ - 'web/static/src/legacy/js/promise_extension.js', - 'web/static/src/boot.js', - 'web/static/src/session.js', - 'web/static/src/legacy/js/core/cookie_utils.js', - 'web/static/src/legacy/js/core/menu.js', - ], + + # Warning: Layouts using "assets_frontend" assets do not have the + # "assets_common" assets anymore. So, if it make sense, files added in + # "assets_common" should also be added in "assets_frontend". + # TODO in the future, probably remove "assets_common" definition + # entirely and let all "main" bundles evolve on their own, including the + # files they need in their bundle. 'web.assets_common': [ ('include', 'web._assets_helpers'), @@ -77,7 +78,11 @@ This module provides the core of the Odoo Web Client. 'web/static/src/legacy/scss/web.zoomodoo.scss', 'web/static/src/legacy/scss/fontawesome_overridden.scss', - ('include', 'web.assets_common_minimal'), + 'web/static/src/legacy/js/promise_extension.js', + 'web/static/src/boot.js', + 'web/static/src/session.js', + 'web/static/src/legacy/js/core/cookie_utils.js', + 'web/static/src/legacy/js/core/menu.js', 'web/static/lib/underscore/underscore.js', 'web/static/lib/underscore.string/lib/underscore.string.js', @@ -170,15 +175,6 @@ This module provides the core of the Odoo Web Client. 'web/static/src/legacy/js/widgets/translation_dialog.js', 'web/static/src/legacy/xml/translation_dialog.xml', ], - 'web.assets_common_lazy': [ - ('include', 'web.assets_common'), - # Remove assets_common_minimal - ('remove', 'web/static/src/legacy/js/promise_extension.js'), - ('remove', 'web/static/src/boot.js'), - ('remove', 'web/static/src/session.js'), - ('remove', 'web/static/src/legacy/js/core/cookie_utils.js'), - ('remove', 'web/static/src/legacy/js/core/menu.js'), - ], 'web.assets_backend': [ ('include', 'web._assets_helpers'), ('include', 'web._assets_backend_helpers'), @@ -310,9 +306,20 @@ This module provides the core of the Odoo Web Client. 'web/static/lib/bootstrap/scss/_variables.scss', ], 'web.assets_frontend_minimal': [ + 'web/static/src/legacy/js/promise_extension.js', + 'web/static/src/boot.js', + 'web/static/src/session.js', + 'web/static/src/legacy/js/core/cookie_utils.js', + 'web/static/src/legacy/js/core/menu.js', 'web/static/src/legacy/js/public/lazyloader.js', ], 'web.assets_frontend': [ + # TODO the 'assets_frontend' bundle now includes 'assets_common' + # files directly. That work was however a good opportunity to start + # removing the files that are not needed anymore in frontend layouts + # but it was not done: all common files were simply put in this + # bundle. We'll have to optimize that. + ('include', 'web._assets_helpers'), ('include', 'web._assets_frontend_helpers'), @@ -322,6 +329,128 @@ This module provides the core of the Odoo Web Client. ('include', 'web._assets_bootstrap'), + 'web/static/src/legacy/scss/tempusdominus_overridden.scss', + 'web/static/lib/tempusdominus/tempusdominus.scss', + 'web/static/lib/jquery.ui/jquery-ui.css', + 'web/static/src/libs/fontawesome/css/font-awesome.css', + 'web/static/lib/odoo_ui_icons/*', + 'web/static/lib/select2/select2.css', + 'web/static/lib/select2-bootstrap-css/select2-bootstrap.css', + 'web/static/lib/daterangepicker/daterangepicker.css', + 'web/static/fonts/fonts.scss', + 'web/static/src/webclient/navbar/navbar.scss', + 'web/static/src/legacy/scss/ui.scss', + 'web/static/src/legacy/scss/ui_extra.scss', + 'web/static/src/legacy/scss/mimetypes.scss', + 'web/static/src/legacy/scss/modal.scss', + 'web/static/src/legacy/scss/animation.scss', + 'web/static/src/legacy/scss/datepicker.scss', + 'web/static/src/legacy/scss/daterangepicker.scss', + 'web/static/src/legacy/scss/banner.scss', + 'web/static/src/legacy/scss/colorpicker.scss', + 'web/static/src/legacy/scss/popover.scss', + 'web/static/src/legacy/scss/translation_dialog.scss', + 'web/static/src/legacy/scss/keyboard.scss', + 'web/static/src/legacy/scss/name_and_signature.scss', + 'web/static/src/legacy/scss/web.zoomodoo.scss', + 'web/static/src/legacy/scss/fontawesome_overridden.scss', + + 'web/static/src/legacy/scss/base_frontend.scss', + 'web/static/src/legacy/scss/lazyloader.scss', + + ('include', 'web.assets_frontend_minimal'), + + 'web/static/lib/underscore/underscore.js', + 'web/static/lib/underscore.string/lib/underscore.string.js', + 'web/static/lib/moment/moment.js', + 'web/static/lib/owl/owl.js', + 'web/static/src/owl2_compatibility/*.js', + 'web/static/src/legacy/js/component_extension.js', + 'web/static/src/legacy/legacy_component.js', + 'web/static/lib/jquery/jquery.js', + 'web/static/lib/jquery.ui/jquery-ui.js', + 'web/static/lib/jquery/jquery.browser.js', + 'web/static/lib/jquery.blockUI/jquery.blockUI.js', + 'web/static/lib/jquery.hotkeys/jquery.hotkeys.js', + 'web/static/lib/jquery.placeholder/jquery.placeholder.js', + 'web/static/lib/jquery.form/jquery.form.js', + 'web/static/lib/jquery.ba-bbq/jquery.ba-bbq.js', + 'web/static/lib/jquery.mjs.nestedSortable/jquery.mjs.nestedSortable.js', + 'web/static/lib/popper/popper.js', + 'web/static/lib/bootstrap/js/dist/dom/data.js', + 'web/static/lib/bootstrap/js/dist/dom/event-handler.js', + 'web/static/lib/bootstrap/js/dist/dom/manipulator.js', + 'web/static/lib/bootstrap/js/dist/dom/selector-engine.js', + 'web/static/lib/bootstrap/js/dist/base-component.js', + 'web/static/lib/bootstrap/js/dist/alert.js', + 'web/static/lib/bootstrap/js/dist/button.js', + 'web/static/lib/bootstrap/js/dist/carousel.js', + 'web/static/lib/bootstrap/js/dist/collapse.js', + 'web/static/lib/bootstrap/js/dist/dropdown.js', + 'web/static/lib/bootstrap/js/dist/modal.js', + 'web/static/lib/bootstrap/js/dist/offcanvas.js', + 'web/static/lib/bootstrap/js/dist/tooltip.js', + 'web/static/lib/bootstrap/js/dist/popover.js', + 'web/static/lib/bootstrap/js/dist/scrollspy.js', + 'web/static/lib/bootstrap/js/dist/tab.js', + 'web/static/lib/bootstrap/js/dist/toast.js', + 'web/static/lib/tempusdominus/tempusdominus.js', + 'web/static/lib/select2/select2.js', + 'web/static/lib/clipboard/clipboard.js', + 'web/static/lib/jSignature/jSignatureCustom.js', + 'web/static/lib/qweb/qweb2.js', + 'web/static/src/legacy/js/assets.js', + 'web/static/src/legacy/js/libs/autocomplete.js', + 'web/static/src/legacy/js/libs/bootstrap.js', + 'web/static/src/legacy/js/libs/content-disposition.js', + 'web/static/src/legacy/js/libs/download.js', + 'web/static/src/legacy/js/libs/fullcalendar.js', + 'web/static/src/legacy/js/libs/jquery.js', + 'web/static/src/legacy/js/libs/moment.js', + 'web/static/src/legacy/js/libs/underscore.js', + 'web/static/src/legacy/js/libs/pdfjs.js', + 'web/static/src/legacy/js/libs/zoomodoo.js', + 'web/static/src/legacy/js/libs/jSignatureCustom.js', + 'web/static/src/legacy/js/core/abstract_service.js', + 'web/static/src/legacy/js/core/abstract_storage_service.js', + 'web/static/src/legacy/js/core/ajax.js', + 'web/static/src/legacy/js/core/browser_detection.js', + 'web/static/src/legacy/js/core/bus.js', + 'web/static/src/legacy/js/core/class.js', + 'web/static/src/legacy/js/core/collections.js', + 'web/static/src/legacy/js/core/concurrency.js', + 'web/static/src/legacy/js/core/dialog.js', + 'web/static/src/legacy/xml/dialog.xml', + 'web/static/src/legacy/js/core/owl_dialog.js', + 'web/static/src/legacy/js/core/popover.js', + 'web/static/src/legacy/js/core/dom.js', + 'web/static/src/legacy/js/core/local_storage.js', + 'web/static/src/legacy/js/core/mixins.js', + 'web/static/src/legacy/js/core/qweb.js', + 'web/static/src/legacy/js/core/ram_storage.js', + 'web/static/src/legacy/js/core/registry.js', + 'web/static/src/legacy/js/core/rpc.js', + 'web/static/src/legacy/js/core/service_mixins.js', + 'web/static/src/legacy/js/core/session.js', + 'web/static/src/legacy/js/core/session_storage.js', + 'web/static/src/legacy/js/core/time.js', + 'web/static/src/legacy/js/core/translation.js', + 'web/static/src/legacy/js/core/utils.js', + 'web/static/src/legacy/js/core/widget.js', + 'web/static/src/legacy/js/services/ajax_service.js', + 'web/static/src/legacy/js/services/config.js', + 'web/static/src/legacy/js/services/core.js', + 'web/static/src/legacy/js/services/local_storage_service.js', + 'web/static/src/legacy/js/services/session_storage_service.js', + 'web/static/src/legacy/js/common_env.js', + 'web/static/src/legacy/js/widgets/name_and_signature.js', + 'web/static/src/legacy/xml/name_and_signature.xml', + 'web/static/src/legacy/js/core/smooth_scroll_on_drag.js', + 'web/static/src/legacy/js/widgets/colorpicker.js', + 'web/static/src/legacy/xml/colorpicker.xml', + 'web/static/src/legacy/js/widgets/translation_dialog.js', + 'web/static/src/legacy/xml/translation_dialog.xml', + 'web/static/src/env.js', 'web/static/src/core/utils/transitions.scss', # included early because used by other files 'web/static/src/core/**/*', @@ -329,11 +458,6 @@ This module provides the core of the Odoo Web Client. ('remove', 'web/static/src/core/debug/debug_menu.js'), 'web/static/src/public/error_notifications.js', - 'web/static/src/legacy/scss/base_frontend.scss', - 'web/static/src/legacy/scss/lazyloader.scss', - - ('include', 'web.assets_frontend_minimal'), - 'web/static/src/legacy/utils.js', 'web/static/src/legacy/js/core/misc.js', 'web/static/src/legacy/js/owl_compatibility.js', @@ -351,7 +475,12 @@ This module provides the core of the Odoo Web Client. 'web.assets_frontend_lazy': [ ('include', 'web.assets_frontend'), # Remove assets_frontend_minimal - ('remove', 'web/static/src/legacy/js/public/lazyloader.js') + ('remove', 'web/static/src/legacy/js/promise_extension.js'), + ('remove', 'web/static/src/boot.js'), + ('remove', 'web/static/src/session.js'), + ('remove', 'web/static/src/legacy/js/core/cookie_utils.js'), + ('remove', 'web/static/src/legacy/js/core/menu.js'), + ('remove', 'web/static/src/legacy/js/public/lazyloader.js'), ], 'web.assets_backend_prod_only': [ 'web/static/src/main.js', @@ -406,7 +535,7 @@ This module provides the core of the Odoo Web Client. # with the addition of a prefixed underscore to reflect the "private" # aspect. # - # Exemples: + # Examples: # > web._assets_helpers = define assets needed in most main bundles 'web._assets_primary_variables': [ diff --git a/addons/web/views/webclient_templates.xml b/addons/web/views/webclient_templates.xml index bd03ca1061a..9a0d421adb0 100644 --- a/addons/web/views/webclient_templates.xml +++ b/addons/web/views/webclient_templates.xml @@ -33,7 +33,6 @@ - @@ -44,10 +43,8 @@ document.cookie = `tz=${userTZ}; path=/`; } - - diff --git a/addons/web_editor/__manifest__.py b/addons/web_editor/__manifest__.py index 4dc259b987e..f51375626be 100644 --- a/addons/web_editor/__manifest__.py +++ b/addons/web_editor/__manifest__.py @@ -120,6 +120,13 @@ Odoo Web Editor widget. 'web.assets_frontend': [ ('include', 'web_editor.assets_media_dialog'), + 'web_editor/static/src/js/editor/odoo-editor/src/base_style.scss', + 'web_editor/static/lib/vkbeautify/**/*', + 'web_editor/static/src/js/common/**/*', + 'web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js', + 'web_editor/static/src/js/wysiwyg/fonts.js', + 'web_editor/static/src/xml/ace.xml', + 'web_editor/static/src/scss/web_editor.common.scss', 'web_editor/static/src/scss/web_editor.frontend.scss', diff --git a/addons/web_tour/__manifest__.py b/addons/web_tour/__manifest__.py index 050c458501f..22960e142fe 100644 --- a/addons/web_tour/__manifest__.py +++ b/addons/web_tour/__manifest__.py @@ -34,6 +34,15 @@ Odoo Web tours. 'web_tour/static/src/debug/tour_dialog_component.xml', ], 'web.assets_frontend': [ + 'web_tour/static/src/scss/**/*', + 'web_tour/static/src/js/running_tour_action_helper.js', + 'web_tour/static/src/js/tip.js', + 'web_tour/static/src/js/tour_manager.js', + 'web_tour/static/src/js/tour_service.js', + 'web_tour/static/src/js/tour_step_utils.js', + 'web_tour/static/src/js/tour_utils.js', + '/web_tour/static/src/xml/tip.xml', + 'web_tour/static/src/js/public/**/*', ], 'web.qunit_suite_tests': [ diff --git a/addons/website/__manifest__.py b/addons/website/__manifest__.py index da59d30723c..4a836730ae5 100644 --- a/addons/website/__manifest__.py +++ b/addons/website/__manifest__.py @@ -119,6 +119,7 @@ 'website/static/src/scss/website.scss', 'website/static/src/scss/website.ui.scss', 'website/static/src/js/utils.js', + 'website/static/src/js/tours/tour_utils.js', 'website/static/src/js/content/website_root.js', 'website/static/src/js/widgets/dialog.js', 'website/static/src/js/content/compatibility.js', diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py index 8c6739c0779..4c180f154a5 100644 --- a/addons/website/controllers/main.py +++ b/addons/website/controllers/main.py @@ -738,7 +738,6 @@ class Website(Home): Reloads asset bundles and returns their unique URLs. """ return { - 'web.assets_common': request.env['ir.qweb']._get_asset_link_urls('web.assets_common', request.session.debug), 'web.assets_frontend': request.env['ir.qweb']._get_asset_link_urls('web.assets_frontend', request.session.debug), } diff --git a/addons/website/models/ir_qweb.py b/addons/website/models/ir_qweb.py index a109fb7f31f..a9c80dca20e 100644 --- a/addons/website/models/ir_qweb.py +++ b/addons/website/models/ir_qweb.py @@ -157,12 +157,9 @@ class IrQWeb(models.AbstractModel): def _pregenerate_assets_bundles(self): # website is adding a website_id to the extra part of the attachement url (/1) - # /web/assets/2223-ee56665/1/web.assets_common.min.css # /web/assets/2224-47bce88/1/web.assets_frontend.min.css - # /web/assets/2225-8b64a2b/1/web.assets_common_minimal.min.js # /web/assets/2226-17d3428/1/web.assets_frontend_minimal.min.js # /web/assets/2227-b9cd4ba/1/web.assets_tests.min.js - # /web/assets/2228-7424684/1/web.assets_common_lazy.min.js # /web/assets/2229-25b1d52/1/web.assets_frontend_lazy.min.js # this means that the previously generated attachment wont be used on the website @@ -179,7 +176,7 @@ class IrQWeb(models.AbstractModel): bundle_info = node[1] bundle_url = bundle_info.get('src', '') or bundle_info.get('href', '') if bundle_url.startswith('/web/assets/'): - # example: "/web/assets/2152-ee56665/web.assets_common.min.js" + # example: "/web/assets/2152-ee56665/web.assets_frontend_lazy.min.js" _, _, _, id_unique, name = bundle_url.split('/') attachment_id, unique = id_unique.split('-') url_pattern = f'/web/assets/%s-%s/{website.id}/{name}' diff --git a/addons/website/tests/test_performance.py b/addons/website/tests/test_performance.py index 199876fe6b1..3ef88348dd6 100644 --- a/addons/website/tests/test_performance.py +++ b/addons/website/tests/test_performance.py @@ -146,7 +146,7 @@ class TestWebsitePerformancePost(UtilPerf): @mute_logger('odoo.http') def test_50_perf_sql_web_assets(self): # assets route /web/assets/.. - self.env['ir.qweb']._generate_asset_nodes('web.assets_common', css=False, js=True) - assets_url = self.env['ir.attachment'].search([('url', '=like', '/web/assets/%/web.assets_common%.js')], limit=1).url + self.env['ir.qweb']._generate_asset_nodes('web.assets_frontend_lazy', css=False, js=True) + assets_url = self.env['ir.attachment'].search([('url', '=like', '/web/assets/%/web.assets_frontend_lazy%.js')], limit=1).url self.assertEqual(self._get_url_hot_query(assets_url), 4) self.assertEqual(self._get_url_hot_query(assets_url, cache=False), 4) diff --git a/addons/website/views/website_templates.xml b/addons/website/views/website_templates.xml index 5e884a2f397..66399a2b91b 100644 --- a/addons/website/views/website_templates.xml +++ b/addons/website/views/website_templates.xml @@ -2528,7 +2528,6 @@ Sitemap: sitemap.xml