This question has been flagged
2 Replies
5898 Views

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?

Avatar
Discard

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

Best Answer

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)]"/>

Avatar
Discard
Author Best Answer

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

Avatar
Discard

I have edited my previous answer.