From 81cac7b2d322bf72ae93e254509371d398d898ce Mon Sep 17 00:00:00 2001 From: Mathieu Walravens Date: Tue, 26 Mar 2024 18:02:48 +0100 Subject: [PATCH] [FIX] stock: allow changing scrap location with done moves Before this commit: Modifying a location from/to a scrap location should be restricted when there are move lines with reservation. However, starting from Odoo 17, the quantity field indicates the reserved quantity only when the move line's state is different from done. After this commit: Only check if there are reservation lines (move lines not in done) in the location when changing from/to a scrap location to match the behaviour before Odoo 17. opw-3815275 closes odoo/odoo#159376 Signed-off-by: Quentin Wolfs (quwo) --- addons/stock/models/stock_location.py | 1 + addons/stock/tests/test_robustness.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/addons/stock/models/stock_location.py b/addons/stock/models/stock_location.py index 4609ef5090f..98dd1a537dd 100644 --- a/addons/stock/models/stock_location.py +++ b/addons/stock/models/stock_location.py @@ -207,6 +207,7 @@ class Location(models.Model): for f in {'usage', 'scrap_location'})) reserved_quantities = self.env['stock.move.line'].search_count([ ('location_id', 'in', modified_locations.ids), + ('state', 'not in', ['done', 'cancel']), ('quantity_product_uom', '>', 0), ]) if reserved_quantities: diff --git a/addons/stock/tests/test_robustness.py b/addons/stock/tests/test_robustness.py index 6ec205a5251..c5cf619544d 100644 --- a/addons/stock/tests/test_robustness.py +++ b/addons/stock/tests/test_robustness.py @@ -97,6 +97,21 @@ class TestRobustness(TransactionCase): move1._action_confirm() move1._action_assign() self.assertEqual(move1.state, 'assigned') + + move2 = self.env['stock.move'].create({ + 'name': 'test_location_archive', + 'location_id': test_stock_location.id, + 'location_dest_id': self.customer_location.id, + 'product_id': self.product1.id, + 'product_uom': self.uom_unit.id, + 'product_uom_qty': 1, + }) + move2._action_confirm() + move2._action_assign() + move2.picked = True + move2._action_done() + self.assertEqual(move2.state, 'done') + quant = self.env['stock.quant']._gather( self.product1, test_stock_location, @@ -113,6 +128,7 @@ class TestRobustness(TransactionCase): # unreserve move1._do_unreserve() + test_stock_location.scrap_location = False def test_package_unpack(self): """ Unpack a package that contains quants with a reservation