xml-rpcodoo-13

In Odoo 13, XML-RPC, how can I update a field for multiple records?


I'm attempting to update a field for multiple records.

The Odoo 13 Developer API document reads that it is possible, but does not give an example how.

https://www.odoo.com/documentation/13.0/developer/api/odoo.html#update-records

"Multiple records can be updated simultaneously, but they will all get the same values for the fields being set."

The below does not work:

    models.execute_kw(db, uid, pw, 'table.name', 'write',
                                   [[records_to_update], {'field': value}])

records_to_update is a list of the record ids.

I receive this error:

"-> message_values = dict((message_id, {}) for message_id in self.ids)"

I have spent quite some time searching for an answer and have come up blank so far.


Solution

  • You should see the following error message:

    unhashable type: 'list' 
    

    records_to_update is a list of the record ids and it should be the first argument to the write function

    Example:

    models.execute_kw(db, uid, pw, 'table.name', 'write',
                                       [records_to_update, {'field': value}])