Skip to content

Commit

Permalink
[REF]stock_auto_move: fix _transfer_pickings_with_auto_move
Browse files Browse the repository at this point in the history
  • Loading branch information
zakiuu committed Oct 12, 2017
1 parent f625b20 commit 81a2a44
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions stock_auto_move/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def _transfer_pickings_with_auto_move(self, auto_moves_by_pickings):

# Create immediate transfer wizard so it will fill the qty_done
# on the auto move linked operation
picking.do_prepare_partial()
wizard = self.env['stock.immediate.transfer'].create(
{'pick_id': picking.id})
wizard.process()
Expand Down
80 changes: 80 additions & 0 deletions stock_auto_move/tests/test_stock_auto_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class TestStockAutoMove(common.TransactionCase):
def setUp(self):
super(TestStockAutoMove, self).setUp()
self.product_a1232 = self.browse_ref("product.product_product_6")
self.product_2 = self.env.ref("product.product_product_9")
self.location_shelf = self.browse_ref(
"stock.stock_location_components")
self.location_1 = self.browse_ref("stock_auto_move.stock_location_a")
Expand Down Expand Up @@ -254,3 +255,82 @@ def test_50_partial_chained_auto_move(self):

self.assertTrue(move2.move_dest_id.auto_move)
self.assertEqual(move2.move_dest_id.state, 'done')

def test_60_partial_chained_auto_move(self):
"""
Test case:
- product with tracking set to serial.
- warehouse reception steps set to two steps.
- create picking with two move lines.
- set one of the move on the second step picking to be an auto
move.
- do partial reception on first step
Expected Result:
The second step movement should be processed automatically
and a back order is created with the product that is not set as an
auto move.
"""
warehouse = self.env.ref('stock.warehouse0')
warehouse.reception_steps = 'two_steps'
warehouse.reception_route_id.push_ids.auto_confirm = True
warehouse.int_type_id.use_create_lots = False
warehouse.int_type_id.use_existing_lots = True

picking = self.env['stock.picking'].with_context(
default_picking_type_id=warehouse.in_type_id.id).create({
'partner_id': self.env.ref('base.res_partner_1').id,
'picking_type_id': warehouse.in_type_id.id,
'group_id': self.auto_group_id,
'location_id':
self.env.ref('stock.stock_location_suppliers').id})

move1 = self.env["stock.move"].create({
'name': "Supply source location for test",
'product_id': self.product_a1232.id,
'product_uom': self.product_uom_unit_id,
'product_uom_qty': 2,
'picking_id': picking.id,
'location_id': self.env.ref('stock.stock_location_suppliers').id,
'location_dest_id': warehouse.wh_input_stock_loc_id.id,
'picking_type_id': warehouse.in_type_id.id,
})

move2 = self.env["stock.move"].create({
'name': "Supply source location for test",
'product_id': self.product_2.id,
'product_uom': self.product_uom_unit_id,
'product_uom_qty': 2,
'picking_id': picking.id,
'location_id': self.env.ref('stock.stock_location_suppliers').id,
'location_dest_id': warehouse.wh_input_stock_loc_id.id,
'picking_type_id': warehouse.in_type_id.id,
})

picking.action_confirm()
self.assertTrue(move1.move_dest_id.auto_move)
self.assertTrue(move2.move_dest_id.auto_move)
second_step_picking = move2.move_dest_id.picking_id
move2.move_dest_id.auto_move = False

# do partial reception of the first picking
move1.linked_move_operation_ids.operation_id.qty_done = 2
move1.linked_move_operation_ids.operation_id.product_qty = 2

move2.linked_move_operation_ids.operation_id.qty_done = 1
move2.linked_move_operation_ids.operation_id.product_qty = 1

picking.do_transfer()

second_step_back_order = self.env['stock.picking'].search(
[('backorder_id', '=', second_step_picking.id)])

print second_step_back_order.move_lines.read(['state', 'auto_move'])
self.assertEqual(second_step_picking.state, 'done')
self.assertEqual(len(second_step_picking.move_lines), 1)
self.assertEqual(len(second_step_picking.pack_operation_ids), 1)

self.assertEqual(len(second_step_back_order.move_lines), 2)
self.assertTrue(second_step_back_order.move_lines.filtered(
lambda m: m.state == 'assigned'))
self.assertTrue(second_step_back_order.move_lines.filtered(
lambda m: m.state == 'waiting'))

0 comments on commit 81a2a44

Please sign in to comment.