diff --git a/addons/stock/models/stock_picking.py b/addons/stock/models/stock_picking.py index ad3095ff09c..1fb6afeda6a 100644 --- a/addons/stock/models/stock_picking.py +++ b/addons/stock/models/stock_picking.py @@ -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: diff --git a/addons/stock/tests/test_move.py b/addons/stock/tests/test_move.py index aba2ac51af8..e8c2aea6e84 100644 --- a/addons/stock/tests/test_move.py +++ b/addons/stock/tests/test_move.py @@ -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. """