在我的模块上,我需要在选择部门时,只显示所选部门的员工
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)]"/>
答案 0 :(得分:1)
编写on_change
department_id
方法。并获取与您选择的部门相关的所有员工。并返回employee_id
。
它只是一个示例代码。
@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
希望它会对你有所帮助。