Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
3106 Vistas

Quiero sumar las cantidades de los productos por id o nombre, es decir si tengo 3 productos iguales en un campo one2many, cada uno con diferente cantidad y luego se agrega 2 veces otro producto con diferente cantidad, al final Quiero mostrar la cantidad total en otro campo que muestre el nombre y la cantidad total de los dos productos

Avatar
Descartar
Mejor respuesta

Hello,

First you need to define a function according to your requirement, In the function you need to get the orderlines of corresponding _order,

ie,

order_lines = self.env['sale.order.line'].search([('order_id', '=', self.id)])

now you need to get the products and corresponding quantity, for that

product = []
qty = []
for order in order_lines:
if order.product_id not in product:
product.append(order.product_id)
qty.append(order.product_uom_qty)
else:
index = product.index(order.product_id)
qty[index] += order.product_uom_qty

Here you will get each product and their qty respectively in the lists product and qty. You can add the values from the list to the needed field by looping them.

Regards

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
jul 23
4101
3
jul 24
6756
1
ago 23
2557
1
dic 22
3804
0
oct 22
2945