Momo Momoretto
Momo Momoretto

Reputation: 89

Odoo Prefilter many2one / many2many / one2many

How can I predefinde/prefilter a many2one field?

As example product.category has a type, in my view the user should only be able to select a product.category based on the category type.

//field in model category_id = fields.Many2one(comodel_name="product.category", string="ebay Category", required=True)

//field in view

How can I prefilter the select in view to offer only categories with type 'external'???

Upvotes: 1

Views: 1165

Answers (1)

Daniel Reis
Daniel Reis

Reputation: 13342

That's what domain is for:

To have the selectable list filtered by type 'external' add:

domain=[('type', '=', 'external')]

You can set the domain either in the field definition (python file) or in the view field (XML file). The actual filter is done by the view; if you set the domain on the field it works as an implicit default domain for the view field.

Upvotes: 1

Related Questions