Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Checking relationship between to objects of the same class

By
Alexei R. Acosta
on 9/11/14, 2:19 PM 648 views

Hello, I need some help in what follows:

I have a class animal with two relational fields to itself:

class animal(osv.osv):

_name = 'animal.animal'

_columns = {

'parent_id': fields.many2one('animal.animal', string='Mother', domain="[('sex', '=', 'female')]"),

'father_ids': fields.many2many('animal.animal',  'animal_father_rel', 'animal_id', 'father_id', string='Fathers', domain="[('sex', '=', 'male')]"),

'father_chid_ids': fields.many2many('animal.animal',  'animal_father_rel', 'father_id', 'animal_id', string='Child animals'),

'chid_ids': fields.one2many('animal.animal',  'parent_id', string='Child animals')

}

As you can see, an animal have only one mother of course, but may have registered one or more fathers (usually they are two), because a female animal may receive one or more services of fertilization, either by artificial insemination or natural service.

So I need to develop a functionality that allows to check relationship between two animal. It should return if those two animals are descendants of an animal, if this is the case, it should show how many generations are between each one and that ancestor; if one of them is direct descendant of the other or if they are not relatives at all.

Perhaps this is not a proper OpenERP question, but I'm stuck here.

Any help, thanks in advanced.

Regards.

0

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
On 9/12/14, 1:32 AM

Alexei, if your concern is only for the relationship between mother and off-spring, I would suggest that you turn on the parent support in your model by specifying _parent_store = True in the model.  Then, OpenERP will provide you with 2 additional fields, parent_left and parent_right.  You can pretty much deduce the relationship between the 2 animals by calculation involving the value of the 2 fields from each animal.  OpenERP implement Nested Set Model if you do so.

If you need to know the relationship amongts all animal (father included), I'm afraid that you need to develop your own algorithm.

 

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 9/11/14, 2:19 PM
Seen: 648 times
Last updated: 3/16/15, 8:10 AM