Ir al contenido
Menú
Se marcó esta pregunta

I need to get  products of sale order which product_uom_qty does not match qty_delivered but the stock.picking of this product should be validated by clicking on validate button as shown in the following screen:

Is the delivery button shown only when the sale order be in the sale state?
and how can i do the condition which to know that the Validating of stock.picking is done of this product?
I did the following code but i want to know how can i add the above condition

def action_print_errors(self):
sales = self.env['sale.order'].search([('state','=','sale')])

# Convert sales variable to a list of dictionaries
sales_list = []
for sale in sales:
sale_dict = {
'id': sale.id,
'name': sale.name,
'order_line': []
}
for line in sale["order_line"]:
line_dict = {
'id': line.id,
'product_id': line.product_id.id,
'product_name': line.product_id.name,
'product_uom_quantity':line.product_id.product_uom_quantity,
'qty_delivered':line.product_id.qty_delivered,
'different':line.product_id.product_uom_quantity-line.product_id.qty_delivered

}
if line_dict['product_uom_quantity'] !=line_dict['qty_delivered']:
sale_dict['order_line'].append(line_dict)
sales_list.append(sale_dict)

I need to make sure that the product stock picking is validated

Avatar
Descartar
Mejor respuesta

Hi,

To retrieve the products of a sale order where the `product_uom_qty` does not match `qty_delivered` after validating the associated stock picking, you can modify the code as follows:

def action_print_errors(self):
sales = self.env['sale.order'].search([('state', '=', 'sale')])
sales_list = []
for sale in sales:
sale_dict = {
'id': sale.id,
'name': sale.name,
'order_line': [],
}
for line in sale.order_line:
line_dict = {
'id': line.id,
'product_id': line.product_id.id,
'product_name': line.product_id.name,
'product_uom_quantity': line.product_uom_qty,
'qty_delivered': line.qty_delivered,
'different': line.product_uom_qty - line.qty_delivered
}
# Check if stock picking is validated for this product
stock_picking = self.env['stock.picking'].search([
('sale_id', '=', sale.id),
('state', '=', 'done'),
('product_id', '=', line.product_id.id)
], limit=1)
if stock_picking and line_dict['product_uom_quantity'] != line_dict['qty_delivered']:
sale_dict['order_line'].append(line_dict)
sales_list.append(sale_dict)

In this updated code, we perform an additional check to validate the associated stock picking for each product within the sale order. We use the `search()` method on the `stock.picking` model to find a validated stock picking with the following criteria:

- `sale_id` matches the current sale order `sale.id`

- `state` is set to 'done' (validated)

- `product_id` matches the current product `line.product_id.id`

If a validated stock picking is found for a product and the `product_uom_qty` does not match `qty_delivered`, we add the product details to the `order_line` list within the `sale_dict`.

Now, the `sales_list` will contain the sale orders and their respective products where the `product_uom_qty` does not match `qty_delivered` after validating the associated stock picking

Regards

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
nov 23
2335
3
jul 25
4531
1
abr 24
1780
0
ago 23
1421
2
may 25
3815