Filter results in Many2Many widget by Category 'subfield'

I built a relation:

    gatekeepers = fields.Many2Many('sale.sale-party.party.gatekeepers', '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__ = 'sale.sale-party.party.gatekeepers'

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

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

Constantine.

I guess that gatekeeper on GatekeepersPartyRealtion class is a Many2One to party.party.
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.

Thanks!
Constantine.

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