This question has been flagged
1 Reply
3948 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
0.0
>>> order_line
.product_id.list_price
1.0

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?

Avatar
Discard
Author Best Answer

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}}

Avatar
Discard