Odoo Help


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

Christian Parent
on 5/8/14, 1:18 PM 1,061 views

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]
        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)

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 5/8/14, 1:18 PM
Seen: 1061 times
Last updated: 3/16/15, 8:10 AM