The create() function generates new records for a specific
model. These new records are initialized using values from the list
of dictionaries (vals list) and, if required, those from the
default_get() function.
Parameters
self.env['model.name'].create({
'field_1': value_1,
'field_2': value_2,
})
E.g., creating a customer:
self.env['res.partner'].create({
'name': 'John Doe',
'email': 'john@example.com',
'phone': '1234567890',
})
- It will raise an AccessError
If the user lacks the necessary permissions to create the
requested object.
An AccessError is raised if the user attempts to bypass access
control rules when creating the requested object.
- It will raise ValidationError
If a user inputs an invalid value into a non-selection field, a
ValidationError will be raised.
- It will raise UserError
A UserError is raised when an operation would create a loop in
an object hierarchy—for example, assigning an object as its own
parent.