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

Hi all,

In my extension to hr.employee I utilize 1:n relation between user and employe: One (system) user has n related employees in user.employe_ids.

When the user logs in he is allowed his employe + child records only:

domain_force of ir.rule:

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

 
 The domain rule works fine if there is 1:1 for user and employe. However, I cannot find a way to iterate through user.employee_ids and test child_of for a given employe_id.
 
 Things I tried so far without success:
 1.


('id','child_of',[employe.id for employe in user.employee_ids])

 causes an exception
 
 2. Inheriting ir_rule:
 

 @api.model   
def _eval_context(self):
    res = super(IRRuleWithSiblings,self)._eval_context()                    
    subordinates = []        
        for employe in self.env.user.employee_ids:                        
            children = self.env['hr.employee'].search([('id', 'child_of', employe.id)])                           
    for child_id in children:               
        subordinates.append(child_id.id)                            
        res['subordinates'] = subordinates       
return res

       
ir.rule record:       

        <field name="domain_force">['id','in',subordinates)</field>


causes
RecursionError: maximum recursion depth exceeded

Can anyone advice me how to iterate through user.employe_ids and check for siblings?

Regards,
Matthias

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

did you find the solution?

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 8 25
3684
1
thg 10 24
3403
2
thg 7 24
2240
0
thg 5 23
2449
9
thg 12 23
33508