December 2018
Beginner to intermediate
404 pages
10h 14m
English
When something does not work as expected, we may want to inform the user and interrupt the program with an error message. This is done by raising an exception. Odoo provides exception classes that we should use for this.
The most useful Odoo exceptions to be used in add-on modules are the following:
from odoo import exceptions
raise exceptions.ValidationError('Not valid message')raise exceptions.UserError('Business logic error')
The ValidationError exception should be used for validations in Python code, such as @api.constrains decorated methods.
The UserError exception should be used in all other cases where some action should not be allowed, because it goes against business logic.
Read now
Unlock full access