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