How to do it...

In order to create a partner with some contacts, you need to take the following steps:

  1. 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)
  1. Prepare a dictionary of values for the fields of the first contact:
    val1 = {'name': 'Eric Idle', 
            'email': '[email protected]' 
            'date': today_str} 
  1. Prepare a dictionary of values for the fields of the second contact:
    val2 = {'name': 'John Cleese', 
            'email': '[email protected]', 
            'date': today_str} 
  1. 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), 
                      ] 
    } 
  1. Call the create() method to create the new records:
record = self.env['res.partner'].create(partner_val) 
..................Content has been hidden....................

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