How to set a specific lines order in a one2many fi

2019-09-17 02:54发布

Is it possible to order lines in a one2many field by a specific column without modifying the original class order?

Let's put an example: The model res.partner is ordered by the field name. So, if you open a res.partner view, the rows are going to be ordered by their name.

Now, I'm in a view of other model. This model has a one2many field pointing to res.partner, this means that I'm seeing a list of partners, and they're ordered by name too.

Can I always see this last list ordered by other column like for example email, but keeping the order by name in res.partner views?

1条回答
甜甜的少女心
2楼-- · 2019-09-17 03:14

Finally, I found a way to manage this, downloading this module:

https://www.odoo.com/apps/modules/7.0/one2many_sorted/

Then, I overrided the one2many whose order I want to alter, in my case the field was child_ids, and I wanted it to be ordered by email:

'child_ids' : one2many_sorted.one2many_sorted( 'res.partner', 'parent_id', 'Contacts', order='email', )

Note that the only different between this field and the one2many is the param order (you can use a couple new more though, search and set).

I also imported the library at the top of the file:

import one2many_sorted

Now, I'm seeing the tree and kanban of res.partner ordered by name, but this one2many is ordered by email. Great!

查看更多
登录 后发表回答