Filter results in Many2Many widget by Category 'subfield'

I built a relation:

    gatekeepers = fields.Many2Many('', 'sale', 'gatekeeper',
        search_context={'name': '????????'}, # <--- is that a way?!? how?
        string = 'Gatekeepers for the Sale Order', 
        help = 'Select gatekeepers for this sale order',

class GatekeepersPartyRealtion(ModelSQL):
    'Sales - Gatekeepers relation'
    __name__ = ''

I want to see these parties (in the list that pops up with the search) that has
‘gatekeeper’ in their category list:

Could you recommend me a way to implement it?
how to define the domain?


I guess that gatekeeper on GatekeepersPartyRealtion class is a Many2One to
So it means you want to get a domain on the Many2Many based on a specific record of category. This is not really a good design because it will require to create this category from XML so you can use PYSON Id. In such case the domain would be:

domain=[('category', '=', Id('<module>', '<gatekeeper xml id>'))]

Another way which is probably more flexible is to add on the category a Boolean field that define that this category give the right to the party to be used as gatekeeper. So the domain would be:

domain=[('category.gatekeeper_allowed', '=', True)]
1 Like

I like the second idea, will use it today.


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.