[FIX] stock: don't check 'scrap' move when validating picking

Steps to reproduce the bug:
- Create a storable product “P1”.
- Update its quantity to 10.
- Create a delivery picking:
    - Add the product “P1” with 10 units.
    - Mark as to do.
    - Scrap 1 quantity of “P1”.
- Try to validate the picking.

Problem:
A wizard asking to create a backorder is triggered. This occurs because
the move of the scrap is created, linked to the picking, and marked as
'done' (so, picked). Therefore, when validating the picking, we will
checks if all the moves are picked (Even if not picked, it will
work because we'll set them all to 'picked'). but as the first move is
not picked and the scrap one is picked, the backorder wizard is raised.

**opw-3821869**

closes odoo/odoo#163395

Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
Djamel Touati
2024-04-26 17:18:03 +00:00
parent 5f017682c1
commit fb16a3411e
2 changed files with 40 additions and 0 deletions
+2
View File
@@ -1179,6 +1179,8 @@ class Picking(models.Model):
has_quantity = False
has_pick = False
for move in picking.move_ids:
if move.scrapped:
continue
if move.picked:
has_pick = True
if move.quantity:
+38
View File
@@ -4972,6 +4972,44 @@ class StockMove(TransactionCase):
self.assertEqual(self.env['stock.quant']._get_available_quantity(product01, self.stock_location), 1)
self.assertEqual(self.env['stock.quant']._get_available_quantity(product02, self.stock_location), 1)
def test_scrap_9_with_delivery(self):
"""
Scrap the product of a reserved move line and check that the picking can
correctly mark as done after the scrap.
"""
# 10 units are available in stock
self.env['stock.quant']._update_available_quantity(self.product, self.stock_location, 10)
picking = self.env['stock.picking'].create({
'name': 'A single picking with one move to scrap',
'location_id': self.stock_location.id,
'location_dest_id': self.customer_location.id,
'picking_type_id': self.env.ref('stock.picking_type_out').id,
})
move1 = self.env['stock.move'].create({
'name': 'A move to confirm and scrap its product',
'location_id': self.stock_location.id,
'location_dest_id': self.customer_location.id,
'product_id': self.product.id,
'product_uom_qty': 9.0,
'picking_id': picking.id,
})
move1._action_confirm()
move1._action_assign()
self.assertEqual(move1.quantity, 9)
# scrap a unit
scrap = self.env['stock.scrap'].create({
'product_id': self.product.id,
'product_uom_id': self.product.uom_id.id,
'scrap_qty': 1,
'picking_id': picking.id,
})
scrap.action_validate()
self.assertEqual(scrap.state, 'done')
picking.button_validate()
self.assertEqual(picking.state, 'done')
def test_in_date_1(self):
""" Check that moving a tracked quant keeps the incoming date.
"""