Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
1076 Переглядів

I can retrieve product.pricelist, but this returns only the price lists. How do I get to the actual products and their price level prices?

Аватар
Відмінити
Автор

This is just what I needed. Thank you!

Найкраща відповідь
How to get product prices via JSON API in Odoo

The usual approach is:

  1. Use the product.pricelist to get pricelist IDs.
  2. Use the product.product to get product IDs.
  3. Call a method on the pricelist to compute the price for each product.
Key Odoo method to compute prices

product.pricelist model has a method named:

_get_product_price_rule(product, qty, partner)

or more generally:

get_product_price(product_id, quantity=1.0, partner=None)

which returns the computed price for the product in that pricelist.


Via JSON API (RPC) you can do this:

You can call the get_product_price method on product.pricelist records, passing the product ID and quantity.

Example JSON-RPC call to get product prices

Step 1 : Get pricelist IDs

{
  "jsonrpc": "2.0",
  "method": "call",
  "params": {
    "model": "product.pricelist",
    "method": "search",
    "args": [[["active", "=", true]]],
    "kwargs": {}
  },
  "id": 1
}

Step 2 : Get product IDs

{
  "jsonrpc": "2.0",
  "method": "call",
  "params": {
    "model": "product.product",
    "method": "search",
    "args": [[["sale_ok", "=", true]]],
    "kwargs": {"limit": 10}
  },
  "id": 2
}

Step 3 : Call pricelist method to get price for product

{
  "jsonrpc": "2.0",
  "method": "call",
  "params": {
    "model": "product.pricelist",
    "method": "get_product_price",
    "args": [
      [pricelist_id], // list of pricelist ids (typically 1)
      product_id, // id of the product
      1.0, // quantity
      false // no partner context for now
    ],
    "kwargs": {}
  },
  "id": 3
}

This returns the computed price for the product in the pricelist.


Python example calling from XML-RPC
price = models.execute_kw(db, uid, password,
    'product.pricelist', 'get_product_price',
    [[pricelist_id], product_id, 1.0, False])
print(price)


Thanks & Regards,

Email: contact@datainteger.com

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
0
серп. 25
127
1
серп. 25
495
2
лип. 25
2945
3
лип. 25
699
1
черв. 25
2180