[FIX] base, website: debug assets in multi-website/multi-company
Fine-tunning of 42eec88e5da164e4930c48113109f2c8d4b73da3 Before this commit, the assets were not found when the user is connected in mode debug assets in a multi-website and multi-company. This occurs because the attachments (assets) were created only for the first website accessed, and cannot be loaded when trying to access the second website. Now, the attachments are created for each website accessed and can be loaded withtout problems. closes odoo/odoo#42593 X-original-commit: 95077a8cdd9f2cd99c2ef85bdf7ca5d58e006b71 Signed-off-by: Jorge Pinna Puissant (jpp) <jpp@odoo.com>
This commit is contained in:
@@ -7,6 +7,7 @@ from odoo import models
|
||||
from odoo.http import request
|
||||
from odoo.addons.base.models.assetsbundle import AssetsBundle
|
||||
from odoo.addons.http_routing.models.ir_http import url_for
|
||||
from odoo.osv import expression
|
||||
from odoo.addons.website.models import ir_http
|
||||
from odoo.tools import html_escape as escape
|
||||
|
||||
@@ -21,6 +22,11 @@ class AssetsBundleMultiWebsite(AssetsBundle):
|
||||
res = super(AssetsBundleMultiWebsite, self)._get_asset_url_values(id, unique, extra, name, sep, type)
|
||||
return res
|
||||
|
||||
def _get_assets_domain_for_already_processed_css(self, assets):
|
||||
res = super(AssetsBundleMultiWebsite, self)._get_assets_domain_for_already_processed_css(assets)
|
||||
current_website = self.env['website'].get_current_website(fallback=False)
|
||||
res = expression.AND([res, current_website.website_domain()])
|
||||
return res
|
||||
|
||||
class QWeb(models.AbstractModel):
|
||||
""" QWeb object for rendering stuff in the website context """
|
||||
|
||||
@@ -370,6 +370,12 @@ class AssetsBundle(object):
|
||||
})("%s");
|
||||
""" % message.replace('"', '\\"').replace('\n', '
')
|
||||
|
||||
def _get_assets_domain_for_already_processed_css(self, assets):
|
||||
""" Method to compute the attachments' domain to search the already process assets (css).
|
||||
This method was created to be overridden.
|
||||
"""
|
||||
return [('url', 'in', list(assets.keys()))]
|
||||
|
||||
def is_css_preprocessed(self):
|
||||
preprocessed = True
|
||||
attachments = None
|
||||
@@ -381,7 +387,7 @@ class AssetsBundle(object):
|
||||
outdated = False
|
||||
assets = dict((asset.html_url, asset) for asset in self.stylesheets if isinstance(asset, atype))
|
||||
if assets:
|
||||
assets_domain = [('url', 'in', list(assets.keys()))]
|
||||
assets_domain = self._get_assets_domain_for_already_processed_css(assets)
|
||||
attachments = self.env['ir.attachment'].sudo().search(assets_domain)
|
||||
for attachment in attachments:
|
||||
asset = assets[attachment.url]
|
||||
@@ -441,7 +447,7 @@ class AssetsBundle(object):
|
||||
fname = os.path.basename(asset.url)
|
||||
url = asset.html_url
|
||||
with self.env.cr.savepoint():
|
||||
self.env['ir.attachment'].sudo().with_context(not_force_website_id=True).create(dict(
|
||||
self.env['ir.attachment'].sudo().create(dict(
|
||||
datas=base64.b64encode(asset.content.encode('utf8')),
|
||||
mimetype='text/css',
|
||||
type='binary',
|
||||
|
||||
Reference in New Issue
Block a user