In Odoo development, writing code that works is just the beginning.
What really makes your module feel professional is how well it handles errors.
Most developers know how to raise an error.
But the real question is:
Are you using the right error for the right situation?
- Should this be a UserError?
- Or a ValidationError?
- Or something related to access rights?
Let’s simplify this once and for all.
Why Error Handling Actually Matters
Error handling is not just a backend concern—it directly affects your users.
Good error handling helps you:
- Prevent bad data from entering the system
- Guide users when something goes wrong
- Avoid broken workflows
- Build trust in your application
Users may not appreciate your clean code,
but they will definitely notice confusing errors or failed actions.
The Real Difference (Simple Way to Think)
Instead of memorizing definitions, think like this:
- ValidationError → “This data is wrong.”
- UserError → “This action cannot continue.”
- AccessError → “You are not allowed to do this.”
That’s it. If you remember this, you’ll rarely go wrong.
UserError — When the Flow Should Stop
Think of UserError as a business rule check during an action.
The user is doing something… but something is missing.
Example situations
- Clicking Approve without completing required steps
- Trying to confirm incomplete data
- Skipping a mandatory process
Example message
“You cannot approve a salary without HR review.”
Notice this:
👉 You’re not saying the data is wrong.
👉 You’re saying the action is not allowed right now.
ValidationError — When Data Itself Is Wrong
Now this is stricter.
ValidationError means:
“This should never be saved in the database.”
Example situations
- Negative salary
- Invalid values
- Missing required logic-based data
This is usually used in constraints.
If this triggers, the record won’t be saved at all.
AccessError — When Permissions Are the Problem
This one is straightforward.
The issue is not the data or the workflow — it’s permissions.
Example situations
- User trying to edit restricted records
- Violating record rules
- Accessing something they shouldn’t
👉 This keeps your system secure.
Quick Practical Example
Let’s see how this works in real code:
from odoo.exceptions import ValidationError, UserError
from odoo import models, fields, api
class SalaryDetails(models.Model):
_name = 'salary.details'
basic_salary = fields.Float(string="Basic Salary")
allowance = fields.Float(string="Allowance")
@api.constrains('basic_salary')
def _check_basic_salary(self):
for record in self:
if record.basic_salary < 0:
raise ValidationError("Basic salary cannot be negative.")
def action_approve(self):
if not self.allowance:
raise UserError("Allowance must be added before approval.")
What’s really happening here?
- ValidationError ensures bad data never gets saved
- UserError ensures the process doesn’t move forward incorrectly
Same model, different responsibilities.
Golden Rules (From Real Projects)
If you remember nothing else, remember this:
- Always show clear, human-readable messages
- Don’t expose technical errors to users
- Use ValidationError for data validation
- Use UserError for workflows and actions
- Log errors for developers, not for users
Why This Matters in Real Life
Clients don’t care about exception types.
They care about:
- Smooth workflows
- Clear messages
- No unexpected crashes
- Reliable system behavior
Smart error handling is one of the easiest ways to make your work stand out as senior-level Odoo development.
Once you start thinking like this:
- ValidationError → protect the database
- UserError → guide the user
- AccessError → enforce permissions
Your code automatically becomes:
- Cleaner
- Safer
- Easier to maintain
And most importantly — much better for the end user.
Have an Odoo Requirement? Let's Talk.
Whether you're planning a new Odoo implementation, struggling with performance issues, or looking to build custom integrations — we're here to help.
Our team works with businesses of all sizes to design, develop, and optimize Odoo solutions that actually fit the way you work. From queue job architecture to full-scale ERP customization, we've got you covered.
📩 Reach out to us at: contact@opturatech.com 🌐 Whatsapp us at: +91 7025199191.
Or simply fill out our Contact Form → and we'll get back to you within one business day.