Odoo 8: Many2many domain filter

巧了我就是萌 提交于 2019-11-30 08:26:21
Ludwik Trammer

Try this:

<field
    name="organization_type_id"
    domain="[('id', 'in', parent_id.organization_type_id.allowed_children_ids.ids)]"
    />

While allowed_children_ids is a set of records, allowed_children_ids.ids is a list of ids of those records.

You can also approach this from the other side. This should work and be event faster:

<field
    name="organization_type_id"
    domain="[('allowed_parent_type_ids', '=', parent_id.organization_type_id)]"
    />

EDIT: This trick doesn't work anymore in 9.0 and 10.0 even at the time I posted the message if your Odoo codebase was up to date see https://github.com/odoo/odoo/issues/16072 for more details.

For an alternative you can give a try to web_domain_field module. It is currently here: https://github.com/OCA/web/pull/567


Former answer:

To have a domain on a Many2many you will find a good answer from Olivier Dony on the Odoo FAQ: https://www.odoo.com/fr_FR/forum/aide-1/question/complex-many2many-domains-in-views-41777#answer_41784

In short, you need to adress the correct values as the Many2many value is a list of tuple like [(6, 0, ids)].

Thus you need to create a domain like this to compare ids:

domain=[('id', 'in', allowed_type_ids[0][2])]

Warning, this might not work on Odoo 9.0 in the case your many2many field is empty.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!