I've got a wizard for analysis of sales that has a O2M relation to a transient model that has a M2O relation on crm.team and a M2M relation to res.users.
ModelA(models.TransientModel):
_name = 'model.a'
sale_team_ids = fields.One2many(comodel_name='model.b', inverse_name='wizard_id')
ModelB(models.TransientModel):
_name = 'model.b'
team_id = fields.Many2one(comodel_name='crm.team')
user_ids = fields.Many2many(comodel_name='res.users')
wizard_id = fields.Many2one(comodel_name='model.a')
<record id="model_a_form_view" model="ir.ui.view">
<field name="name">Model A</field>
<field name="model">model.a</field>
<field name="arch" type="xml">
<form>
<sheet>
<field name="sale_team_ids" nolabel="1">
<tree create="1" editable="bottom">
<field name="team_id" required="1"/>
<field name="user_ids" widget="many2many_tags" domain="[('sale_team_id', '=', 'team_id')]"/>
<field name="show_user_data"/>
</tree>
</field>
</sheet>
</form>
</field>
</record>
I need a domain that shows only users that are in the sale team. How can I do this with a domain in the view?
I've got a method that on.change of team_id gets a list of users that are in the sale team.
@api.onchange('team_id')
def _get_domain(self):
if self.team_id:
domain_users = [('id', 'in', self.team_id.member_ids.ids)]
return {'domain': {'user_ids': domain_users}}
But the domain is active only once, after the focus is lost and the user does not change the team_id it shows all users.
So how cam I create a better domain filter and in the view and not in python?