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?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- 客戶關係
- e-Commerce
- 會計
- 庫存
- PoS
- 專案管理
- MRP
此問題已被標幟
How to get product prices via JSON API in Odoo
The usual approach is:
- Use the product.pricelist to get pricelist IDs.
- Use the product.product to get product IDs.
- 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
8月 25
|
1446 | ||
|
|
1
8月 25
|
1818 | ||
|
|
2
7月 25
|
4771 | ||
|
|
3
7月 25
|
1927 | ||
|
|
1
6月 25
|
3819 |
This is just what I needed. Thank you!
Not any method to get price from api as it is only private functions.