I have a model called PERSON, with the generals of a person (name, sex, surname, etc), but a person also has parents who are PERSON type and a person has grandparents of the PERSON type also and who are the parents from his parents. I also have an INVITATION model, in which I must use the information of a person, their parents and their grandparents, the question is:
1- How do I relate parents and grandparents in the person model?
2- How do I relate the children, with the parents, with their grandparents in the invitation model?
3 - and more importantly, how do I access the fields of children, their parents and grandparents from the view of the invitation model ?.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
Hello Cybrosys Techno Solutions Pvt.Ltd, thank you very much for your answer, first I have to tell you that I'm not working on anything specific, I'm just learning Odoo and this topic of inheritance seemed like a good place to start, that is, I do not have anything codified yet, I'm gathering information to get me to code. I was thinking of doing exactly what you tell me, but in the INVITATION model, not in the PERSON model, becouse is in the INVITATION model that I will work with the data of the people (son, parents, grandparents). My INVITATION model would look like this( please don´t check the names, this is just an excercise):
class wed_invitation(models.Model):
_name='wed.invitation'
_inherits = {'wed.person': 'child_id',
'wed.person': 'father_id',
'wed.person': 'mother_id',
'wed.person': 'grand_father_father_id',
'wed.person': 'grand_mother_father_id',
'wed.person': 'grand_father_mother_id',
'wed.person': 'grand_mother_mother_id',
}
wed_date = fields.Date('Wedding date:')
wed_address = fields.Char('Address:')
#relationals fields
child_id= fields.Many2one(comodel_name="wed.person", string="", required=False)
father_id= fields.Many2one(comodel_name="wed.person", string="", required=False)
mother_id= fields.Many2one(comodel_name="wed.person", string="", required=False)
grand_father_father_id= fields.Many2one(comodel_name="wed.person", string="", required=False)
grand_mother_father_id= fields.Many2one(comodel_name="wed.person", string="", required=False)
grand_father_mother_id= fields.Many2one(comodel_name="wed.person", string="", required=False)
grand_mother_mother_id= fields.Many2one(comodel_name="wed.person", string="", required=False)
Now, at the view, how do I know which field belongs to the son, and which one to the father or the
mother or the grandparents separately? As I define only the name of the model wed.invitation in
the view then I do not know how to refer to each of the fields. Someone told me to declare all the
fields in the INVITATION model, like this:
father_name = fields.Char (string = 'Name',
store = True,
related = 'father_id.name')
father_surname = fields.Char (string = 'Surname',
store = True,
related = 'father_id.surname')
.
.
.
grand_mother_mother_name = fields.Char (string = 'Grand mother (Mother)'s Name',
store = True,
related = 'father_id.name')
and then use them in the model INVITATION ´s view, but i don´t think this is a good looking
solution. How do i use the parents fields in the view!!??
thanks!!!
Hi Julio,
You can define Many2one fields for Father, Mother, Grand Father(Mother), Grand Mother(Mother), Grand Father(Father), Grand Mother(Father) and a One2many field for children in the person model.
Please provide more information about the Invitation model.So that we can check what we can do.
Regards
Hi,
you can follow below link:
https://www.odoo.com/documentation/10.0/reference/orm.html#fields
* you can read Fields/Related Fields Section
Thank You
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up