Odoo Help

Welcome!

This community 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.

2

change tree color with field function

By
Sebastian Schadock
on 5/17/13, 5:04 AM 3,999 views

Hello,

I want to change the tree list item colors with my own field functions.

purchase_view.xml:

    <record model="ir.ui.view" id="view_purchase_color_open_orders">
    <field name="name">purchase_order_tree_color_open_orders</field>
    <field name="model">purchase.order</field>
    <field name="inherit_id" ref="purchase.purchase_order_tree"/>
    <field name="arch" type="xml">            
        <xpath expr="//tree[@string='Purchase Order']" position="inside">
            <field name="is_green" invisible="1"/>
            <field name="is_orange" invisible="1"/>
            <field name="is_red" invisible="1"/>
        </xpath>
        <xpath expr="//tree[@string='Purchase Order']" position="attributes">
            <attribute name="colors">                    
                green:is_green=='True';
                orange:is_orange=='True';
                red:is_red=='True'
            </attribute>
        </xpath>
    </field>
</record>

is_green, is_orange and is_red are my functions and this is the definition:

    _columns = {
             'is_green': fields.function(_is_green, type = 'boolean'),
             'is_orange': fields.function(_is_orange, type = 'boolean'),
             'is_red': fields.function(_is_red, type = 'boolean'),
               }

The functions works without any problem, but the view color all items green (always the first color).

I also tryed:

            <attribute name="colors">                    
                green:('is_green', '=', 'True');
                orange:('is_orange', '=', 'True');
                red:('is_red', '=', 'True')
            </attribute>

with the same result.

Is this the right way, or is there another opportunity to solve the problem?

Regards,

Sebastian

3
Sebastian Schadock
On 5/17/13, 6:54 AM

I find the solution:

        <xpath expr="//tree[@string='Purchase Order']" position="attributes">
            <attribute name="colors">
                green:is_green==True;
                orange:is_orange==True;
                red:is_red==True
            </attribute>
        </xpath>

U have to compare boolean values without ' '.

1

Francesco OpenCode

--Francesco OpenCode--
3608
| 5 7 9
Grottaglie, Italy
--Francesco OpenCode--

Italian Odoo (OpenERP) Modules Developer LINKEDIN: http://www.linkedin.com/in/francescoapruzzese

Francesco OpenCode
On 5/17/13, 6:56 AM

Try to set the function storable.

_columns = {
         'is_green': fields.function(_is_green, type = 'boolean', store=True),
         'is_orange': fields.function(_is_orange, type = 'boolean', store=True),
         'is_red': fields.function(_is_red, type = 'boolean', store=True),
           }

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 5/17/13, 5:04 AM
Seen: 3999 times
Last updated: 3/16/15, 8:10 AM