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

Using Abstract Models for reusable Model features


Sometimes, there is a particular feature that we want to be able to add to several different models. Repeating the same code in different files is bad programming practice, so it would be nice to be able to implement it once and be able to reuse it many times.

Abstract models allow us to just create a generic model that implements some feature that can then be inherited by regular models in order to make that feature available in them.

As an example, we will implement a simple Archive feature. It adds the active field to the model (if it doesn't exist already) and makes available an archive method to toggle the active flag. This works because active is a magic field; if present in a model by default, the records with active=False will be filtered out from queries.

We will then add it to the Library Book model.

Getting ready

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

How to do it…

The archive feature would certainly...