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

Adding constraint validations to a Model


Models can have validations preventing them from entering undesired conditions. Two different types of constraint can be used: the ones checked at the database level and the ones checked at the server level.

Database level constraints are limited to the constraints supported by PostgreSQL. The most commonly used are the UNIQUE constraints, but CHECK and EXCLUDE constraints can also be used. If these are not enough for our needs, we can use Odoo server level constraints, written in Python code.

We will use the Library Book model created in Chapter 3, Creating Odoo Modules and add a couple of constraints to it. We will add a database constraint preventing duplicate book titles, and a Python model constraint preventing release dates in the future.

Getting ready

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

We expect it to contain at least the following:

# -*- coding: utf-8 -*-from openerp import models, fieldsclass LibraryBook...