Boubaker
Boubaker

Reputation: 429

Rules For Many2many in ODOO 12

I have a parent department, and I have several sub departments, and some employees organize under his department so I create a Many2many field in the res.user model that calls the departments.

class HrDepartment(models.Model):
    _inherit = 'res.users'

    dep_ids = fields.Many2many('hr.department', string='Department')

and I made a rules for that, so that when I have a department selected in this user, the user can not see that the employees under these departments

 <record model="ir.rule" id="employee_center_multi_department">
       <field name="name">Employee Multi Department</field>
       <field name="model_id" ref="model_hr_employee" />
       <field name="groups" eval="[(4, ref('charity_center_groups.group_manager_center_department'))]" />
       <field name="global" eval="True" />
      <field name="domain_force">[('department_id.parent_id.id','=',[user.dep_ids.id])]</field>   
    </record>   

When I choose a single department it shows me the employees perfectly but when I choose more than one department it shows me an error

ValueError: <class 'ValueError'>: "Expected singleton: hr.department(3, 4)" while evaluating
"[('department_id.parent_id.id','=',[user.dep_ids.id])]"  

Upvotes: 0

Views: 1254

Answers (1)

Boubaker
Boubaker

Reputation: 429

I found the solution

need to put a loop in the field many2many,

domain_force is work perfectly

 <field name="domain_force">['|',('department_id.parent_id.id','in',[x.id for x in user.dep_ids]),('id','in',[x.id for x in user.dep_ids])]</field> 

Upvotes: 1

Related Questions