Odoo Help

Welcome!

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

0

Reorder one2many_list ?

By
Rick
on 8/15/14, 8:15 AM 902 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?

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

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

Ludo - Neobis

--Ludo - Neobis--
2387
| 2 2 5
Hoogvliet, Netherlands
--Ludo - Neobis--

Developer

Ludo - Neobis
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. 

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

0
Rick
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.

Ludo - Neobis
on 8/15/14, 9:46 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

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