Odoo Help


6 Answers

Jose David Moreno Hernandez Spain

--Jose David Moreno Hernandez--

| 4 2 4
Málaga, Spain
--Jose David Moreno Hernandez--

Jose David Moreno Hernandez Spain
2/15/19, 10:24 AM

I've been for a long time looking for a solution for that, and I've ended creating my own. It's a little of a hack but works perfectly for colouring the field's backgrounds depending on other fields values.

First I add a new meaningful class name to my field, for example 'opt_required', and use in it the odoo's built-in colouring functionality, I'll chose 'decoration-warning'

<field name="custom_field" class="opt_required" decoration-warning="company_name == 'Elektrolux'"/>

After that, in my custom css file I add the next code. The decoration-warning will trigger the .text-warning class in the case the conditional is met, otherwise the input-field won't have that class. So the next piece of css code will only work if the input has either the .text-warning class and the opt_required class, and our field will have happily its background colour :)

   background-color: #D2D2FF !important;
   color: rgb(31, 31, 31) !important; /*We don't want the text to actually have the warning color, so we keep it the usual*/

Take care of adding your css file to the assets as usual, for instance like this:

<?xml version="1.0" encoding="utf-8" ?>
    <template id="assets_backend" name="Technical Service Assets" inherit_id="web.assets_backend">
        <xpath expr="//link[last()]" position="after">            
            <link rel="stylesheet" href="technical_service/static/src/css/styles.css"/>       

And after to the __manifest__.py

'data': [
'css': ['static/src/css/styles.css'],

Then you just need to upgrade your module, and your fields will start working as you desired.


Vishal Gediya India

--Vishal Gediya--

| 3 2 4
Surat, India
--Vishal Gediya--

Python and Odoo Developer

Vishal Gediya India
2/9/16, 7:45 AM

If you want all fields color then give colors attribute in <tree>

<tree string="Configuration" colors="green:no == 0;red:no > 0">
    <field name="no" />
Versão Integral, Anabela Damas Portugal
2/9/16, 11:02 AM

For tree the answer is rigth. But I need in a form just the field.

Vishal Gediya India
2/10/16, 12:57 AM

you need only for to_pay filed.

Ask a Question
Keep Informed
1 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now