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

Traversing recordset relations


When working with a recordset of length 1, the various fields are available as record attributes. Relational attributes (One2many, Many2one, and Many2many) are also available with values that are recordsets too. When working with recordsets with more than one record, the attributes cannot be used.

This recipe shows how to use the mapped() method to traverse recordset relations; we will write two methods performing the following operations:

  • Retrieving the e-mails of all contacts of a single partner company passed as an argument

  • Retrieving the various companies to which some contact partners are related

Getting ready

We will be reusing the simplified Partner model shown in the Create new records recipe of this chapter.

How to do it…

To write the partner manipulation methods, you need to perform the following steps:

  1. Define a method called get_email_addresses():

        @api.model
        def get_email_addresses(self, partner):
            partner.ensure_one()
  2. Call mapped() to get the...