تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
962 أدوات العرض

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

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
أغسطس 25
294
2
يوليو 25
2746
3
يوليو 25
568
1
يونيو 25
2023
1
أبريل 25
1612