I have two models, one is hr.employee which has a one-to-many relation with a new custom module called, hr.family where the employee declares all their family members.
On the other side, I have another model called hr.form.home. where an employee can declare information about their place of living, also here there is an one2many relation with a new class called, hr.family.home, which contains the same fields of hr.family
The code look like this:
This is the base hr which contains information of the employee class:
Class hr_employee(models.Model):
_name = "hr.employee"
_descripcion = "Employee"
employee_name = fields.Char('Employee Name')
employee_family_ids =
fields.One2many('hr.family','employee_id','family')
Then I have the model which contains all the information of the family.
Class form_family(models.Model):
_name = "hr.family"
_descripcion = "Employee"
employee_id = fields.Many2one('hr.employee')
name = fields.Char('Family member name')
relation = fields.Selection('mother, wife, etc')
Now, on the other side, I have a model which must contain the information of the living place of the employee, including the family members which must be write by an automatic methods.
Class form_home(models.Model):
_name = "form.home"
employee_id = fields.Many2one('hr.employee','Employee')
roms = fiels.Integer('How Many roms?')
address = field.Char('Address')
employee_family_ids =
fields.One2many('hr.family.home','home_id','family')
Class hr_family_home(modesl.Model):
_name: "hr.family.home"
home_id = fields.Many2one('form.home')
name = fields.Char('Family member name')
relation = fields.Selection('mother, wife, etc')
In order to avoid the employee load their family members twice, if a family member its written in hr.family an automatic copy must be made in hr.family.home.