Use the colors attribute on the tree element to colorize records based on some conditions. 

Example, to colorize session list depending on it’s state:


                <tree string=”session List”

                                colors=”blue:state==’draft’; green:state==’confirmed’ “>

                     <field name=”name”/>

                     <field name=”start_date”/>

                     <field name=”end_date”/>

                     <field name=”duration”/>

                     <field name=”seats”/>

                     <field name=”instructor_id”/>

                     <field name=”course_id”/>

                     <field name=”attendee_count”/>

                     <field name=”state” />

                     <field name=”taken_seats” widget=”progressbar”/>



Don’t forget to include the conditional field also in the field list, otherwise it will not work.

Some conditional expresions that can be used on the colors attribute:

If state in either ‘confirmed’, ‘done’, ‘waiting’ :

  • colors=”blue: state in (‘confirmed’, ‘done’, ‘waiting’)”

if state is equal to ‘draft’:

  • colors=”blue: state==’draft’ “

if duration is greater than 5:          

  • colors=”blue: duration &gt; 5 “

if duration is less than 15:  

  • colors=”blue: duration &lt; 15 “

multiple conditions:

  • colors=”blue: state in (‘confirmed’, ‘done’, ‘waiting’) ; red: state==’draft’”



There is also fonts attribute to set the font of the records, for example to set bold fonts on records with message_unread is True:

  • fonts=”bold:message_unread==True”


Colorize and Fonts in Tree View Record in OpenERP
Tagged on: