Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
11776 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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),
           }
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 7 21
17513
1
thg 3 15
6276
6
thg 1 19
9354
3
thg 4 17
10370
1
thg 3 15
4856