In the employee profile, I added a Many2one
field which relates to the employee table itself (known as Reporting of the current employee) and another field is a Many2one
with a foreign key of Reporting manager field.
And I have another field Many2many
related to the employee table itself, called All reporters. I need to populate all the reporters to the Many2many field including my sublevel reporters.
Here is the structure:
A B C D
| | | |
/ | \ / | \ / | \ / \
E F G H I J K L M N O
/|\ /|\ | /\
P Q R S T U V W X
This is what I want,
- The many2many of A, need to populate with: E,F,G,P,Q,R,S,T,U
- The many2many of B, need to populate with: H,I,J
- The many2many of C, need to populate with: K,L,M,V
- The many2many of E, need to populate with: P,Q,R
- The many2many of N, need to populate with: W,X
Here is my code:
reportee_ids = fields.One2many('hr.employee','reporting_officer_id',string="Reportees")
employee_child_ids = fields.Many2many('hr.employee')
def compute_reportees(self,emp,list1=None):
rm_id = emp.reporting_officer_id
if list1 is None:
list1 = []
if emp.id != rm_id.id:
list1 += emp.reportee_ids.ids + rm_id.reportee_ids.ids
rm_id.user_id.write({'employee_child_ids':list1})
self.compute_reportees(rm_id,list1)
else:
return list1
How can I do this?