I would like to know how to copy a One2many field, that is let's say that I have 2 One2many fields that point to different models, and in both models are the same fields, and I want to create a method where all the contents of the first One2many field are copied to me in the second field One2many, I do not know if you explain ... I wait for your answers, Greetings and thanks in advance if you can help me.
Try this test code to see if it worked but I get an error:
def foo(self):
detalles = self.env['detalle'].browse(self._context.get('active_ids', []))
obj = self.env['detalle2contract']
for r in self:
for d in detalles:
tipo = d.tipo
descripcion = d.descripcion
cantidad = d.cantidad
unidad = d.unidad
detalle2contract_id = d.detalle_id
lines = obj.create({
'tipo': tipo,
'descripcion': descripcion,
'cantidad' cantidad,
'unidad': unidad,
'detalle2contract_id': detalle2contract_id
})
return lines