コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
3727 ビュー

I want to add the quantities of the products by id or name, that is, if I have 3 equal products in a one2many field, each one with a different quantity and then another product with a different quantity is added 2 times, at the end I want to show the total quantity in another field showing the name and total quantity of the two products.

アバター
破棄
最善の回答
product_qty = {}
for line in order.order_line: # assuming "order" is the parent record with a one2many field "order_line"
if line.product_id.id in product_qty:
product_qty[line.product_id.id] += line.product_uom_qty
else:
product_qty[line.product_id.id] = line.product_uom_qty

# Now, product_qty dictionary will contain product IDs as keys and their respective quantities as values

アバター
破棄
関連投稿 返信 ビュー 活動
1
11月 23
2159
1
10月 23
2784
3
7月 24
6029
2
1月 24
5377
1
8月 23
2058