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

Hi all,

I'm using the new V8 version of ODOO. I've added product_attributes via attribute_line_ids of my product.template.
In my template i've added a one2many_list field with attribute_line_ids:

<field name="attribute_line_ids" widget="one2many_list">
                            <tree string="Variants" editable="bottom">
                                <field name="attribute_id" />
                                <field name="value_ids" widget="many2many_tags" domain="[('attribute_id', '=', attribute_id)]" context="{'default_attribute_id': attribute_id}"/>
                            </tree>
                        </field>

Now, I would like to filter and reorder these values:

  • Attribute1: Value 1
  • Attribute3: Value 3
  • Attribute2: Value 2

Let's say I would like to hide Attribute2 and put Attribute1 underneath Attribute3:

  • Attribute3: Value 3
  • Attribute1: Value 1

Is there a way to control this list? Or is it always alphabetic?

Ảnh đại diện
Huỷ bỏ

Rick, You have to handle the _order of that one2many model.

Câu trả lời hay nhất

The underlying object controls the way of sorting. Like Serpet Consulting said, using the "_order" parameter on that object you can define a field on which to sort. You can also define if that should be descending or ascending.

For example, the field value_ids would point to record of the object my.values, then your code should look like so:

class myvalue(osv.osv):

    _name = "my.values"

    _order = "myfield asc"

Note by the way that his does not fix/add any kind of tree view. It is just the same records list without indentation but only sorted on a different field. 

[EDIT]

About hiding items in a list: Hiding in a list is done using a domain. For example, suppose you want all the elements of my.value where the field "myinteger" is higher than 4. You would create a construction like:

"my_value_ids" : fields.one2many("my.value", string="My values", domain="[("myinteger",">",4)]"),

you can also define a domain on the XML view of the other object referencing to my.value, like so:

<field name="my_value_ids"  domain="[('myinteger','>',4)]"/>

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

Thank you Ludo and Serpent for the answers, but what about hiding Attribute2 in the list?

Ảnh đại diện
Huỷ bỏ

I have edited my previous answer.

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 2 20
17784
1
thg 4 17
19754
2
thg 12 15
3955
3
thg 7 25
9176
1
thg 5 25
1413