Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion web_company_color/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"name": "Web Company Color",
"category": "web",
"version": "19.0.1.0.0",
"version": "19.0.1.1.0",
"author": "Alexandre Díaz, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/web",
"depends": ["web", "base_sparse_field"],
Expand Down
8 changes: 8 additions & 0 deletions web_company_color/migrations/19.0.1.1.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import SUPERUSER_ID, api


def migrate(cr, version):
env = api.Environment(cr, SUPERUSER_ID, {})
# Regenerate stylesheets with the Odoo 19 templates; saved colours are kept.
env["res.company"].search([]).scss_create_or_update_attachment()
14 changes: 2 additions & 12 deletions web_company_color/models/assetsbundle.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
# Copyright 2020 Alexandre Díaz <dev@redneboa.es>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.http import request

from odoo.addons.base.models.assetsbundle import AssetsBundle


class AssetsBundleCompanyColor(AssetsBundle):
def get_company_color_asset_node(self):
"""Process the user active company scss and returns the node to inject"""
try:
active_company_id = int(
request.httprequest.cookies.get("cids", "").split("-")[0]
)
except Exception:
active_company_id = False
company_id = (
self.env["res.company"].browse(active_company_id) or self.env.company
)
return company_id.scss_get_url()
company = self.env["res.company"]._get_company_color_active_company()
return company.scss_get_url()
65 changes: 14 additions & 51 deletions web_company_color/models/ir_qweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,6 @@
class QWeb(models.AbstractModel):
_inherit = "ir.qweb"

def _generate_asset_links_cache(
self, bundle, css=True, js=True, assets_params=None, rtl=False, autoprefix=False
):
res = super()._generate_asset_links_cache(
bundle,
css=css,
js=js,
assets_params=assets_params,
rtl=rtl,
autoprefix=autoprefix,
)
if bundle == "web_company_color.company_color_assets":
asset = AssetsBundleCompanyColor(
bundle, [], env=self.env, css=True, js=True
)
res += [asset.get_company_color_asset_node()]
return res

def _generate_asset_links(
self,
bundle,
css=True,
js=True,
debug_assets=False,
assets_params=None,
rtl=False,
autoprefix=False,
):
res = super()._generate_asset_links(
bundle,
css=css,
js=js,
debug_assets=debug_assets,
assets_params=assets_params,
rtl=rtl,
autoprefix=autoprefix,
)
if bundle == "web_company_color.company_color_assets":
asset = AssetsBundleCompanyColor(
bundle, [], env=self.env, css=True, js=True
)
res += [asset.get_company_color_asset_node()]
return res

def _get_asset_content(self, bundle, assets_params=None):
"""Handle 'special' web_company_color bundle"""
if bundle == "web_company_color.company_color_assets":
Expand All @@ -69,7 +25,20 @@ def _get_asset_nodes(
media=None,
autoprefix=False,
):
res = super()._get_asset_nodes(
if bundle == "web_company_color.company_color_assets":
if not css:
return []
# Company selection belongs to this request, never the shared
# asset cache. Mutating cached links leaked previous companies'
# styles into later pages, including companies with no overrides.
asset = AssetsBundleCompanyColor(
bundle, [], env=self.env, css=True, js=False
)
url = asset.get_company_color_asset_node()
node = self._link_to_node(url, media=media)
node[1].pop("type", None)
return [node]
return super()._get_asset_nodes(
bundle,
css=css,
js=js,
Expand All @@ -79,9 +48,3 @@ def _get_asset_nodes(
media=media,
autoprefix=autoprefix,
)
for tag, attributes in res:
if tag == "link" and attributes.get("href", "").startswith(
"/web_company_color/static/src/scss/custom_colors."
):
attributes.pop("type", None)
return res
Loading
Loading