Updating Records

Updating Records in Odoo 18

Records can be updated using the interface, importing a file, or via code/API.

1. Assign values directly to a field

Directly assigning a value to a field is possible. self refers to the record being updated.

self.test_boolean = True

2. Using update() method

The update() method modifies the value of fields using a dictionary that maps each field to its new value.

self.update({
  'start_date': fields.Date.today(),
  'test_boolean': False
})

3. Using write() method

Similar to update(), but also handles ORM validations and recordset operations. This triggers a single database write call for the entire recordset, making it efficient even for large updates.

self.write({
   'start_date': fields.Date.today(),
   'test_boolean': True
})

Note: Relational fields must be handled using fields.Command commands.

Relational Field Commands

  • fields.Command.create(values) – Create a new record in the related model and link it.
  • fields.Command.update(id, values) – Update the linked record with the specified ID.
  • fields.Command.delete(id) – Delete the related record entirely from the database.
  • fields.Command.unlink(id) – Remove the link without deleting the record.
  • fields.Command.link(id) – Link an existing record.
  • fields.Command.clear() – Remove all existing links.
  • fields.Command.set([ids]) – Replace all links with the given list of IDs.
whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message