From 177d4827cd82d1a0f117273894e7aa210bbde23d Mon Sep 17 00:00:00 2001 From: Simone Rubino Date: Mon, 2 Feb 2026 12:22:04 +0100 Subject: [PATCH] [IMP] web_company_color: Compile SCSS Otherwise function calls are not evaluated in the created attachment --- web_company_color/README.rst | 10 +++--- web_company_color/models/res_company.py | 8 ++++- web_company_color/readme/CONTRIBUTORS.md | 2 ++ .../static/description/index.html | 32 +++++++++---------- web_company_color/tests/test_res_company.py | 23 +++++++++++++ 5 files changed, 52 insertions(+), 23 deletions(-) diff --git a/web_company_color/README.rst b/web_company_color/README.rst index 13215077c780..ef9971623eba 100644 --- a/web_company_color/README.rst +++ b/web_company_color/README.rst @@ -1,7 +1,3 @@ -.. image:: https://odoo-community.org/readme-banner-image - :target: https://odoo-community.org/get-involved?utm_source=readme - :alt: Odoo Community Association - ================= Web Company Color ================= @@ -17,7 +13,7 @@ Web Company Color .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png :target: https://odoo-community.org/page/development-status :alt: Beta -.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github @@ -86,6 +82,10 @@ Contributors - Alexandre Díaz - Carlos Roca +- `PyTech `__: + + - Simone Rubino + Maintainers ----------- diff --git a/web_company_color/models/res_company.py b/web_company_color/models/res_company.py index f4c296b0fba6..f82336bdd028 100644 --- a/web_company_color/models/res_company.py +++ b/web_company_color/models/res_company.py @@ -5,6 +5,8 @@ from odoo import api, fields, models +from odoo.addons.base.models.assetsbundle import ScssStylesheetAsset + from ..utils import convert_to_image, image_to_rgb, n_rgb_to_hex URL_BASE = "/web_company_color/static/src/scss/" @@ -240,8 +242,12 @@ def scss_get_url(self): def scss_create_or_update_attachment(self): IrAttachmentObj = self.env["ir.attachment"] for record in self: - datas = base64.b64encode(record._scss_generate_content().encode("utf-8")) custom_url = record.scss_get_url() + SCSS_asset = ScssStylesheetAsset( + "web_company_color.company_color_assets", url=custom_url + ) + compiled_CSS = SCSS_asset.compile(record._scss_generate_content()) + datas = base64.b64encode(compiled_CSS.encode("utf-8")) custom_attachment = IrAttachmentObj.sudo().search( [("url", "=", custom_url), ("company_id", "=", record.id)] ) diff --git a/web_company_color/readme/CONTRIBUTORS.md b/web_company_color/readme/CONTRIBUTORS.md index c66d22568de5..e074b858bf02 100644 --- a/web_company_color/readme/CONTRIBUTORS.md +++ b/web_company_color/readme/CONTRIBUTORS.md @@ -8,3 +8,5 @@ - Jairo Llopis - Alexandre Díaz - Carlos Roca +- [PyTech](https://www.pytech.it): + - Simone Rubino \<\> diff --git a/web_company_color/static/description/index.html b/web_company_color/static/description/index.html index 8545f0ec29b1..d580b48c5338 100644 --- a/web_company_color/static/description/index.html +++ b/web_company_color/static/description/index.html @@ -3,7 +3,7 @@ -README.rst +Web Company Color -
+
+

Web Company Color

- - -Odoo Community Association - -
-

Web Company Color

-

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runboat

+

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runboat

This module change navbar colors based in the company logo colors.

Table of contents

@@ -391,18 +386,18 @@

Web Company Color

-

Usage

+

Usage

Go to company record and set a logo. Can see/modify applied colors on the “Navbar” section.

For optimal results use images with alpha channel.

-

Known issues / Roadmap

+

Known issues / Roadmap

White color is omitted in the addition operation to support images without alpha channel.

-

Bug Tracker

+

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed @@ -410,15 +405,15 @@

Bug Tracker

Do not contact contributors directly about support or help with technical issues.

-

Credits

+

Credits

-

Authors

+

Authors

  • Alexandre Díaz
-

Contributors

+

Contributors

+
  • PyTech: +
  • -

    Maintainers

    +

    Maintainers

    This module is maintained by the OCA.

    Odoo Community Association @@ -448,6 +447,5 @@

    Maintainers

    -
    diff --git a/web_company_color/tests/test_res_company.py b/web_company_color/tests/test_res_company.py index 1c2fb665e975..0121e9eeefe2 100644 --- a/web_company_color/tests/test_res_company.py +++ b/web_company_color/tests/test_res_company.py @@ -1,5 +1,8 @@ # Copyright 2019 Alexandre Díaz # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +import base64 + from odoo.tests import common from ..models.res_company import URL_BASE @@ -75,3 +78,23 @@ def test_change_color(self): company_id.company_colors, "Invalid Navbar Background Color", ) + + def test_compiled_scss(self): + """The SCSS is compiled before being sent to the client.""" + # Arrange + company = self.env.company + color = "#d2e1dd" + desaturated_color = "#dadada" + company.color_navbar_bg = "desaturate(#d2e1dd, 30%)" + + # Act + company.scss_create_or_update_attachment() + + # Assert + attachment = self.env["ir.attachment"].search( + [("url", "=", company.scss_get_url())] + ) + css = base64.b64decode(attachment.datas).decode() + self.assertNotIn("desaturate", css) + self.assertNotIn(color, css) + self.assertIn(desaturated_color, css)