This commit goal is to encapsulate every tour-test into a separate assets bundle that would be called only during tests (command line) or by URL (debug=tests). That way, a lot of .js files would not be loaded anymore uselessly outside test mode and will speed up the page loads (especially in the frontend as the backend do not reload the page anyway). In order to do that, we needed to propagate the `debug` state from page to page. Otherwise, every page change during a test would simply lose the debug mode and the test would stop as the test assets would not be loaded. As we could not add the `&debug=tests` on every link (either hardcoded or preprocess during the rendering), it has been decided to store it in session. Technical summary: 1. `debug` state (currently only stored in URL) will be stored in session. Either when adding the `debug` param in URL (handled with _dispatch) or by starting Odoo with `test-enable` or `test-file` (handled by session init). 2. Once activated (and so set in session), debug mode will remain activated even if not visible in URL (after a page navigation eg). To deactivate it, set its value to nothing, `debug=`. That will exit debug mode (whatever mode it is: debug, assets, tests). 3. As tour-test files are now in a separate bundle, every layout (when needed) should `t-call="web.conditional_assets_tests"`. As it would be redundant and verbose, no `t-if` is needed on the t-call to load it only in test debug mode. That will be handled by `compiled_assets_tests` that will actually do the conditionnal t-call-assets to web.assets_tests, if tests debug mode is activated. 4. In addition to separating the tour-tests files in a separate bundle, we also moved those files to a specific folder under /static/tests/tours next to QUnit tests. 5. Also, tour files will be moved in a specific folder /static/src/js/tours for cleanness purpose (those files will still be kept in their 'normal' assets as needed outside test mode since it is tours). This will be done in the next commit. 6. It is possible to enable multiple debug mode, such as 'tests' and 'assets' together. Simply separate debug modes with a comma, eg '?debug=assets,tests' task-1934445 Comes with https://github.com/odoo/enterprise/pull/4281 Closes #33213
80 lines
3.5 KiB
Python
80 lines
3.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
import hashlib
|
|
import json
|
|
|
|
from odoo import api, models
|
|
from odoo.http import request
|
|
from odoo.tools import ustr
|
|
|
|
from odoo.addons.web.controllers.main import concat_xml, manifest_glob, module_boot
|
|
|
|
import odoo
|
|
|
|
|
|
class Http(models.AbstractModel):
|
|
_inherit = 'ir.http'
|
|
|
|
def webclient_rendering_context(self):
|
|
return {
|
|
'menu_data': request.env['ir.ui.menu'].load_menus(request.session.debug),
|
|
'session_info': json.dumps(self.session_info()),
|
|
}
|
|
|
|
def session_info(self):
|
|
user = request.env.user
|
|
version_info = odoo.service.common.exp_version()
|
|
|
|
user_context = request.session.get_context() if request.session.uid else {}
|
|
|
|
mods = module_boot()
|
|
files = [f[0] for f in manifest_glob('qweb', addons=','.join(mods))]
|
|
_, qweb_checksum = concat_xml(files)
|
|
|
|
lang = user_context.get("lang")
|
|
translations_per_module, _ = request.env['ir.translation'].get_translations_for_webclient(mods, lang)
|
|
|
|
menu_json_utf8 = json.dumps(request.env['ir.ui.menu'].load_menus(request.session.debug), default=ustr, sort_keys=True).encode()
|
|
translations_json_utf8 = json.dumps(translations_per_module, sort_keys=True).encode()
|
|
|
|
return {
|
|
"uid": request.session.uid,
|
|
"is_system": user._is_system() if request.session.uid else False,
|
|
"is_admin": user._is_admin() if request.session.uid else False,
|
|
"user_context": request.session.get_context() if request.session.uid else {},
|
|
"db": request.session.db,
|
|
"server_version": version_info.get('server_version'),
|
|
"server_version_info": version_info.get('server_version_info'),
|
|
"name": user.name,
|
|
"username": user.login,
|
|
"partner_display_name": user.partner_id.display_name,
|
|
"company_id": user.company_id.id if request.session.uid else None, # YTI TODO: Remove this from the user context
|
|
"partner_id": user.partner_id.id if request.session.uid and user.partner_id else None,
|
|
# current_company should be default_company
|
|
"user_companies": {'current_company': (user.company_id.id, user.company_id.name), 'allowed_companies': [(comp.id, comp.name) for comp in user.company_ids]},
|
|
"currencies": self.get_currencies() if request.session.uid else {},
|
|
"web.base.url": self.env['ir.config_parameter'].sudo().get_param('web.base.url', default=''),
|
|
"show_effect": True,
|
|
"display_switch_company_menu": user.has_group('base.group_multi_company') and len(user.company_ids) > 1,
|
|
"cache_hashes": {
|
|
"load_menus": hashlib.sha1(menu_json_utf8).hexdigest(),
|
|
"qweb": qweb_checksum,
|
|
"translations": hashlib.sha1(translations_json_utf8).hexdigest(),
|
|
},
|
|
}
|
|
|
|
@api.model
|
|
def get_frontend_session_info(self):
|
|
return {
|
|
'is_admin': self.env.user._is_admin(),
|
|
'is_system': self.env.user._is_system(),
|
|
'is_website_user': self.env.user._is_public(),
|
|
'user_id': self.env.user.id,
|
|
'is_frontend': True,
|
|
}
|
|
|
|
def get_currencies(self):
|
|
Currency = request.env['res.currency']
|
|
currencies = Currency.search([]).read(['symbol', 'position', 'decimal_places'])
|
|
return {c['id']: {'symbol': c['symbol'], 'position': c['position'], 'digits': [69,c['decimal_places']]} for c in currencies}
|