简体   繁体   中英

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'???

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM