-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Odoo 11 Development Cookbook - Second Edition - Second Edition
By :
Models can have validations preventing them from entering undesired conditions.
Two different types of constraints can be used:
Database-level constraints are limited to the constraints supported by PostgreSQL. The most commonly used ones are the UNIQUE constraints, but the 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 4,Creating Odoo Addon 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.
We will reuse the my_module addon module from Chapter 4,Creating Odoo Addon Modules.
We expect it to contain at least the following:
from odoo import models, fields class LibraryBook(models.Model...