In TransientModel I want to write/update a Many2many field but it only write in last record. I am overriding the write method and call write on many2many field.
Code:
class dispatch_processing(models.TransientModel):
_name = "module.dispatch_processing"
dispatch_ids = fields.Many2many(comodel_name="module.dispatch", string='Dispatch Order Numbers')
driver = fields.Many2many(comodel_name="module.driver",string='Delivery Men', ondelete='restrict')
@api.multi
def write(self, values):
self.dispatch_ids.write(values)
In values:{u'truck_number': 1, u'driver': [[6, False, [2, 1]]]}
I had also tried this in for loop but still update only last record.
Here is dispatch model:
class dispatch(models.Model):
_name = 'module.dispatch'
truck_number = fields.Many2one("module.truck",'Truck Number', ondelete='restrict')
driver = fields.One2many(comodel_name="module.driver",string='name',inverse_name='driver_id', ondelete='restrict')