I have made a function in a one2many field so that each time an article is selected, it automatically adds two more articles, but given the current code every time the field is updated, it adds the same items again, I need to Just add the articles only once.
This is my code:
@api.multi
def write(self, values):
domain = [('combo', '=', True)]
articulos = self.env['registro_personal.utiles'].search(domain)
for record in self.lista_ids:
if record.articulo_id.name == 'Bolso':
for articulo in articulos:
if articulo.name not in self.lista_ids:
record.create({
'compra_id': self.id,
'articulo_id': articulo.id,
'name': articulo.name,
'precio': articulo.precio,
})
return super(ComprasAnuales, self).write(values)
and this is what happens every time I edit the record.
In theory, when selecting the Bag Registry, you should bring a pen and notebook only once, but every time I edit the record, add pencil and notebook again, it should be only once. Maybe there is a way to prevent it from repeating itself.