forked from Techsystech/web
[MIG] web_company_color: Migration to 15.0
parent
add28d652b
commit
b4dfc4942a
|
@ -5,7 +5,7 @@
|
||||||
{
|
{
|
||||||
"name": "Web Company Color",
|
"name": "Web Company Color",
|
||||||
"category": "web",
|
"category": "web",
|
||||||
"version": "14.0.1.0.0",
|
"version": "15.0.1.0.0",
|
||||||
"author": "Alexandre Díaz, Odoo Community Association (OCA)",
|
"author": "Alexandre Díaz, Odoo Community Association (OCA)",
|
||||||
"website": "https://github.com/OCA/web",
|
"website": "https://github.com/OCA/web",
|
||||||
"depends": ["web", "base_sparse_field"],
|
"depends": ["web", "base_sparse_field"],
|
||||||
|
|
|
@ -1,14 +1,22 @@
|
||||||
# Copyright 2020 Alexandre Díaz <dev@redneboa.es>
|
# Copyright 2020 Alexandre Díaz <dev@redneboa.es>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# 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
|
from odoo.addons.base.models.assetsbundle import AssetsBundle, ScssStylesheetAsset
|
||||||
|
|
||||||
|
|
||||||
class AssetsBundleCompanyColor(AssetsBundle):
|
class AssetsBundleCompanyColor(AssetsBundle):
|
||||||
def get_company_color_asset_node(self):
|
def get_company_color_asset_node(self):
|
||||||
"""Process the user active company scss and returns the node to inject"""
|
"""Process the user active company scss and returns the node to inject"""
|
||||||
company_id = self.env["res.company"].browse(
|
try:
|
||||||
self.env.context.get("active_company_id", 0)
|
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())
|
asset = ScssStylesheetAsset(self, url=company_id.scss_get_url())
|
||||||
compiled = self.compile_css(asset.compile, asset.get_source())
|
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>
|
# Copyright 2020 Alexandre Díaz <dev@redneboa.es>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
from inspect import unwrap
|
from odoo import models
|
||||||
|
|
||||||
from odoo import api, models, tools
|
|
||||||
from odoo.http import request
|
|
||||||
|
|
||||||
from odoo.addons.base.models.ir_qweb import IrQWeb
|
|
||||||
|
|
||||||
from .assetsbundle import AssetsBundleCompanyColor
|
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"
|
||||||
|
|
||||||
|
def _generate_asset_nodes_cache(
|
||||||
@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(
|
|
||||||
self,
|
self,
|
||||||
xmlid,
|
bundle,
|
||||||
options,
|
|
||||||
css=True,
|
css=True,
|
||||||
js=True,
|
js=True,
|
||||||
debug=False,
|
debug=False,
|
||||||
async_load=False,
|
async_load=False,
|
||||||
defer_load=False,
|
defer_load=False,
|
||||||
lazy_load=False,
|
lazy_load=False,
|
||||||
values=None,
|
media=None,
|
||||||
):
|
):
|
||||||
return _orig_get_asset_nodes(
|
res = super()._generate_asset_nodes(
|
||||||
self,
|
bundle, css, js, debug, async_load, defer_load, lazy_load, media
|
||||||
xmlid,
|
|
||||||
options,
|
|
||||||
css=css,
|
|
||||||
js=js,
|
|
||||||
debug=debug,
|
|
||||||
async_load=async_load,
|
|
||||||
defer_load=defer_load,
|
|
||||||
lazy_load=lazy_load,
|
|
||||||
values=values,
|
|
||||||
)
|
)
|
||||||
|
if bundle == "web_company_color.company_color_assets":
|
||||||
|
asset = AssetsBundleCompanyColor(
|
||||||
IrQWeb._get_asset_nodes = _get_asset_nodes__mp
|
bundle, [], env=self.env, css=True, js=True
|
||||||
|
|
||||||
|
|
||||||
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]
|
|
||||||
)
|
)
|
||||||
except Exception:
|
res += [asset.get_company_color_asset_node()]
|
||||||
active_company_id = False
|
return res
|
||||||
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)
|
|
||||||
|
|
||||||
def _get_asset_content(self, xmlid, options):
|
def _get_asset_content(
|
||||||
"""Handle 'special' web_company_color xmlid"""
|
self, bundle, nodeAttrs=None, defer_load=False, lazy_load=False
|
||||||
if xmlid == "web_company_color.company_color_assets":
|
):
|
||||||
asset = AssetsBundleCompanyColor(xmlid, [], env=self.env)
|
"""Handle 'special' web_company_color bundle"""
|
||||||
return ([], [asset.get_company_color_asset_node()])
|
if bundle == "web_company_color.company_color_assets":
|
||||||
return super()._get_asset_content(xmlid, options)
|
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)
|
* 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>
|
* Simone Orsi <simone.orsi@camptocamp.com>
|
||||||
* Jairo Llopis <jairo.llopis@tecnativa.com>
|
* Jairo Llopis <jairo.llopis@tecnativa.com>
|
||||||
* Iván Antón <ozono@ozonomultimedia.com>
|
* Iván Antón <ozono@ozonomultimedia.com>
|
||||||
|
* Bernat Puig <bernat.puig@forgeflow.com> (ForgeFlow)
|
||||||
|
|
Loading…
Reference in New Issue