Odoo Help


Reorder one2many_list ?

on 8/15/14, 8:15 AM 1,550 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}"/>

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?

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

Serpent Consulting Services Pvt. Ltd., Serpent Consulting Services Pvt. Ltd.
on 8/15/14, 8:38 AM

Ludo - 21South

--Ludo - 21South--
| 2 2 5
Zwijndrecht, Netherlands
--Ludo - 21South--


Ludo - 21South
On 8/15/14, 8:52 AM

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. 


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

On 8/15/14, 9:14 AM

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

I have edited my previous answer.

21south, Ludo - 21South
on 8/15/14, 9:46 AM

About This Community

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


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 8/15/14, 8:15 AM
Seen: 1550 times
Last updated: 3/16/15, 8:10 AM