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

Exposing Related fields stored in other models


When reading data from the server, Odoo clients can only get values for the fields available in the model being queried. Client-side code can't use dot notation to access data in the related tables like server-side code can.

But those fields can be made available there by adding them as related fields. We will do this to make the publisher's city available in the Library Book model.

Getting ready

We will reuse the my_module addon module from Chapter 3, Create Odoo Modules.

How to do it…

Edit the models/library_book.py file to add the new "related" field:

  1. Make sure that we have a field for the book Publisher:

    class LibraryBook(models.Model):
        # ...
        publisher_id = fields.Many2one(
            'res.partner', string='Publisher')
  2. Now, add the related field for the Publisher's city:

    # class LibraryBook(models.Model):
        # ...
        publisher_city = fields.Char(
            'Publisher City',
            related='publisher_id.city')
    

Finally, we need to upgrade the...