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

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

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