[FIX] stock: inconsistent state after unpack.

Usecase to reproduce:
- Update quantity in stock with a product inside a package
- Reserve a picking with this package.
- Go on the package form view and unpack it.
The package does not exist anymore on the quant, the reserved move line
still having the package as source package.

When the user try to unreserve the move lines, it will try to unrerserve
a quant with this package that does not exist anymore and then return
the error message 'can not unreserve more than you have in stock'.

This commit removes the source package on move lines that contain the
unpacked pack.
This commit is contained in:
Arnold Moyaux
2018-06-26 13:16:52 +02:00
parent bd5ca8c612
commit 52f323545a
2 changed files with 44 additions and 0 deletions
+6
View File
@@ -459,6 +459,12 @@ class QuantPackage(models.Model):
if move_lines_to_remove:
move_lines_to_remove.write({'result_package_id': False})
else:
move_line_to_modify = self.env['stock.move.line'].search([
('package_id', '=', package.id),
('state', 'in', ('assigned', 'partially_available')),
('product_qty', '!=', 0),
])
move_line_to_modify.write({'package_id': False})
package.mapped('quant_ids').write({'package_id': False})
def action_view_picking(self):
+38
View File
@@ -107,3 +107,41 @@ class TestRobustness(TransactionCase):
# unreserve
move1._do_unreserve()
def test_package_unpack(self):
""" Unpack a package that contains quants with a reservation
should also remove the package on the reserved move lines.
"""
package = self.env['stock.quant.package'].create({
'name': 'Shell Helix HX7 10W30',
})
self.env['stock.quant']._update_available_quantity(
self.product1,
self.stock_location,
10,
package_id=package
)
# reserve a dozen
move1 = self.env['stock.move'].create({
'name': 'test_uom_rounding',
'location_id': self.stock_location.id,
'location_dest_id': self.customer_location.id,
'product_id': self.product1.id,
'product_uom': self.uom_unit.id,
'product_uom_qty': 10,
})
move1._action_confirm()
move1._action_assign()
move1.result_package_id = False
package.unpack()
# unreserve
move1._do_unreserve()
self.assertEqual(len(self.env['stock.quant']._gather(self.product1, self.stock_location)), 1)
self.assertEqual(len(self.env['stock.quant']._gather(self.product1, self.stock_location, package_id=package)), 0)
self.assertEqual(self.env['stock.quant']._gather(self.product1, self.stock_location).reserved_quantity, 0)