I need to get all parent objects from child object. I don't know how many parent objects it will have, so I think I would need to use recursion here somehow.
So I have an object, that may have or not have other inherited objects. If it has any inherited object, I need to add that objects id to list and then check if that inherited object (or objects) have parents, then if it does, then add those parents ids into same list and check their parents and so on. It should stop when deepest object does not have any parents.
So my code now looks like this:
def get_parent_groups(self, cr, uid, ids, grp_id, context=None):
res = [] # list for parent ids
grp_obj = self.pool.get('res.groups')
#grp_id is childs `id` it means same thing as
# `parent_grp.id`, only that latter is parent object id.
grp = grp_obj.browse(cr, uid, grp_id)
if grp.implied_ids: #check if child has any parent ids
for parent_grp in grp.implied_ids:
res.append(parent_grp.id) #append found parent ids
return res
This code only get first parent object ids. So from here I think I should put recursion and get all other parents, but I can't wrap my head how I should properly get it. Any help?
P.S.
As I see some one asked what things like cr, uid
mean, I didn't specify it as I thought it is not related with this problem (as it is really not), but to make it clear these inputs are needed in OpenERp framework methods:
`cr` - database cursor
`uid` - current user id
`ids` - ids of the object
But as I said, these are not related with problem, I just posted working method to not miss anything.