SlideShare a Scribd company logo
Errors and exceptions in Odoo 18
Enterprise
Enterprise
Introduction
In Odoo 18, there are many kinds of errors and exceptions possible
while running the module or code under development.
Error management in Odoo 18 involves understanding how the
system handles exceptions and bugs, as well as employing good
practices to manage and resolve them effectively.
Odoo 18 have the common and standard exceptions like Attribute
Error, Value Error, Type Error, Validation Error, etc
Enterprise
1.ValidationError
At any time, we can raise an exception in Odoo using the ValidationError based
on any condition we need to set. For example, we can just set a Validation error
for the stock.picking model if the field partner_id , ie ‘Receive From’ is not filled
using the code.
from odoo import models
from odoo.exceptions import ValidationError
class StockPicking(models.Model):
_inherit = 'stock.picking'
def button_validate(self):
result = super(StockPicking, self).button_validate()
if not self.partner_id:
raise ValidationError('Fill in the field "Receive From"')
return result
Enterprise
While trying to validate the picking without filing the ‘Receive From’ field, it
shows like
Enterprise
2.UserError
User Errors can also be raised with the needed constraints or conditions with
which the system undergoes checks for every record. Import UserError from
odoo.exceptions and we can just replace the previous code as below to
demonstrate the workflow.
from odoo import models
from odoo.exceptions import UserError
class StockPicking(models.Model):
_inherit = 'stock.picking'
def button_validate(self):
result = super(StockPicking, self).button_validate()
if not self.partner_id:
raise UserError('Fill in the field "Receive From"')
return result
Enterprise
And in the UI, whenever the condition is true, the exception will pop
up like
Enterprise
3.AccessError
This exception is used when the user tries to login to the Odoo instance with
invalid login details. First, we need to import AccessError as
from odoo.exceptions import AccessError
Now, let’s write a simple python code to block all the users other than Admin
from accessing a document.
if not self.env.is_admin():
raise AccessError(_("Sorry, you are not allowed to access this
document."))
Enterprise
4.MissingError
These Missing Errors are used in Odoo 18 usually when the user tries to access
any record or data that is not actually available in the database of the instance. It
may have either been deleted/ removed or doesn’t exist at all.
For the previous code, let’s try to access any record with a random ID, say 1000 as
def button_validate(self):
result = super(StockPicking, self).button_validate()
print(self.browse(1000).name)
return result
Enterprise
Here, the stock.picking(1000,) is a non existing record and hence, while
clicking on the Validate button, it will pop up the Odoo 18’s inbuilt
exception as
Enterprise
We can add our own Missing Error exception first by importing it from
odoo.exceptions.
from odoo.exceptions import MissingError
And then by raising it as below.
raise MissingError('Missing Error Demo')
Enterprise
5.Access Denied
Access Denied exception in the case when a user tries to perform any
kind of action or operation for which he/she is not allowed to do due
to the restriction in the access rights.
from odoo import models
from odoo.exceptions import AccessDenied
class StockPicking(models.Model):
_inherit = 'stock.picking'
def button_validate(self):
if not self.env.is_admin():
raise AccessDenied("You are not allowed to validate the
Operation")
return super(StockPicking, self).button_validate()
Enterprise
Here, for any user other than Admin, the right to validate the stock
movement will be denied. Let us login to the system as any other
internal user with no Admin access and try to validate the picking. The
error will come like
Enterprise
6.CacheMiss
This error is raised by Odoo in case when a record or a data is not found. Odoo
usually caches data about the record that is accessed recently for some time. This
CacheMiss occurs when the needed record is not found in the cache. It can be
caused due to high traffic or the memory limits allowed.
country = self.env['res.country].browse(1)
print(country.name)
Here, in the first line, the ‘country’ variable is having a value. Odoo fetches it from the
database and stores it in the cache. And in the second line, ‘country.name’ is printed.
During this time, Odoo will return it from cache without requiring to run a database
query again as in the first line.
In case if it is not found in the cache, CacheMiss exception will pop up.
Enterprise
7. RedirectWarning
This error is raised to redirect the workflow to a particular page instead of giving any
warning to the user. Redirect Warning can be useful to suggest an alternate flow that
should be followed, such as confirming an operation or redirecting to a form view
before continuing with the original action.
The necessary parameters for RedirectWarning are
action_id: It is the id of the action were to perform the redirection
message: It is the message for exception
button_text: It is the text to put on the button that will trigger the redirection
Enterprise
With our previous example of validating a picking, let’s rewrite the code to implement
Redirect Warning for demonstration as
from odoo import _, models
from odoo.exceptions import RedirectWarning
class StockPicking(models.Model):
_inherit = 'stock.picking'
def button_validate(self):
warehouse_action = self.env.ref('stock.action_warehouse_form')
msg = _('Please create a warehouse for company %s.',
self.env.company.display_name)
raise RedirectWarning(msg, warehouse_action.id, _('Go to Warehouses'))
return super(StockPicking, self).button_validate()
Enterprise
Here, while validating the picking, the system will generate a Redirect
Warning with a message on the body and two buttons named ‘Go to
Warehouses’ and ‘Close’.
Enterprise
While clicking on the ‘Go to Warehouses’ button, we get the page
For More Info.
Check our company website for related blogs
and Odoo book.
Check our YouTube channel for
functional and technical videos in Odoo.
Enterprise
www.cybrosys.com
Ad

More Related Content

Similar to Errors and exceptions in Odoo 18 - Odoo Slides (20)

How to make a component and add it to systray in Odoo
How to make a component and add it to systray in OdooHow to make a component and add it to systray in Odoo
How to make a component and add it to systray in Odoo
Celine George
 
Diving into VS 2015 Day5
Diving into VS 2015 Day5Diving into VS 2015 Day5
Diving into VS 2015 Day5
Akhil Mittal
 
How to Load JS Function in Menu Item Click in Odoo 17
How to Load JS Function in Menu Item Click in Odoo 17How to Load JS Function in Menu Item Click in Odoo 17
How to Load JS Function in Menu Item Click in Odoo 17
Celine George
 
Java căn bản - Chapter8
Java căn bản - Chapter8Java căn bản - Chapter8
Java căn bản - Chapter8
Vince Vo
 
Chapter 8 - Exceptions and Assertions Edit summary
Chapter 8 - Exceptions and Assertions  Edit summaryChapter 8 - Exceptions and Assertions  Edit summary
Chapter 8 - Exceptions and Assertions Edit summary
Eduardo Bergavera
 
Tips On Trick Odoo Add-On.pptx
Tips On Trick Odoo Add-On.pptxTips On Trick Odoo Add-On.pptx
Tips On Trick Odoo Add-On.pptx
Agusto Sipahutar
 
Rhino Mocks
Rhino MocksRhino Mocks
Rhino Mocks
Anand Kumar Rajana
 
Lecture 20-21
Lecture 20-21Lecture 20-21
Lecture 20-21
talha ijaz
 
How to Create User Notification in Odoo 17
How to Create User Notification in Odoo 17How to Create User Notification in Odoo 17
How to Create User Notification in Odoo 17
Celine George
 
Tony Vitabile .Net Portfolio
Tony Vitabile .Net PortfolioTony Vitabile .Net Portfolio
Tony Vitabile .Net Portfolio
vitabile
 
How to Empty a One2Many Field in Odoo 17
How to Empty a One2Many Field in Odoo 17How to Empty a One2Many Field in Odoo 17
How to Empty a One2Many Field in Odoo 17
Celine George
 
How To Open The Form View Of Many2many Clicking Tag In Odoo 18
How To Open The Form View Of Many2many Clicking Tag In Odoo 18How To Open The Form View Of Many2many Clicking Tag In Odoo 18
How To Open The Form View Of Many2many Clicking Tag In Odoo 18
Celine George
 
44CON London 2015 - How to drive a malware analyst crazy
44CON London 2015 - How to drive a malware analyst crazy44CON London 2015 - How to drive a malware analyst crazy
44CON London 2015 - How to drive a malware analyst crazy
44CON
 
How to drive a malware analyst crazy
How to drive a malware analyst crazyHow to drive a malware analyst crazy
How to drive a malware analyst crazy
Michael Boman
 
Secure mvc application saineshwar
Secure mvc application   saineshwarSecure mvc application   saineshwar
Secure mvc application saineshwar
Saineshwar bageri
 
How to Use JS Class in Form Views in Odoo 17 - Odoo 17 Slides
How to Use JS Class in Form Views in Odoo 17 - Odoo 17 SlidesHow to Use JS Class in Form Views in Odoo 17 - Odoo 17 Slides
How to Use JS Class in Form Views in Odoo 17 - Odoo 17 Slides
Celine George
 
How to modify_create components control buttons in Pos odoo.pptx
How to modify_create components control buttons in Pos odoo.pptxHow to modify_create components control buttons in Pos odoo.pptx
How to modify_create components control buttons in Pos odoo.pptx
Celine George
 
Wheels
WheelsWheels
Wheels
guest9fd0a95
 
Connecting your Python App to OpenERP through OOOP
Connecting your Python App to OpenERP through OOOPConnecting your Python App to OpenERP through OOOP
Connecting your Python App to OpenERP through OOOP
raimonesteve
 
Debugging - Figuring it out yourself (WordCamp Dublin 2019)
Debugging - Figuring it out yourself (WordCamp Dublin 2019)Debugging - Figuring it out yourself (WordCamp Dublin 2019)
Debugging - Figuring it out yourself (WordCamp Dublin 2019)
Damien Carbery
 
How to make a component and add it to systray in Odoo
How to make a component and add it to systray in OdooHow to make a component and add it to systray in Odoo
How to make a component and add it to systray in Odoo
Celine George
 
Diving into VS 2015 Day5
Diving into VS 2015 Day5Diving into VS 2015 Day5
Diving into VS 2015 Day5
Akhil Mittal
 
How to Load JS Function in Menu Item Click in Odoo 17
How to Load JS Function in Menu Item Click in Odoo 17How to Load JS Function in Menu Item Click in Odoo 17
How to Load JS Function in Menu Item Click in Odoo 17
Celine George
 
Java căn bản - Chapter8
Java căn bản - Chapter8Java căn bản - Chapter8
Java căn bản - Chapter8
Vince Vo
 
Chapter 8 - Exceptions and Assertions Edit summary
Chapter 8 - Exceptions and Assertions  Edit summaryChapter 8 - Exceptions and Assertions  Edit summary
Chapter 8 - Exceptions and Assertions Edit summary
Eduardo Bergavera
 
Tips On Trick Odoo Add-On.pptx
Tips On Trick Odoo Add-On.pptxTips On Trick Odoo Add-On.pptx
Tips On Trick Odoo Add-On.pptx
Agusto Sipahutar
 
How to Create User Notification in Odoo 17
How to Create User Notification in Odoo 17How to Create User Notification in Odoo 17
How to Create User Notification in Odoo 17
Celine George
 
Tony Vitabile .Net Portfolio
Tony Vitabile .Net PortfolioTony Vitabile .Net Portfolio
Tony Vitabile .Net Portfolio
vitabile
 
How to Empty a One2Many Field in Odoo 17
How to Empty a One2Many Field in Odoo 17How to Empty a One2Many Field in Odoo 17
How to Empty a One2Many Field in Odoo 17
Celine George
 
How To Open The Form View Of Many2many Clicking Tag In Odoo 18
How To Open The Form View Of Many2many Clicking Tag In Odoo 18How To Open The Form View Of Many2many Clicking Tag In Odoo 18
How To Open The Form View Of Many2many Clicking Tag In Odoo 18
Celine George
 
44CON London 2015 - How to drive a malware analyst crazy
44CON London 2015 - How to drive a malware analyst crazy44CON London 2015 - How to drive a malware analyst crazy
44CON London 2015 - How to drive a malware analyst crazy
44CON
 
How to drive a malware analyst crazy
How to drive a malware analyst crazyHow to drive a malware analyst crazy
How to drive a malware analyst crazy
Michael Boman
 
Secure mvc application saineshwar
Secure mvc application   saineshwarSecure mvc application   saineshwar
Secure mvc application saineshwar
Saineshwar bageri
 
How to Use JS Class in Form Views in Odoo 17 - Odoo 17 Slides
How to Use JS Class in Form Views in Odoo 17 - Odoo 17 SlidesHow to Use JS Class in Form Views in Odoo 17 - Odoo 17 Slides
How to Use JS Class in Form Views in Odoo 17 - Odoo 17 Slides
Celine George
 
How to modify_create components control buttons in Pos odoo.pptx
How to modify_create components control buttons in Pos odoo.pptxHow to modify_create components control buttons in Pos odoo.pptx
How to modify_create components control buttons in Pos odoo.pptx
Celine George
 
Connecting your Python App to OpenERP through OOOP
Connecting your Python App to OpenERP through OOOPConnecting your Python App to OpenERP through OOOP
Connecting your Python App to OpenERP through OOOP
raimonesteve
 
Debugging - Figuring it out yourself (WordCamp Dublin 2019)
Debugging - Figuring it out yourself (WordCamp Dublin 2019)Debugging - Figuring it out yourself (WordCamp Dublin 2019)
Debugging - Figuring it out yourself (WordCamp Dublin 2019)
Damien Carbery
 

More from Celine George (20)

Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18
Celine George
 
How to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 SalesHow to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 Sales
Celine George
 
How to Add Customer Note in Odoo 18 POS - Odoo Slides
How to Add Customer Note in Odoo 18 POS - Odoo SlidesHow to Add Customer Note in Odoo 18 POS - Odoo Slides
How to Add Customer Note in Odoo 18 POS - Odoo Slides
Celine George
 
How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18
Celine George
 
Link your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRMLink your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRM
Celine George
 
How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18
Celine George
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
How to Manage a Customer Account in Odoo 17 Sales
How to Manage a Customer Account in Odoo 17 SalesHow to Manage a Customer Account in Odoo 17 Sales
How to Manage a Customer Account in Odoo 17 Sales
Celine George
 
How to Open a Wizard When Clicking on the Kanban Tile in Odoo 18
How to Open a Wizard When Clicking on the Kanban Tile in Odoo 18How to Open a Wizard When Clicking on the Kanban Tile in Odoo 18
How to Open a Wizard When Clicking on the Kanban Tile in Odoo 18
Celine George
 
Ledger Posting in odoo Continental Accounting
Ledger Posting in odoo Continental AccountingLedger Posting in odoo Continental Accounting
Ledger Posting in odoo Continental Accounting
Celine George
 
How to Create & Manage a New User Menu in Odoo 18
How to Create & Manage a New User Menu in Odoo 18How to Create & Manage a New User Menu in Odoo 18
How to Create & Manage a New User Menu in Odoo 18
Celine George
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18
Celine George
 
How to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 SalesHow to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 Sales
Celine George
 
How to Add Customer Note in Odoo 18 POS - Odoo Slides
How to Add Customer Note in Odoo 18 POS - Odoo SlidesHow to Add Customer Note in Odoo 18 POS - Odoo Slides
How to Add Customer Note in Odoo 18 POS - Odoo Slides
Celine George
 
How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18How to Create A Todo List In Todo of Odoo 18
How to Create A Todo List In Todo of Odoo 18
Celine George
 
Link your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRMLink your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRM
Celine George
 
How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18
Celine George
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...Multi-currency in odoo accounting and Update exchange rates automatically in ...
Multi-currency in odoo accounting and Update exchange rates automatically in ...
Celine George
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
How to Manage a Customer Account in Odoo 17 Sales
How to Manage a Customer Account in Odoo 17 SalesHow to Manage a Customer Account in Odoo 17 Sales
How to Manage a Customer Account in Odoo 17 Sales
Celine George
 
How to Open a Wizard When Clicking on the Kanban Tile in Odoo 18
How to Open a Wizard When Clicking on the Kanban Tile in Odoo 18How to Open a Wizard When Clicking on the Kanban Tile in Odoo 18
How to Open a Wizard When Clicking on the Kanban Tile in Odoo 18
Celine George
 
Ledger Posting in odoo Continental Accounting
Ledger Posting in odoo Continental AccountingLedger Posting in odoo Continental Accounting
Ledger Posting in odoo Continental Accounting
Celine George
 
How to Create & Manage a New User Menu in Odoo 18
How to Create & Manage a New User Menu in Odoo 18How to Create & Manage a New User Menu in Odoo 18
How to Create & Manage a New User Menu in Odoo 18
Celine George
 
Ad

Recently uploaded (20)

Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Ad

Errors and exceptions in Odoo 18 - Odoo Slides

  • 1. Errors and exceptions in Odoo 18 Enterprise
  • 2. Enterprise Introduction In Odoo 18, there are many kinds of errors and exceptions possible while running the module or code under development. Error management in Odoo 18 involves understanding how the system handles exceptions and bugs, as well as employing good practices to manage and resolve them effectively. Odoo 18 have the common and standard exceptions like Attribute Error, Value Error, Type Error, Validation Error, etc
  • 3. Enterprise 1.ValidationError At any time, we can raise an exception in Odoo using the ValidationError based on any condition we need to set. For example, we can just set a Validation error for the stock.picking model if the field partner_id , ie ‘Receive From’ is not filled using the code. from odoo import models from odoo.exceptions import ValidationError class StockPicking(models.Model): _inherit = 'stock.picking' def button_validate(self): result = super(StockPicking, self).button_validate() if not self.partner_id: raise ValidationError('Fill in the field "Receive From"') return result
  • 4. Enterprise While trying to validate the picking without filing the ‘Receive From’ field, it shows like
  • 5. Enterprise 2.UserError User Errors can also be raised with the needed constraints or conditions with which the system undergoes checks for every record. Import UserError from odoo.exceptions and we can just replace the previous code as below to demonstrate the workflow. from odoo import models from odoo.exceptions import UserError class StockPicking(models.Model): _inherit = 'stock.picking' def button_validate(self): result = super(StockPicking, self).button_validate() if not self.partner_id: raise UserError('Fill in the field "Receive From"') return result
  • 6. Enterprise And in the UI, whenever the condition is true, the exception will pop up like
  • 7. Enterprise 3.AccessError This exception is used when the user tries to login to the Odoo instance with invalid login details. First, we need to import AccessError as from odoo.exceptions import AccessError Now, let’s write a simple python code to block all the users other than Admin from accessing a document. if not self.env.is_admin(): raise AccessError(_("Sorry, you are not allowed to access this document."))
  • 8. Enterprise 4.MissingError These Missing Errors are used in Odoo 18 usually when the user tries to access any record or data that is not actually available in the database of the instance. It may have either been deleted/ removed or doesn’t exist at all. For the previous code, let’s try to access any record with a random ID, say 1000 as def button_validate(self): result = super(StockPicking, self).button_validate() print(self.browse(1000).name) return result
  • 9. Enterprise Here, the stock.picking(1000,) is a non existing record and hence, while clicking on the Validate button, it will pop up the Odoo 18’s inbuilt exception as
  • 10. Enterprise We can add our own Missing Error exception first by importing it from odoo.exceptions. from odoo.exceptions import MissingError And then by raising it as below. raise MissingError('Missing Error Demo')
  • 11. Enterprise 5.Access Denied Access Denied exception in the case when a user tries to perform any kind of action or operation for which he/she is not allowed to do due to the restriction in the access rights. from odoo import models from odoo.exceptions import AccessDenied class StockPicking(models.Model): _inherit = 'stock.picking' def button_validate(self): if not self.env.is_admin(): raise AccessDenied("You are not allowed to validate the Operation") return super(StockPicking, self).button_validate()
  • 12. Enterprise Here, for any user other than Admin, the right to validate the stock movement will be denied. Let us login to the system as any other internal user with no Admin access and try to validate the picking. The error will come like
  • 13. Enterprise 6.CacheMiss This error is raised by Odoo in case when a record or a data is not found. Odoo usually caches data about the record that is accessed recently for some time. This CacheMiss occurs when the needed record is not found in the cache. It can be caused due to high traffic or the memory limits allowed. country = self.env['res.country].browse(1) print(country.name) Here, in the first line, the ‘country’ variable is having a value. Odoo fetches it from the database and stores it in the cache. And in the second line, ‘country.name’ is printed. During this time, Odoo will return it from cache without requiring to run a database query again as in the first line. In case if it is not found in the cache, CacheMiss exception will pop up.
  • 14. Enterprise 7. RedirectWarning This error is raised to redirect the workflow to a particular page instead of giving any warning to the user. Redirect Warning can be useful to suggest an alternate flow that should be followed, such as confirming an operation or redirecting to a form view before continuing with the original action. The necessary parameters for RedirectWarning are action_id: It is the id of the action were to perform the redirection message: It is the message for exception button_text: It is the text to put on the button that will trigger the redirection
  • 15. Enterprise With our previous example of validating a picking, let’s rewrite the code to implement Redirect Warning for demonstration as from odoo import _, models from odoo.exceptions import RedirectWarning class StockPicking(models.Model): _inherit = 'stock.picking' def button_validate(self): warehouse_action = self.env.ref('stock.action_warehouse_form') msg = _('Please create a warehouse for company %s.', self.env.company.display_name) raise RedirectWarning(msg, warehouse_action.id, _('Go to Warehouses')) return super(StockPicking, self).button_validate()
  • 16. Enterprise Here, while validating the picking, the system will generate a Redirect Warning with a message on the body and two buttons named ‘Go to Warehouses’ and ‘Close’.
  • 17. Enterprise While clicking on the ‘Go to Warehouses’ button, we get the page
  • 18. For More Info. Check our company website for related blogs and Odoo book. Check our YouTube channel for functional and technical videos in Odoo. Enterprise www.cybrosys.com