How to do it...

In order to find the partners, you need to perform the following steps:

  1. Get an empty recordset for res.partner:
    @api.model 
    def find_partners_and_contacts(self, name): 
        partner = self.env['res.partner'] 
  1. Write the search domain for your criteria:
     domain = ['|',  
              '&',  
               ('is_company', '=', True), 
               ('name', 'like', name), 
               '&', 
               ('is_company', '=', False), 
               ('parent_id.name', 'like', name) 
               ] 
  1. Call the search() method with the domain and return the recordset:
    return partner.search(domain)