Skip to content

Instantly share code, notes, and snippets.

@ray-odoo
Last active April 24, 2025 19:16
Show Gist options
  • Save ray-odoo/17a1dc72c7f59314ed1592b1a3db7e0c to your computer and use it in GitHub Desktop.
Save ray-odoo/17a1dc72c7f59314ed1592b1a3db7e0c to your computer and use it in GitHub Desktop.
<!-- Note: the ID's of your Company records may not be 1 and 2, so adjust accordingly -->
<!-- Odoo 15 -->
<data inherit_id="web.layout">
<xpath expr="//body" position="inside">
<t t-if="request.httprequest.cookies.get('cids') and request.httprequest.cookies.get('cids')[0] == '1'">
<style>.o_main_navbar {background-color: #57596F!important;border-bottom: 0px;}</style></t>
<t t-if="request.httprequest.cookies.get('cids') and request.httprequest.cookies.get('cids')[0] == '2'">
<style>.o_main_navbar {background-color: #6B3C3C!important;border-bottom: 0px;}</style></t>
</xpath>
</data>
<!-- Odoo 16 -->
<data inherit_id="web.layout">
<xpath expr="//body" position="inside">
<t t-if="request.httprequest.cookies.get('cids') and request.httprequest.cookies.get('cids')[0] == '1'">
<style>.o_main_navbar {background: linear-gradient(45deg, #57596F, #57596F);
background-color: #57596F!important;border-bottom: 0px;}</style></t>
<t t-if="request.httprequest.cookies.get('cids') and request.httprequest.cookies.get('cids')[0] == '2'">
<style>.o_main_navbar {background: linear-gradient(45deg, #6B3C3C, #6B3C3C);
background-color: #6B3C3C!important;border-bottom: 0px;}</style></t>
</xpath>
</data>
<!-- Odoo 17 -->
<data inherit_id="web.layout">
<xpath expr="//body" position="inside">
<t t-if="request.httprequest.cookies.get('cids') and request.httprequest.cookies.get('cids')[0] == '1'">
<style>.o_main_navbar {background: linear-gradient(45deg, #57596F, #57596F);
background-color: #57596F!important;border-bottom: 0px;}</style></t>
<t t-if="request.httprequest.cookies.get('cids') and request.httprequest.cookies.get('cids')[0] == '2'">
<style>.o_main_navbar {background: linear-gradient(45deg, #6B3C3C, #6B3C3C);
background-color: #6B3C3C!important;border-bottom: 0px;}</style></t>
</xpath>
</data>
<!-- Odoo 18 -->
<data inherit_id="web.layout">
<xpath expr="//body" position="inside">
<t t-if="request.httprequest.cookies.get('cids') and request.httprequest.cookies.get('cids')[0] == '1'">
<style>.o_main_navbar {background: linear-gradient(45deg, #ffcccc, #ffcccc);
background-color: #ffcccc!important;
border-bottom: 0px;
}
.dropdown-toggle {background: linear-gradient(45deg, #ffcccc, #ffcccc);
background-color: #ffcccc!important;
border-bottom: 0px;
}
.o_nav_entry {background: linear-gradient(45deg, #ffcccc, #ffcccc);
background-color: #ffcccc!important;
border-bottom: 0px;
}</style></t>
<t t-if="request.httprequest.cookies.get('cids') and request.httprequest.cookies.get('cids')[0] == '2'">
<style>.o_main_navbar {background: linear-gradient(45deg, #ccccff, #ccccff);
background-color: #ccccff!important;border-bottom: 0px;}
.dropdown-toggle {background: linear-gradient(45deg, #ccccff, #ccccff);
background-color: #ccccff!important;border-bottom: 0px;}
.o_nav_entry {background: linear-gradient(45deg, #ccccff, #ccccff);
background-color: #ccccff!important;border-bottom: 0px;}
</style>
</t>
<t t-if="request.httprequest.cookies.get('cids') and request.httprequest.cookies.get('cids')[0] == '3'">
<style>.o_main_navbar {background: linear-gradient(45deg, #ccffcc, #ccffcc);
background-color: #ccffcc!important;border-bottom: 0px;}
.dropdown-toggle {background: linear-gradient(45deg, #ccffcc, #ccffcc);
background-color: #ccffcc!important;border-bottom: 0px;}
.o_nav_entry {background: linear-gradient(45deg, #ccffcc, #ccffcc);
background-color: #ccffcc!important;border-bottom: 0px;}</style></t>
</xpath>
</data>
@dynaz
Copy link

dynaz commented Sep 29, 2022

work good thak you

@alh-odoo
Copy link

Confirmed the v16 section still works for v16.3 SaaS

@Captivea-BEL
Copy link

Captivea-BEL commented Jul 13, 2023

This also worked for me in v16 albeit I used a different approach. Adding it below incase it might be of use to someone else. I made mine into a setting on the settings page with a color picker widget. Here is the template I made to pull from the settings.

<template id='my_navbar_web_layout' inherit_id='web.layout'> <data inherit_id="web.layout"> <xpath expr="//body" position="inside"> <t t-set="color" t-value='request.env["ir.config_parameter"].sudo().get_param("my_settings.nav_bar_color") if request else False' /> <t t-if='color'> <style>.o_main_navbar {background-color:<t t-esc='color'/>!important;border-bottom: 0px;}</style> </t> </xpath> </data> </template>

Edit... I cant get the code viewer to properly display but hopefully it would make sense if you paste it into an XML formatter

image

@ihzaputra
Copy link

This also worked for me in v16 albeit I used a different approach. Adding it below incase it might be of use to someone else. I made mine into a setting on the settings page with a color picker widget. Here is the template I made to pull from the settings.

<template id='my_navbar_web_layout' inherit_id='web.layout'> <data inherit_id="web.layout"> <xpath expr="//body" position="inside"> <t t-set="color" t-value='request.env["ir.config_parameter"].sudo().get_param("my_settings.nav_bar_color") if request else False' /> <t t-if='color'> <style>.o_main_navbar {background-color:<t t-esc='color'/>!important;border-bottom: 0px;}</style> </t> </xpath> </data> </template>

Edit... I cant get the code viewer to properly display but hopefully it would make sense if you paste it into an XML formatter

image

i dont see or have any changes in setting when i try this code

@Symbolics
Copy link

Does anyone have the incantation for version 18?

@ray-odoo
Copy link
Author

The same code works in Odoo 17.0 and 18.0, I just updated the GIST and the Forum post

@Symbolics
Copy link

This also worked for me in v16 albeit I used a different approach. Adding it below incase it might be of use to someone else. I made mine into a setting on the settings page with a color picker widget. Here is the template I made to pull from the settings.

<template id='my_navbar_web_layout' inherit_id='web.layout'> <data inherit_id="web.layout"> <xpath expr="//body" position="inside"> <t t-set="color" t-value='request.env["ir.config_parameter"].sudo().get_param("my_settings.nav_bar_color") if request else False' /> <t t-if='color'> <style>.o_main_navbar {background-color:<t t-esc='color'/>!important;border-bottom: 0px;}</style> </t> </xpath> </data> </template>

Edit... I cant get the code viewer to properly display but hopefully it would make sense if you paste it into an XML formatter

image

Nice! That really should be the default.

@Symbolics
Copy link

Symbolics commented Oct 24, 2024

The gist snippet for 18 mostly works, but the button backgrounds aren't updated:

image

@Captivea-BEL
Copy link

This also worked for me in v16 albeit I used a different approach. Adding it below incase it might be of use to someone else. I made mine into a setting on the settings page with a color picker widget. Here is the template I made to pull from the settings.
<template id='my_navbar_web_layout' inherit_id='web.layout'> <data inherit_id="web.layout"> <xpath expr="//body" position="inside"> <t t-set="color" t-value='request.env["ir.config_parameter"].sudo().get_param("my_settings.nav_bar_color") if request else False' /> <t t-if='color'> <style>.o_main_navbar {background-color:<t t-esc='color'/>!important;border-bottom: 0px;}</style> </t> </xpath> </data> </template>
Edit... I cant get the code viewer to properly display but hopefully it would make sense if you paste it into an XML formatter
image

Nice! That really should be the default.

It definitely is a little goofier with v17/18 with letting users pick whatever color they want. Sometimes it might clash with dark mode making it unusable

For better or worse this is how I am solving a similar situation for a different different customer... The view inherits into the web.layout template. nav_bar_color is just still a color picker widget in settings

image

@Symbolics
Copy link

The gist snippet for 18 mostly works, but the button backgrounds aren't updated:

image

Anyone have any ideas on how to get the rest of the theme to use a different colour?

@ray-odoo
Copy link
Author

I have updated this for Odoo 18.0, it is better (still not perfect):

image

image

image

@Captivea-BEL
Copy link

Captivea-BEL commented Apr 24, 2025

While doing a v18 upgrade this is what I am settling with for v18

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <template id='navbar_web_layout_comp_color' inherit_id='web.layout'>
        <data inherit_id="web.layout">
            <xpath expr="//body" position="inside">
                <t t-set="color" t-value='request.env["ir.config_parameter"].sudo().get_param("custom_icp.nav_bar_color") if request else False' />
                <t t-if='color'>
                    <t t-set="text_color">
                        <t t-set="r" t-value="int(color[1:3], 16)"/>
                        <t t-set="g" t-value="int(color[3:5], 16)"/>
                        <t t-set="b" t-value="int(color[5:7], 16)"/>
                        <t t-set="brightness" t-value="(r * 299 + g * 587 + b * 114) / 1000"/>
                        <t t-set="text_color_val" t-value="'white' if brightness &lt; 128 else 'black'"/>
                    </t>
                    <style>
                        .o_main_navbar {
                            background-color: <t t-esc="color"/> !important;
                            background: linear-gradient(45deg, <t t-esc="color"/>, <t t-esc="color"/>);
                            color: <t t-esc="text_color_val"/> !important;
                        }
                        .o_main_navbar *,
                        .o_main_navbar .breadcrumb-item,
                        .o_main_navbar .o_menu_toggle,
                        .o_main_navbar .o_user_menu,
                        .o_main_navbar a,
                        .o_main_navbar .o_MessagingMenu,
                        .o_main_navbar .o_debug_manager,
                        .o_main_navbar .o_menu_sections,
                        .o_main_navbar .o_menu_brand,
                        .o_main_navbar .o_switch_company_menu,                    
                        .o_main_navbar .dropdown-toggle {
                            color: <t t-esc="text_color_val"/> !important;
                        }
                        .o_main_navbar button,
                        .o_main_navbar .o_nav_entry,
                        .o_main_navbar .btn,
                        .o_main_navbar .btn-secondary,
                        .o_main_navbar .badge,
                        .o_main_navbar .dropdown-menu .dropdown-item {
                            color: <t t-esc="text_color_val"/> !important;
                            background-color: transparent !important;
                            border-color: rgba(255, 255, 255, 0.3);
                        }
                    </style>
                </t>
            </xpath>
        </data>
    </template>
</odoo>

Edit: Cant get screenshot to upload :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment