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

Defining model methods and use the API decorators


The model classes defining custom data models declare fields for the data processed by the model. They can also define custom behavior by defining methods on the model class.

In this recipe, we will see how to write a method that can be called by a button in the user interface, or by some other piece of code in our application. This method will act on LibraryBooks and perform the required actions to change the state of a selection of books.

Getting ready

This recipe assumes you have an instance ready, with the my_module addon module available, as described in Chapter 3, Creating Odoo Modules. You will need to add a state field to the LibraryBook model defined as follows:

from openerp import models, fields, api
class LibraryBook(models.Model):
    # […]
    state = fields.Selection([('draft', 'Unavailable'),
                              ('available', 'Available'),
                              ('borrowed', 'Borrowed'),
                      ...