Writing on records
We have two different ways to write on records—using object-style direct assignment and using the write()
method. The first one is simpler to use but only works with one record at a time and can be less efficient. Since each assignment performs a write
operation, redundant recomputations may happen. The latter requires special syntax to write on relation fields, but a single command can write on several fields and records, and more efficient field recomputations.
Writing with object-style value assignment
Recordsets implement the active record pattern. This means that we can assign values to them, and these changes will be made persistent in the database. This is an intuitive and convenient way to manipulate data, but only works with one field and one record at a time.
Here is an example:
>>> root = self.env['res.users'].browse(1)
>>> print(root.name)
OdooBot
>>> root.name = 'Superuser'
>>> print(root.name)
Superuser
While using the active...