December 2018
Beginner to intermediate
404 pages
10h 14m
English
The write() method is used to write dates on existing records. But we also need to create and delete records. This is done using the create() and unlink() model methods.
The create() method takes a dictionary with the fields and values for the record to be created, using the same syntax as write(). Default values are automatically applied as expected, which is shown here:
>>> Partner = self.env['res.partner']
>>> new = Partner.create({'name': 'ACME', 'is_company': True})
>>> print(new)
res.partner(59,)>>> print(new.customer) # customer flag is True by defaultTrue
The unlink() method deletes the records in the recordset, as shown here:
>>> rec = Partner.search([('name', '=', 'ACME')])
>>> rec.unlink()2018-11-02 ...Read now
Unlock full access