Reputation: 1137
On my module I need that when I select departments, only the employees of selected departments appear
employee_id0 = fields.Many2many('hr.employee', string='Employee', index=True)
department_id = fields.Many2many('hr.department', string="Department", store=True, required=True)
<field name="department_id" attrs="{'readonly':[('affec_type','=','category')],'invisible':[('affec_type','=','category')]}" widget="many2many_checkboxes"/>
<field name="employee_id0" attrs="{'invisible':[('affec_type','=','category')]}" widget="many2many_checkboxes" domain="[('department_id', 'in',department_id)]"/>
Upvotes: 2
Views: 1034
Reputation: 4174
Write an on_change
method of department_id
. and fetch all employees related to the departments that you have selected. And return to employee_id
.
Its just a sample code.
@api.depends('department_id')
@api.onchange("department_id")
def _onchange_department_id(self):
vals = {}
data = self.env['hr.employee'].search([('departmentt_id','in',self.department_id.ids)])
ids = list(data.ids)
vals['domain'] = {
"employee_id": [("id", "in", ids)],
}
return vals
Hope it will help you.
Upvotes: 2