Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
11781 Переглядів

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

Аватар
Відмінити
Автор Найкраща відповідь

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 ' '.

Аватар
Відмінити
Найкраща відповідь

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),
           }
Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
2
лип. 21
17519
1
бер. 15
6279
6
січ. 19
9357
3
квіт. 17
10375
1
бер. 15
4861