[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:
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user