Book Image

Odoo Development Cookbook

By : Holger Brunn, Alexandre Fayolle, Daniel Reis
Book Image

Odoo Development Cookbook

By: Holger Brunn, Alexandre Fayolle, Daniel Reis

Overview of this book

Odoo is a full-featured open source ERP with a focus on extensibility. The flexibility and sustainability of open source is also a key selling point of Odoo. It is built on a powerful framework for rapid application development, both for back-end applications and front-end websites. The book starts by covering Odoo installation and administration, and provides a gentle introduction to application development. It then dives deep into several of the areas that an experienced developer will need to use. You’ll learn implement business logic, adapt the UI, and extend existing features.
Table of Contents (23 chapters)
Odoo Development Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

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', '=', True),
                      ('name', 'like', name),
                      '&',
                      ('is_company', '=', False),
                      ('parent_id.name', 'like', name)
            ...