From 06b5d25e9375063f6ccf360e5f3f34a289d5bd73 Mon Sep 17 00:00:00 2001 From: anusrinps96 Date: Thu, 26 Jun 2025 11:23:53 +0200 Subject: [PATCH 01/26] [REF] web_company_color: Update fetching scss_template Using a function to fetch SCSS_TEMPLATE --- web_company_color/models/res_company.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/web_company_color/models/res_company.py b/web_company_color/models/res_company.py index 0dc6d2147192..115343bb2e16 100644 --- a/web_company_color/models/res_company.py +++ b/web_company_color/models/res_company.py @@ -14,7 +14,8 @@ class ResCompany(models.Model): _inherit = "res.company" - SCSS_TEMPLATE = """ + def _get_scss_template(self): + return """ .o_main_navbar { background: %(color_navbar_bg)s !important; background-color: %(color_navbar_bg)s !important; @@ -228,7 +229,7 @@ def _scss_generate_content(self): # ir.attachment need files with content to work if not self.company_colors: return "// No Web Company Color SCSS Content\n" - return self.SCSS_TEMPLATE % self._scss_get_sanitized_values() + return self._get_scss_template() % self._scss_get_sanitized_values() def scss_get_url(self): self.ensure_one() From 2db6ff17422135c71df15d79361e6053533a3aec Mon Sep 17 00:00:00 2001 From: Simone Rubino Date: Mon, 2 Feb 2026 12:22:04 +0100 Subject: [PATCH 02/26] [IMP] web_company_color: Compile SCSS Otherwise function calls are not evaluated in the created attachment --- web_company_color/models/res_company.py | 8 ++++++- web_company_color/readme/CONTRIBUTORS.md | 2 ++ web_company_color/tests/test_res_company.py | 23 +++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/web_company_color/models/res_company.py b/web_company_color/models/res_company.py index 115343bb2e16..e152593df114 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/" @@ -238,8 +240,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 56447aa857e7..46792413d58e 100644 --- a/web_company_color/readme/CONTRIBUTORS.md +++ b/web_company_color/readme/CONTRIBUTORS.md @@ -10,3 +10,5 @@ - Carlos Roca - [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io) - Bhavesh Heliconia +- [PyTech](https://www.pytech.it): + - Simone Rubino \<\> 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) From a6108db70858730c7e0ec492cb6230fc98d3e735 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Tue, 17 Mar 2026 14:03:37 +0100 Subject: [PATCH 03/26] [REF] web_company_color: simplify write code --- web_company_color/models/res_company.py | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/web_company_color/models/res_company.py b/web_company_color/models/res_company.py index e152593df114..fc4eafec906a 100644 --- a/web_company_color/models/res_company.py +++ b/web_company_color/models/res_company.py @@ -162,22 +162,15 @@ def unlink(self): return super().unlink() def write(self, values): - if not self.env.context.get("ignore_company_color", False): - fields_to_check = ( - "color_navbar_bg", - "color_navbar_bg_hover", - "color_navbar_text", - "color_button_bg", - "color_button_bg_hover", - "color_button_text", - "color_link_text", - "color_link_text_hover", - ) - result = super().write(values) - if any([field in values for field in fields_to_check]): + result = super().write(values) + if not self.env.context.get("ignore_company_color"): + fields_to_check = ["company_colors"] + [ + field_name + for field_name, field in self._fields.items() + if field.sparse == "company_colors" + ] + if any(field in values for field in fields_to_check): self.scss_create_or_update_attachment() - else: - result = super().write(values) return result def button_compute_color(self): From 95936269fd78e7658ccff98bb4b950dc17c5ba37 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Tue, 17 Mar 2026 14:30:26 +0100 Subject: [PATCH 04/26] [IMP] web_company_color: allow to set bottom border color of navbar --- web_company_color/models/res_company.py | 11 ++++++++++- web_company_color/view/res_company.xml | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/web_company_color/models/res_company.py b/web_company_color/models/res_company.py index fc4eafec906a..9c382481d757 100644 --- a/web_company_color/models/res_company.py +++ b/web_company_color/models/res_company.py @@ -21,6 +21,7 @@ def _get_scss_template(self): .o_main_navbar { background: %(color_navbar_bg)s !important; background-color: %(color_navbar_bg)s !important; + border-bottom: 1px solid %(color_navbar_border_bottom)s !important; color: %(color_navbar_text)s !important; .show { @@ -109,6 +110,7 @@ def _get_scss_template(self): &:hover, &:focus, &:active, &:focus:active { background-color: %(color_navbar_bg_hover)s !important; } + border-bottom: 1px solid %(color_navbar_border_bottom)s !important; } .o_menu_sections .dropdown-toggle { background: %(color_navbar_bg)s !important; @@ -117,6 +119,7 @@ def _get_scss_template(self): &:hover, &:focus, &:active, &:focus:active { background-color: %(color_navbar_bg_hover)s !important; } + border-bottom: 1px solid %(color_navbar_border_bottom)s !important; } .o_menu_systray button{ color: %(color_navbar_text)s !important; @@ -134,6 +137,9 @@ def _get_scss_template(self): color_navbar_bg_hover = fields.Char( "Navbar Background Color Hover", sparse="company_colors" ) + color_navbar_border_bottom = fields.Char( + "Navbar Bottom Border Color", sparse="company_colors" + ) color_navbar_text = fields.Char("Navbar Text Color", sparse="company_colors") color_button_text = fields.Char("Button Text Color", sparse="company_colors") color_button_bg = fields.Char("Button Background Color", sparse="company_colors") @@ -191,10 +197,11 @@ def button_compute_color(self): { "color_navbar_bg": n_rgb_to_hex(_r, _g, _b), "color_navbar_bg_hover": n_rgb_to_hex(_rd, _gd, _bd), + "color_navbar_border_bottom": n_rgb_to_hex(_rd, _gd, _bd), "color_navbar_text": "#000" if _a < 0.5 else "#fff", } ) - self.write(values) + self.update(values) def _scss_get_sanitized_values(self): self.ensure_one() @@ -206,6 +213,8 @@ def _scss_get_sanitized_values(self): { "color_navbar_bg": (values.get("color_navbar_bg") or "$o-brand-odoo"), "color_navbar_bg_hover": (values.get("color_navbar_bg_hover")), + "color_navbar_border_bottom": values.get("color_navbar_border_bottom") + or f"darken({values.get('color_navbar_bg') or '$o-brand-odoo'}, 10%)", "color_navbar_text": (values.get("color_navbar_text") or "#FFF"), "color_button_bg": values.get("color_button_bg") or "#71639e", "color_button_bg_hover": values.get("color_button_bg_hover") diff --git a/web_company_color/view/res_company.xml b/web_company_color/view/res_company.xml index 45dd79421834..55969037919a 100644 --- a/web_company_color/view/res_company.xml +++ b/web_company_color/view/res_company.xml @@ -18,6 +18,7 @@ + From 0c7aed1544732e9c27fca478a654cf1f60ef4529 Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Tue, 17 Mar 2026 14:51:51 +0100 Subject: [PATCH 05/26] [IMP] web_company_color: test ignore_company_color context key --- web_company_color/tests/test_res_company.py | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/web_company_color/tests/test_res_company.py b/web_company_color/tests/test_res_company.py index 0121e9eeefe2..ea300cb38cb0 100644 --- a/web_company_color/tests/test_res_company.py +++ b/web_company_color/tests/test_res_company.py @@ -98,3 +98,26 @@ def test_compiled_scss(self): self.assertNotIn("desaturate", css) self.assertNotIn(color, css) self.assertIn(desaturated_color, css) + + def test_ignore_company_color(self): + """ + Test that we can turn off regenerating css attachment via context key + """ + company = self.env.company + attachment = self.env["ir.attachment"].search( + [("url", "=", company.scss_get_url())] + ) + attachment.unlink() + + company.company_colors = {} + attachment = self.env["ir.attachment"].search( + [("url", "=", company.scss_get_url())] + ) + self.assertTrue(attachment, "attachment should have been regenerated") + + attachment.unlink() + company.with_context(ignore_company_color=True).company_colors = {} + attachment = self.env["ir.attachment"].search( + [("url", "=", company.scss_get_url())] + ) + self.assertFalse(attachment, "attachment should not have been regenerated") From e029b5ea3d14a11f822b895475dfd7503976999c Mon Sep 17 00:00:00 2001 From: MarwanBHL Date: Sun, 31 May 2026 23:08:38 +0200 Subject: [PATCH 06/26] [FIX] web_company_color: load webp plugin to handle webp logos --- web_company_color/README.rst | 6 ++++++ web_company_color/readme/CONTRIBUTORS.md | 1 + web_company_color/static/description/index.html | 7 ++++++- web_company_color/utils.py | 5 ++++- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/web_company_color/README.rst b/web_company_color/README.rst index 57e444e24caa..885f47ab0cf1 100644 --- a/web_company_color/README.rst +++ b/web_company_color/README.rst @@ -90,6 +90,12 @@ Contributors - Bhavesh Heliconia +- `PyTech `__: + + - Simone Rubino + +- Marwan Behillil + Maintainers ----------- diff --git a/web_company_color/readme/CONTRIBUTORS.md b/web_company_color/readme/CONTRIBUTORS.md index 46792413d58e..4141ecccdf38 100644 --- a/web_company_color/readme/CONTRIBUTORS.md +++ b/web_company_color/readme/CONTRIBUTORS.md @@ -12,3 +12,4 @@ - Bhavesh Heliconia - [PyTech](https://www.pytech.it): - Simone Rubino \<\> +- Marwan Behillil \<> diff --git a/web_company_color/static/description/index.html b/web_company_color/static/description/index.html index 3b7361f161c1..bead4ac2861e 100644 --- a/web_company_color/static/description/index.html +++ b/web_company_color/static/description/index.html @@ -3,7 +3,7 @@ -Web Company Color +README.rst