O'Reilly logo

Odoo Development Cookbook by Daniel Reis, Alexandre Fayolle, Holger Brunn

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Searching for records

Searching for records is also a common operation in business logic methods. This recipe shows how to find all the Partner companies and their contacts by company name.

Getting ready

This recipe will be using the same simplified res.partner definition as the Creating new records recipe previously. You may refer to this simplified definition to know the fields.

We will write the code in a method called find_partners_and_contact(self, name).

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']
  2. Write the search domain for your criteria:
     domain = ['|', '&', ('is_company', '=', ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required