Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
3640 Visualizzazioni

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
Abbandona
Risposta migliore
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
Abbandona
Post correlati Risposte Visualizzazioni Attività
1
nov 23
2045
1
ott 23
2701
3
lug 24
5688
2
gen 24
5262
1
ago 23
1977