0

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.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • 1
    Your question is not clear. Could you explain a bit more your needs? – aekis.dev Sep 07 '18 at 20:39
  • I need to copy records from model A to model B, but if i add new records in model B they must be writen in model A as well. – Luis Contreras Sep 07 '18 at 23:17
  • 1
    Still unclear, also your model definitions have several errors, like the field employee_family_ids with form_family_id as the target model. You should edit your whole question to make it clear because I could tell you that you could override the create and write from one model to write into the other one the relation field that connect boths records, or you could write a function field to search for all the records matching boths model relations, but it's not clear to me what it's your goal and design – aekis.dev Sep 08 '18 at 01:43
  • Thats the solution in looking for, i must redefine write and create ORM, however i dont know how the code should look like, never thougth of making a search, wich could work getting the family members of with the same employee_id.id, but again, i dont know how the code should look like. – Luis Contreras Sep 08 '18 at 22:50

1 Answers1

-1

Family members must be a many2many relation between homes and employees.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Blue Robin Mar 15 '23 at 00:07