Search code examples
odooodoo-13

Custom font-color Field Odoo


The model has attribute status

status = fields.Selection([
    ('Progreso', 'En progreso'),
    ('Completa', 'Completa'),
    ('Anulada', 'Anulada'),
    ('En espera', 'En espera')
], 'Estado')

The view

<div class="card-text">
     <field name="status" />
 </div>

I would like each status have a particular font-color:

Progreso: Blue

Completo:Green

Thanks


Solution

  • You can try this but you are limited to list of color.

    <field name = 'status' widget="selection" decoration-danger="status=='Progreso'" decoration-info="status=='Completa'" decoration-muted="status=='Anulada'" decoration-success="status=='En espera'"/>
    

    decoration-bf - BOLD

    decoration-it - ITALICS

    decoration-danger - LIGHT RED

    decoration-info - LIGHT BLUE

    decoration-muted - LIGHT GRAY

    decoration-primary - LIGHT PURPLE

    decoration-success - LIGHT GREEN

    decoration-warning - LIGHT BROWN

    You can try this too...

    <field name = 'status' widget="selection" t-att-style="'color: #f00;' if status == 'Progreso' else ('color: #00f;' if status == 
         'Completa' else 'color: #696969;')" />