summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorPierre Masereel <pim@odoo.com>2017-11-20 11:33:44 +0100
committerSimon Lejeune <sle@openerp.com>2017-11-24 15:34:53 +0100
commitf59e96f0147a3ce90ee56e5390feb9bcbc57b806 (patch)
tree454cfa212be2fddd58aec5ba4036af7ca9987aba /addons
parent72799e1f02282978a770473362bff2202961cf19 (diff)
[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
Diffstat (limited to 'addons')
-rw-r--r--addons/stock/models/stock_picking.py4
-rw-r--r--addons/stock/tests/test_move.py37
2 files changed, 40 insertions, 1 deletions
diff --git a/addons/stock/models/stock_picking.py b/addons/stock/models/stock_picking.py
index 9ca3ab06561..44b0958f47e 100644
--- a/addons/stock/models/stock_picking.py
+++ b/addons/stock/models/stock_picking.py
@@ -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})
diff --git a/addons/stock/tests/test_move.py b/addons/stock/tests/test_move.py
index aa6adaf1778..9fd8088ca38 100644
--- a/addons/stock/tests/test_move.py
+++ b/addons/stock/tests/test_move.py
@@ -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)
+