How to do it...

Odoo v12 added support for creating records in batches. If you are creating a single record, simply pass a dictionary with the field values. To create records in a batch, you just need to pass a list of these dictionaries instead of a single dictionary. The following example creates three book records in a single create call:

vals = [{
'name': "Book1",
'date_release': '2018/12/12',
}, {
'name': "Book2",
'date_release': '2018/12/12',
}, {
'name': "Book3",
'date_release': '2018/12/12',
}]

self.env['library.book'].create(vals)

Write operations are carried out on the recordset. You should avoid using write operations in the for loop if you are writing the same data on multiple recordsets:

# not good
data = {...}
for record in recordset:
record.write(data)

# good
data = {...}
recordset.write(data)

If you are writing a single value, it is possible to write data by assigning values such as self.name = 'Admin'. Check the following example to explore the correct usage of the write operation:

# not good
recordset.name= 'Admin'
recordset.email= '[email protected]'

# good
recordset.write({'name': 'Admin', 'email'= '[email protected]'})
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset