Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
7 Trả lời
31280 Lượt xem

How do I access the department_id through the user.id on a domain filter?

I created a rule with Leave as the object. My goal is to have the user see leaves only from employees of his/her department. I see that an employee is connected to the user by user.id and employee contains the field department_id.

None of the following domain filters worked:

[('department_id','=',user.id.employee_id.department_id)]

[('department_id','=',['employee_id.user_id','=',user.id,'.','department_id'])]

[('department_id','=','employee_id.user_id')]

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

I would say this is the right answer:

<field name="domain_force">[('department_id.member_ids.user_id', 'in', [user.id])]</field>

Explanation:

  • user.id" - in the data model of OpenERP for res_users no way to hr_employee is possible
  • therefore department_id.member_ids will just give back a list with employee_ids
  • in hr.employee the field user_id is available - therefore the path deparment_id.member_ids.user_id is the right way
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Try this one: (Settings > Technical > Record Rules)


<record id="record_rule_id" model="ir.rule">

<field name="name">Your Rule Name</field>

<field name="model_id" ref="module.your_model_id"/>

<field name="domain_force">['|', ('department_id', '=', False), (' department_id ','child_of',[user. department_id .id])]</field>

<field name="perm_write" eval="1"/>

<field name="perm_create" eval="1"/>

<field name="perm_read" eval="1"/>

<field name="perm_unlink" eval="1"/>

</record>


I hope this may help you.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Try Following,

domain = "[('department_id','=',user.id.employee_id.department_id)]" in your xml file.

Hope it work for you.

Ảnh đại diện
Huỷ bỏ
Tác giả

On what particular XML file do I add it and where is it located? I tried adding the rule on ir_rule.xml under the security folder of the hr_holidays addon but it still doesn't work. Thanks for the answer.

Put this domain on your field, suppose you field is xyz, then add <field name="xyz" domain="[('department_id','=',user.id.employee_id.department_id)]" />

Tác giả

I found another way around and it worked. I used this domain filter instead: [('department_id.member_ids','=',user.id)] Thanks again.

Câu trả lời hay nhất

Hello kevin, nasolve mo ba ung problem mo sa domain filter? hindi ko kc makuha sakin.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 3 15
6627
0
thg 3 15
4193
1
thg 10 21
2636
0
thg 3 15
3481
0
thg 2 19
5316