Writing on records

Recordsets implement the active record pattern. This means that we can assign values on them, and these changes will be made persistent in the database. This is an intuitive and convenient way to manipulate data, as shown here:

>>> admin = self.env['res.users'].browse(1)
>>> print admin.name 
Administrator
>>> admin.name = 'Superuser'
>>> print admin.name 
Superuser

Recordsets also have three methods to act on their data: create(), write(), and unlink().

The create() method takes a dictionary to map fields to values and returns the created record. Default values are automatically applied as expected, which is shown here:

>>> Partner = self.env['res.partner'] >>> new = Partner.create({'name': 'ACME', 'is_company': True}) >>> ...

Get Odoo 11 Development Essentials - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.