Odoo Help


Create pos.order.line with unit_price according to pricelist_id and product_id

Julian Hammer
on 6/18/14, 6:51 PM 1,219 views

I need to implement a custom POS interface in our existing POS structure. To do so i use oerplib:

>>> order_id = oerp.create('pos.order', {'session_id': session_id, 'pricelist_id': 1})
>>> order_line_id = oerp.create('pos.order.line', {'order_id': order_id, 'product_id': 23, 'qty': 1.0})
>>> order_line = oerp.browse('pos.order.line', order_line_id)
>>> order_line.price_unit
>>> order_line

We see that the unit_price was not updated based on the pricelist_id and product_id.

Any idear how I can retrieve the product price according to the pricelist without implement the logic myself?

Julian Hammer
On 6/24/14, 11:07 AM

I found out that you need to use the onchange functions:

# Load default values
>>> oerp.execute('pos.order.line', 'default_get',
... ["product_id","price_unit","price_subtotal","price_subtotal_incl","qty","discount"])
{'discount': 0.0, 'qty': 1}

# Recalculate price if pricelist was already "asked" order price was manualy
# changed
# onchange_qty(ids, product, discount, qty, price_unit)
>>> oerp.execute('pos.order.line', 'onchange_qty', [], 700, False, 1, 23)
{'value': {'price_subtotal': 23.0, 'price_subtotal_incl': 23.0}}

# Recalculate price based on pricelist
# onchange_product_id(ids, pricelist, product_id, qty=0, partner_id=False) [calcs price]
>>> oerp.execute('pos.order.line', 'onchange_product_id', [], 1, 700, 23)
{'value': {'price_subtotal': 1.3800000000000001,
  'price_subtotal_incl': 1.3800000000000001,
  'price_unit': 0.06}}

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

1 follower(s)


Asked: 6/18/14, 6:51 PM
Seen: 1219 times
Last updated: 3/16/15, 8:10 AM