anand raj
anand raj

Reputation: 227

How to give color for particular field (only some column) depending on some condition in Odoo 11 in an one2many tree?

I would like give color for particular field value in one2many form view. This is my sample code.

 <field name="custom_order_line" mode="tree,kanban" attrs="{'readonly': [('state', '=', 'validate')]}">
    <tree colors="red:customs_sale_price &lt; price_unit;green:customs_sale_price &gt; price_unit;" string="Customs Order Lines" editable="bottom">
        <field name="customs_sale_price" colors="green:state == 'draft' "/>
        <field name="customs_cost_price" colors="red:customs_cost_price &lt; customs_sale_price"/>
    </tree>
</field>

Upvotes: 0

Views: 4569

Answers (1)

ChesuCR
ChesuCR

Reputation: 9620

I found a module (web_tree_dynamic_colored_field) that does what you need. Check the link

Example changing the bg_color color:

<field name="arch" type="xml">
    <tree string="View name">
        ...
        <field name="name" options='{"bg_color": "red: customer == True"}'/>
        ...
    </tree>
</field>

Example changing the fg_color color:

<field name="arch" type="xml">
    <tree string="View name">
        ...
        <field name="name" options='{"fg_color": "white:customer == True"}'/>
        ...
    </tree>
</field>

Note: that you should always use single quotes for fields options and wrap nested values in double quotes since options is a JSON object.

Decorators

If you just want to color rows you can use decorators (only for the 11 version)

decoration-bf - shows the line in BOLD 
decoration-it - shows the line in ITALICS 
decoration-danger - shows the line in LIGHT RED 
decoration-info - shows the line in LIGHT BLUE 
decoration-muted - shows the line in LIGHT GRAY 
decoration-primary - shows the line in LIGHT PURPLE 
decoration-success - shows the line in LIGHT GREEN 
decoration-warning - shows the line in LIGHT BROWN

Syntax

<tree decoration-type="field=='value'">

Example

<tree decoration-success="state=='done'">

Upvotes: 1

Related Questions