Skip to content
Merged
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
34 changes: 18 additions & 16 deletions web_company_color/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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,
.o_navbar_breadcrumbs,
Expand All @@ -137,6 +140,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")
Expand Down Expand Up @@ -165,22 +171,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):
Expand All @@ -201,10 +200,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()
Expand All @@ -216,6 +216,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")
Expand Down
23 changes: 23 additions & 0 deletions web_company_color/tests/test_res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
1 change: 1 addition & 0 deletions web_company_color/view/res_company.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<group string="Colors" name="navbar_colors">
<field name="color_navbar_bg" widget="color" />
<field name="color_navbar_bg_hover" widget="color" />
<field name="color_navbar_border_bottom" widget="color" />
<field name="color_navbar_text" widget="color" />
<field name="color_button_bg" widget="color" />
<field name="color_button_bg_hover" widget="color" />
Expand Down
Loading