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

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, ...

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