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>
@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