Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
3780 Weergaven

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.

Avatar
Annuleer
Beste antwoord
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

Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
1
nov. 23
2228
1
okt. 23
2826
3
jul. 24
6119
2
jan. 24
5446
1
aug. 23
2125