Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Raise validation error is blocking the flow

Subscribe

Get notified when there's activity on this post

This question has been flagged
insertflowvalidateerrorraiseblock
4 Replies
16771 Views
Avatar
nagarjuna

inside create method i have an if condition. in the condition i am performing some insertion. code is not giving any error but record is not inserting into the db, due to the last line raise validation error. if remove that and give return something then the record is inserting into db. how to avoid this ?

def create(self, cr, uid, vals, context=None):

reserve_item_id = vals['reserve_item_id' 

result = self.pool.get('item.item').browse(cr, uid, reserve_item_id)  

item_count = result.item_count

if result.item_count - result.reserve_count == 0:

vals={}

vals['mail_user_id']=uid

vals['mail_item_id']=reserve_item_id

vals['status']=False

cr.execute("INSERT INTO email_email (mail_user_id,mail_item_id) VALUES (%s, %s)", (uid, reserve_item_id))

raise ValidationError("No Item available")

0
Avatar
Discard
nagarjuna
Author

Hi Pavan, my issues resolved after using curson.commit(). Thank you

Avatar
Pawan
Best Answer

Nagarjuna,

After your cr.execute() statement, you can call "cr.commit()", that will save your record in the database, and let your exception call.

One more thing, inspite your record will be created in the database with the values you are inserting, but its better if you pass odoos default field values also, as create function didn't called successfully, these values will not be inserted.[create_uid, create_date, write_date, write_uid.]

Hope it helps


1
Avatar
Discard
Avatar
nagarjuna
Author Best Answer

Hi Yenthe,


Thanks for the reply, i have as like below

from openerp.modules.registry import RegistryManager

newcr = RegistryManager.get(cr.dbname).cursor()

self.pool.get('email.email').create(cr, uid, vals, context=context)

newcr.close()

still i am facing same issue, can you please help on this

0
Avatar
Discard
Yenthe Van Ginneken (Mainframe Monkey)

If I'm not mistaking the problem is that you're using self.ppol.get which is still not using your new cursor. Your new record is still created with the default cursor? Do your cr.execute with new new cursor (newcr)

Avatar
Yenthe Van Ginneken (Mainframe Monkey)
Best Answer

Hi Nagarjuna,

The simple answer is you can't with the way you're trying to. When Odoo runs through this function it will start checking things, you then do your cr.execute which works fine but the moment it hits your ValidationError it will do a roll-back. The default behaviour by Odoo is to do a transactional rollback when there is a ValidationError.
You could however avoid this by creating a separate transaction. Transactions are bound to cursors so you need to get a new cursor to the current database, something along the lines of:

newcr = RegistryManager.get(cr.dbname).cursor() 

With the new cursor you can do your transaction and then the ValidationError won't do a rollback since it is a separate cursor. (Don't forget to open and close that cursor).

Yenthe

0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
"Unauthorized or invalid company access error" trying to validate an Activity (17.4)
validateerror
Avatar
0
Oct 24
2461
ERROR DE VALIDACION
validateerror
Avatar
0
Sep 23
2936
Input needed for best flow Corporate entertainment company
flow
Avatar
0
Feb 23
2138
Link in Validation Error
validateerror
Avatar
Avatar
1
Nov 21
2915
Can not validate any orders or invoices that's created by other users (the users was created by admin user) on Odoo 9.0c?
validateerror
Avatar
Avatar
7
May 18
5120
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now