In order to create a partner with some contacts, you need to take the following steps:
- Inside the method that needs to create a new partner, get the current date formatted as a string expected by create():
def some_method(self):
today_str = fields.Date.context_today(self)
- Prepare a dictionary of values for the fields of the first contact:
val1 = {'name': 'Eric Idle', 'email': '[email protected]' 'date': today_str}
- Prepare a dictionary of values for the fields of the second contact:
val2 = {'name': 'John Cleese', 'email': '[email protected]', 'date': today_str}
- Prepare a dictionary of values for the fields of the company:
partner_val = { 'name': 'Flying Circus', 'email': '[email protected]', 'date': today_str, 'is_company': True, 'child_ids': [(0, 0, val1), (0, 0, val2), ] }
- Call the create() method to create the new records:
record = self.env['res.partner'].create(partner_val)