[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) <whe@odoo.com>
This commit is contained in:
Adrien Widart
2022-02-16 14:02:14 +00:00
parent b9019878ea
commit 05261f12c2
2 changed files with 41 additions and 1 deletions
+1 -1
View File
@@ -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
+40
View File
@@ -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)