forked from Techsystech/web
[MIG] web_company_color: Migration to 15.0
parent
d8b68e0f1f
commit
860150e938
|
@ -5,7 +5,7 @@
|
|||
{
|
||||
"name": "Web Company Color",
|
||||
"category": "web",
|
||||
"version": "14.0.1.0.0",
|
||||
"version": "15.0.1.0.0",
|
||||
"author": "Alexandre Díaz, Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/web",
|
||||
"depends": ["web", "base_sparse_field"],
|
||||
|
|
|
@ -1,14 +1,22 @@
|
|||
# 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, ScssStylesheetAsset
|
||||
|
||||
|
||||
class AssetsBundleCompanyColor(AssetsBundle):
|
||||
def get_company_color_asset_node(self):
|
||||
"""Process the user active company scss and returns the node to inject"""
|
||||
company_id = self.env["res.company"].browse(
|
||||
self.env.context.get("active_company_id", 0)
|
||||
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
|
||||
)
|
||||
asset = ScssStylesheetAsset(self, url=company_id.scss_get_url())
|
||||
compiled = self.compile_css(asset.compile, asset.get_source())
|
||||
return ("style", {}, compiled)
|
||||
return "style", {}, compiled
|
||||
|
|
|
@ -1,86 +1,40 @@
|
|||
# Copyright 2020 Alexandre Díaz <dev@redneboa.es>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from inspect import unwrap
|
||||
|
||||
from odoo import api, models, tools
|
||||
from odoo.http import request
|
||||
|
||||
from odoo.addons.base.models.ir_qweb import IrQWeb
|
||||
from odoo import models
|
||||
|
||||
from .assetsbundle import AssetsBundleCompanyColor
|
||||
|
||||
# Monkey Patch to change the ormcache_context decorator of '_get_asset_nodes' to
|
||||
# add 'active_company_id' context key. This is done to avoid "clear_caches" usage
|
||||
# that works in a more aggressive way to the LRU cache.
|
||||
|
||||
_orig_get_asset_nodes = unwrap(IrQWeb._get_asset_nodes)
|
||||
class QWeb(models.AbstractModel):
|
||||
_inherit = "ir.qweb"
|
||||
|
||||
|
||||
@tools.conditional(
|
||||
"xml" not in tools.config["dev_mode"],
|
||||
tools.ormcache_context(
|
||||
"xmlid",
|
||||
'options.get("lang", "en_US")',
|
||||
"css",
|
||||
"js",
|
||||
"debug",
|
||||
"async_load",
|
||||
"defer_load",
|
||||
"lazy_load",
|
||||
keys=("website_id", "active_company_id"),
|
||||
),
|
||||
)
|
||||
def _get_asset_nodes__mp(
|
||||
def _generate_asset_nodes_cache(
|
||||
self,
|
||||
xmlid,
|
||||
options,
|
||||
bundle,
|
||||
css=True,
|
||||
js=True,
|
||||
debug=False,
|
||||
async_load=False,
|
||||
defer_load=False,
|
||||
lazy_load=False,
|
||||
values=None,
|
||||
media=None,
|
||||
):
|
||||
return _orig_get_asset_nodes(
|
||||
self,
|
||||
xmlid,
|
||||
options,
|
||||
css=css,
|
||||
js=js,
|
||||
debug=debug,
|
||||
async_load=async_load,
|
||||
defer_load=defer_load,
|
||||
lazy_load=lazy_load,
|
||||
values=values,
|
||||
res = super()._generate_asset_nodes(
|
||||
bundle, css, js, debug, async_load, defer_load, lazy_load, media
|
||||
)
|
||||
|
||||
|
||||
IrQWeb._get_asset_nodes = _get_asset_nodes__mp
|
||||
|
||||
|
||||
class QWeb(models.AbstractModel):
|
||||
_inherit = "ir.qweb"
|
||||
|
||||
@api.model
|
||||
def _render(self, id_or_xml_id, values=None, **options):
|
||||
"""Adds the active company to the context"""
|
||||
try:
|
||||
active_company_id = int(
|
||||
request.httprequest.cookies.get("cids", "").split(",")[0]
|
||||
if bundle == "web_company_color.company_color_assets":
|
||||
asset = AssetsBundleCompanyColor(
|
||||
bundle, [], env=self.env, css=True, js=True
|
||||
)
|
||||
except Exception:
|
||||
active_company_id = False
|
||||
company_id = (
|
||||
self.env["res.company"].browse(active_company_id)
|
||||
or self.env.user.company_id
|
||||
)
|
||||
self = self.with_context(active_company_id=company_id.id)
|
||||
return super()._render(id_or_xml_id, values=values, **options)
|
||||
res += [asset.get_company_color_asset_node()]
|
||||
return res
|
||||
|
||||
def _get_asset_content(self, xmlid, options):
|
||||
"""Handle 'special' web_company_color xmlid"""
|
||||
if xmlid == "web_company_color.company_color_assets":
|
||||
asset = AssetsBundleCompanyColor(xmlid, [], env=self.env)
|
||||
return ([], [asset.get_company_color_asset_node()])
|
||||
return super()._get_asset_content(xmlid, options)
|
||||
def _get_asset_content(
|
||||
self, bundle, nodeAttrs=None, defer_load=False, lazy_load=False
|
||||
):
|
||||
"""Handle 'special' web_company_color bundle"""
|
||||
if bundle == "web_company_color.company_color_assets":
|
||||
return [], []
|
||||
return super()._get_asset_content(
|
||||
bundle, nodeAttrs, defer_load=defer_load, lazy_load=lazy_load
|
||||
)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
* Jordi Ballester Alomar <jordi.ballester@forgeflow.com> (ForgeFlow)
|
||||
* Lois Rilo <lois.rilo@forgefloww.com> (ForgeFlow)
|
||||
* Lois Rilo <lois.rilo@forgeflow.com> (ForgeFlow)
|
||||
* Simone Orsi <simone.orsi@camptocamp.com>
|
||||
* Jairo Llopis <jairo.llopis@tecnativa.com>
|
||||
* Iván Antón <ozono@ozonomultimedia.com>
|
||||
* Bernat Puig <bernat.puig@forgeflow.com> (ForgeFlow)
|
||||
|
|
Loading…
Reference in New Issue