Raising exceptions

When something is not right, we will want to interrupt the program with an error message. This is done by raising an exception. Odoo provides a few additional exception classes in addition to the ones available in Python.

These are examples for the most useful ones:

from odoo import exceptions 
raise exceptions.Warning('Warning message') 
raise exceptions.ValidationError('Not valid message') 

The Warning message also interrupts execution but can sound less severe than a ValidationError. All data manipulation done during the method execution is in a database transaction, which is rolled back when an exception occurs. This means that all these database operations will be canceled.

While it's not the best user interface, we ...

Get Odoo 11 Development Essentials - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.