[FIX] stock: packages and reservation

When the result packaged is changed on a move line, we should not change
the reservation of quants, because result_package is not related to
reservation, only package_id is used during the reservation.

We also changed the copy of move_line when we split a move line to put a
part of it in a package. By copying the move line and set the
product_uom_id in the default values of copy function, we mess the
reservation, because there is no quant reservation made for the move
line even if the move_line has a product_uom_qty. So we set the
product_uom_qty to 0 when copying the line, and then write the
product_uom_qty which will call the quant reservation

Fixes #20784
This commit is contained in:
Pierre Masereel
2017-11-24 15:34:53 +01:00
committed by Simon Lejeune
parent 72799e1f02
commit f59e96f014
2 changed files with 40 additions and 1 deletions
+3 -1
View File
@@ -811,9 +811,11 @@ class Picking(models.Model):
operation.product_uom_qty - operation.qty_done,
precision_rounding=operation.product_uom_id.rounding,
rounding_method='UP')
done_to_keep = operation.qty_done
new_operation = operation.copy(
default={'product_uom_qty': operation.qty_done, 'qty_done': operation.qty_done})
default={'product_uom_qty': 0, 'qty_done': operation.qty_done})
operation.write({'product_uom_qty': quantity_left_todo, 'qty_done': 0.0})
new_operation.write({'product_uom_qty': done_to_keep})
operation_ids |= new_operation
operation_ids.write({'result_package_id': package.id})
+37
View File
@@ -3137,3 +3137,40 @@ class StockMove(TransactionCase):
self.assertTrue(ml.move_id in picking.move_lines, 'Links are not correct between picking, moves and move lines.')
self.assertEqual(picking.state, 'done', 'Picking should still done after adding a new move line.')
self.assertTrue(all(move.state == 'done' for move in picking.move_lines), 'Wrong state for move.')
def test_put_in_pack_1(self):
""" Check that reserving a move and adding its move lines to
different packages work as expected.
"""
self.env['stock.quant']._update_available_quantity(self.product1, self.stock_location, 2)
picking = self.env['stock.picking'].create({
'location_id': self.stock_location.id,
'location_dest_id': self.customer_location.id,
'picking_type_id': self.env.ref('stock.picking_type_out').id,
})
move1 = self.env['stock.move'].create({
'name': 'test_transit_1',
'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': 2.0,
'picking_id': picking.id,
})
picking.action_confirm()
picking.action_assign()
self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0)
move1.quantity_done = 1
picking.put_in_pack()
self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0)
self.assertEqual(len(picking.move_line_ids), 2)
unpacked_ml = picking.move_line_ids.filtered(lambda ml: not ml.result_package_id)
self.assertEqual(unpacked_ml.product_qty, 1)
unpacked_ml.qty_done = 1
picking.put_in_pack()
self.assertEqual(len(picking.move_line_ids), 2)
self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0)
picking.button_validate()
self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.stock_location), 0)
self.assertEqual(self.env['stock.quant']._get_available_quantity(self.product1, self.customer_location), 2)