跳至內容
選單
此問題已被標幟
1 回覆
3979 瀏覽次數

Hello, I've seen multiple posts where it's answered how to get OnHand quantity on a  warehouse  within python code, but I want to know how to get it using the External API, can you give me a hint?

Thanks

頭像
捨棄
作者

@Cybrosys how would i call that from the external API? external API uses RPC, but afaik this adds an endpoint to be consumed with HTTP 

最佳答案

Hi,

Please try the following code.

@http.route('/stock', auth='user')
def stock(self, **kw):
product = request.env['product.template'].search([('id', '=', kw['product_id'])])
warehouse = request.env['stock.warehouse'].search([])
stock = []
for variant in products.product_variant_ids:
"""Looping through the product variants"""
wh_qty = {}
for j in warehouse:
wh_qty[j.name] = variant.with_context(
{'warehouse': j.id}).qty_available
"""Getting the qty from the current warehouse"""
item = {
'size': variant.attribute_value_ids.name,
'total': variant.qty_available,
}
for k in wh_qty:
item[k] = wh_qty[k]
stock.append(item)
return Response(json.dumps(stock))
Regards


頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
2
1月 23
3454
0
3月 22
1570
1
7月 21
2749
1
3月 21
3783
1
12月 20
2248