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

Sales - add constraint on "Confirm Sales" button

Subscribe

Get notified when there's activity on this post

This question has been flagged
salessale.order.lineodooV8odoo8.0odoo8
6 Replies
8059 Views
Avatar
Salim Rahal

I need to forbid the user from confirming a sales order (action occurred when clicking on confirm sale button: Sales-> Sales Order-> choose an order). So I override the action that confirm the Sales, and add a condition which raise a validation Error, so the super wont be called in case an invalid condition(e.g. order line with product without names).
But the issue occured in S.O. - Edit mode and  when clicking on confirm SO an insert to the database(insert in sale_order_line) is executed before executing the following overwritten function.

//the inherited class
class sales_warning(models.Model):
    _inherit = "sale.order"
@api.multi  
def action_button_confirm(self):
    print "begin overwritten action_button_confirm()"
     if(ForbidCondition==True):
              raise ValidationError("You cannot confirm a S.O...")
    else:
    res = super(sales_warning, self).action_button_confirm()       
return res
Logs showing the write operation before invoking the overwritten function:
crm werkzeug: .. "POST /web/dataset/call_kw/sale.order/write HTTP/1.1" 200 begin overwritten action_button_confirm()


Question: is there a way to add a constraint the will be launched before any other action such as the write above?

thank you

0
Avatar
Discard
Avatar
Salim Rahal
Author Best Answer

Since the error (i.e. calling the write function when confirming the SO in edit mode) occurs only in Edit mode, note that in read only mode and when saving the SO the write wont be called (seems Odoo consider nothing to be updated in Sales order line-read only mode), so I choose to hide the confirm button in edit mode by adding oe_read_only css class to the button:


<xpath expr="//button[@name='action_button_confirm']" position="attributes">          
          <attribute name="class">oe_read_only</attribute>            
 </xpath>


In Brief:


-SO (Sale order) in read only mode: confirm button is visible and Won't do an update (update sale_order_line) to DB once it's clicked, only the action action_button_confirm is called
-SO in Edit mode: Hide the button of confirmation in order to prevent updating the sale_order_line

0
Avatar
Discard
Avatar
Qutechs, Ahmed M.Elmubarak
Best Answer

Hi,

In Odoo, when you press any button it'll invoke the write function "to save the changes" then calling the desired button's function.

So it'll depends on your requirement:

1. Overriding the writing method.

2. Add a constrains function, by adding the decorator @api.constrains to your method ... so you'll be sure that this function will be called before any CRUD operation ...


Hope this could helps ...

0
Avatar
Discard
Salim Rahal
Author

I tried the @constraints but it will be called on all action on SO recordset: confirm sales, save action and on duplicate So. But I need only to handle the confirm sales action, since I don't want to forbid create a SO with invalid product names, only forbid the confirm SO. Also I tried to send a param from the button to the constraints in order to handle this specific case but it I doesn't works. I couldn't find the write method it in sale.py, Seems that the write couldn't be overridden, I didnt found the function that handle it in sale.py, I found only the create(): called on first save. 10x

Qutechs, Ahmed M.Elmubarak

If I got you, you can just override the confirmation function and raise warning if some condition is true, then the record will be saved but not going to be confirmed. Also you can use @api.onchange to raise some warnings or set values to null if you'd like to validate the user input ...

Qutechs, Ahmed M.Elmubarak

Also the create function will be called when the record is new; the write function will be called when the record is to update. If you don't find the write function in the model it will be inherited from the parent model. You can simply override it same as the create method !

Salim Rahal
Author

Dear Ahmad, I don't want to let user confirm SO with invalid product name I need to check them before save, and in the same time I will let them save the SO but without confirm. I will try to override the write() in the parent

Salim Rahal
Author

Dear Ahmad, check my answer and if you find it useful click on up narrow please

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
Error "account.analytic.account()" when invoicing
sales invoicing odooV8 odoo8.0 odoo8
Avatar
0
Dec 18
3367
How to pass product_ids from old sales order to new sales order. Solved
sales sale.order.line sale.order odooV8 odoo8.0
Avatar
Avatar
2
Jul 16
5680
High Availability Odoo 8.0 on Windows
odooV8 odoo8.0 odoo8
Avatar
0
Feb 21
4535
Product received Administrator in Odoo 8 purchase module
odooV8 odoo8.0 odoo8
Avatar
0
Feb 18
3273
blockUI requires jQuery v1.2.3 or later! You are using v1.11.1 error when installing Odoo 8 on Windows 10
odooV8 odoo8.0 odoo8
Avatar
Avatar
Avatar
3
Jun 17
6634
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