From 05261f12c253d49ea7af2caff75ab7c3f7f48d1b Mon Sep 17 00:00:00 2001 From: Adrien Widart Date: Tue, 15 Feb 2022 13:31:35 +0000 Subject: [PATCH] [FIX] stock: compute the source location of package level When performing a picking with a package, the source location of the package level may become incorrect To reproduce the issue: (Use demo data) 1. In Settings, enable: - Packages - Storage Locations 2. In Operations Types, edit "Internal Transfers": - Enable "Move Entire Packages" 3. Create a storable product P 4. Create a receipt R with for P 5. Put 10 P in pack and validate R - Let be PK the package generated/used 6. Process an internal transfer with PK - The destination location of the package level is WH/Stock/Shelf 1 Error: Once the picking is validated, the source location of the package level is "WH/Stock/Shelf 1". This is not true, it should still be "WH/Stock" The compute method is incorrect. It uses the package location to define the source location of the package level. However, once the picking is processed, this package has moved so using its location to define the source location doesn't make sense anymore. OPW-2754179 closes odoo/odoo#84709 X-original-commit: 239898ed699d98ff185f6a18fc5a8529e126cecb Signed-off-by: William Henrotin (whe) --- addons/stock/models/stock_package_level.py | 2 +- addons/stock/tests/test_packing.py | 40 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/addons/stock/models/stock_package_level.py b/addons/stock/models/stock_package_level.py index 7d701d1c9e1..a95b9c9cd02 100644 --- a/addons/stock/models/stock_package_level.py +++ b/addons/stock/models/stock_package_level.py @@ -168,7 +168,7 @@ class StockPackageLevel(models.Model): for pl in self: if pl.state == 'new' or pl.is_fresh_package: pl.location_id = False - elif pl.package_id: + elif pl.state != 'done' and pl.package_id: pl.location_id = pl.package_id.location_id elif pl.state == 'confirmed' and pl.move_ids: pl.location_id = pl.move_ids[0].location_id diff --git a/addons/stock/tests/test_packing.py b/addons/stock/tests/test_packing.py index e8f8f2b99c3..ee6dc10869f 100644 --- a/addons/stock/tests/test_packing.py +++ b/addons/stock/tests/test_packing.py @@ -889,3 +889,43 @@ class TestPacking(TestPackingCommon): self.assertNotIn(packB, picking.package_level_ids) self.assertEqual(packB, bo.package_level_ids) self.assertEqual(bo.package_level_ids.state, 'assigned') + + def test_package_and_sub_location(self): + """ + Suppose there are some products P available in shelf1, a child location of the pack location. + When moving these P to another child location of pack location, the source location of the + related package level should be shelf1 + """ + shelf1_location = self.env['stock.location'].create({ + 'name': 'shelf1', + 'usage': 'internal', + 'location_id': self.pack_location.id, + }) + shelf2_location = self.env['stock.location'].create({ + 'name': 'shelf2', + 'usage': 'internal', + 'location_id': self.pack_location.id, + }) + + pack = self.env['stock.quant.package'].create({'name': 'Super Package'}) + self.env['stock.quant']._update_available_quantity(self.productA, shelf1_location, 20.0, package_id=pack) + + picking = self.env['stock.picking'].create({ + 'picking_type_id': self.warehouse.in_type_id.id, + 'location_id': self.pack_location.id, + 'location_dest_id': shelf2_location.id, + }) + package_level = self.env['stock.package_level'].create({ + 'package_id': pack.id, + 'picking_id': picking.id, + 'location_dest_id': picking.location_dest_id.id, + 'company_id': picking.company_id.id, + }) + + self.assertEqual(package_level.location_id, shelf1_location) + + picking.action_confirm() + package_level.is_done = True + picking.button_validate() + + self.assertEqual(package_level.location_id, shelf1_location)