From fb16a3411e081d0d18f58222fa60c489655b7d24 Mon Sep 17 00:00:00 2001 From: Djamel Touati Date: Thu, 25 Apr 2024 17:32:39 +0200 Subject: [PATCH] [FIX] stock: don't check 'scrap' move when validating picking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- addons/stock/models/stock_picking.py | 2 ++ addons/stock/tests/test_move.py | 38 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) 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. """