Launch offer
Business website $150 USD Custom plugin $200 USD Ready in 5 days
Get a quote
Odoo

Constraints and Validation in Odoo

Validate business rules with @api.constrains and UserError/ValidationError.

Constraints and Validation in Odoo — a practical guide to Odoo constraints validation with clear examples you can reuse in real projects.

Odoo Tutorial Series (60/112). Prefer one article? Read the complete Odoo tutorial.

Short description

Fail early with clear messages users can act on.

constrains

from odoo.exceptions import ValidationError

@api.constrains('pages')
def _check_pages(self):
    for rec in self:
        if rec.pages < 0:
            raise ValidationError('Pages cannot be negative.')

Leave a reply

Your email address will not be published. Required fields are marked *