Skip to Content
Menu
This question has been flagged
1 Reply
4445 Views

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')




Avatar
Discard
Best Answer

TransientModel is a class that stores data in the database temporary and it is automatically cleaned up on a defined period of time.
Go to menu Settings >> Technical >> Automation >> Scheduled Actions and you will able to see cron record for to clean up Transient model data.

Avatar
Discard
Author

Thanks for reply Sreejith. It works by replacing

driver = fields.One2many(comodel_name="module.driver",string='name',inverse_name='driver_id', ondelete='restrict')

to this

driver = fields.Many2many(comodel_name="module.driver",string='name',inverse_name='driver_id', ondelete='restrict')

Related Posts Replies Views Activity
1
Nov 21
4698
0
Jul 24
3645
0
Oct 19
2177
1
Nov 18
1960
0
Jul 18
3028