Skip to content

Commit

Permalink
[FIX] stock: don't check 'scrap' move when validating picking
Browse files Browse the repository at this point in the history
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#163395

Signed-off-by: William Henrotin (whe) <whe@odoo.com>
  • Loading branch information
DjamelTouati committed Apr 26, 2024
1 parent 5f01768 commit fb16a34
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions addons/stock/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,8 @@ def _pre_action_done_hook(self):
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:
Expand Down
38 changes: 38 additions & 0 deletions addons/stock/tests/test_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -4972,6 +4972,44 @@ def test_scrap_8(self):
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.
"""
Expand Down

0 comments on commit fb16a34

Please sign in to comment.