Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
3740 มุมมอง

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

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
พ.ย. 23
2164
1
ต.ค. 23
2785
3
ก.ค. 24
6039
Merge Same Item in Sale Order Line แก้ไขแล้ว
2
ม.ค. 24
5379
1
ส.ค. 23
2062