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

Purchase module, unit price reset on change of qty or uom. What needs to be changed in on_change function ?

Subscribe

Get notified when there's activity on this post

This question has been flagged
purchasefunctionv8price
1 Reply
10592 Views
Avatar
Christian Parent

When creating a purchase order, if you happen to change the price first then quantity or unit of measure after, the price will reset back to what it was before you changeg it (default price or 0.0). It have something to do with the onchange_product_id function but, cannot figure out what exactly creates this.

here is the code of the function (with non relevent code removed) :

def onchange_product_id(self, cr, uid, ids, pricelist_id, product_id, qty, uom_id,
        partner_id, date_order=False, fiscal_position_id=False, date_planned=False,
        name=False, price_unit=False, context=None):

    if context is None:
        context = {}

    res = {'value': {'price_unit': price_unit or 0.0, 'name': name or '', 'product_uom' : uom_id or False}}
    if not product_id:
        return res

    product_product = self.pool.get('product.product')
    product_uom = self.pool.get('product.uom')
    product_pricelist = self.pool.get('product.pricelist')

 ....

    if pricelist_id:
        price = product_pricelist.price_get(cr, uid, [pricelist_id],
                product.id, qty or 1.0, partner_id or False, {'uom': uom_id, 'date': date_order})[pricelist_id]
    else:
        price = product.standard_price

....

    res['value'].update({'price_unit': price, 'taxes_id': taxes_ids})

    return res

product_id_change = onchange_product_id
product_uom_change = onchange_product_uom

What cause that behavior and how to modify it to keep the price entered by the user at any time ? (This has been like that since at least V.6)

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

Hello,

the price changed by this code:

# - determine price_unit and taxes_id
    if pricelist_id:
        price = product_pricelist.price_get(cr, uid, [pricelist_id],
                product.id, qty or 1.0, partner_id or False, {'uom': uom_id, 'date': date_order})[pricelist_id]
    else:
        price = product.standard_price

it'll check the price list for the product or set it to the standard one. So if you need the price entered by the user never changed you have to overwrite this function to don't use the price variable in the line "before the return res":

res['value'].update({'price_unit': price, 'taxes_id': taxes_ids})

Update

you can add

if price_unit:
         price = price_unit

after the if - else condition ...

note: this is simple solution, in case the user doesn't change the price and then he changed the uom, there will be no automatic converting to the price ! so you'll need more work here.

I hope this could helps..

Regards...

0
Avatar
Discard
Christian Parent
Author

I did had tried that change, it did not worked.

It had something to do with the declaration price_unit=False in the signature. I have moved price_unit before the date_order=False, in the signature so it did not need to be initiated, did the changes in form view too. It works. Not for the the onchange_product_uom function which calls the onchange_product_id function in its return. Did the same changes in same order (in signature) but, getting a string instead of int error.... Looking at it now !

Qutechs, Ahmed M.Elmubarak

there is no something to to with price_unit=False it just a default value, you've to don't interrupt the order of the signature. I have tried my change before I post this answer and it worked! I hope if you can return the function as it is original one with that change and try it...

Christian Parent
Author

When using:

res['value'].update({'price_unit': price_unit, 'taxes_id': taxes_ids})

If I change the quantity afterwards or the unit of measure, the price returns to 0.00$.

I have changed everything back to original, I had already tried your solution before and it was behaving that way. I will also retry the price = price_unit and see but as I remember, it was also setting it back to 0.00$

Qutechs, Ahmed M.Elmubarak

I've updated the answer, if you still get the 0.00 , please check the order of the params in the xml view you can check the price_unit value by printing it to server and then try to change the qty.

Qutechs, Ahmed M.Elmubarak

hey man, I didn't notice that you're tagging V8, this may not work with you cause I checked it with V7 I'm so sorry for that...

Christian Parent
Author

No prob, I have a production server which runs 6.0.x, will try your solution on it. For 8, I have set everything back to normal, re-moved price_unit in the signature of only onchange_product_id fonction so it does not need to be initiated to false, and made the appropriated changes in the xml also and it works as intended for both, onchange_product_id and onchange_product_uom. Looks like the signature sets it to 0 (false) no mather what the call pass as argument.

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
Purchase module, unit price reset on change of qty or uom. What needs to be changed in on_change function ?
purchase function v8 price
Avatar
0
Mar 15
4696
Purchase module, unit price reset on change of qty or uom. What needs to be changed in on_change function ?
purchase function v8 price
Avatar
0
Mar 15
4706
Adding custom field in Sale order line to show values into Purchase order line
purchase sales function
Avatar
Avatar
Avatar
Avatar
3
Aug 25
2460
Why does the purchase order allow products where Can be Purchased is false?
purchase v8 product
Avatar
Avatar
1
Nov 24
4773
Price not updated when new value is written from purchase order
purchase price purchase_order
Avatar
Avatar
1
Sep 23
7284
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