Search code examples
pythonodooodoo-8

Odoo append to one2many


How do you add new line to one2many?

I have tried

car_ids = fields.One2many()
for line in used_car_ids:
    value = {   'make': line.make,
                'type': line.type
            }
    self.car_ids = [(0,0,value)]

But it does not append. The car_ids will always be filled with only one used_car_ids (only the last used_car_ids)

How do I append to one2many?


Solution

  • Maybe you should try the following:

    car_ids = fields.One2many()
    
    result = []
    for line in used_car_ids:
        result.append((0, 0, {'make': line.make, 'type': line.type}))
    self.car_ids = result
    

    Hope that will help.