'Put a pack in pack'

def test_40_pack_in_pack(self):

    picking_out = self.PickingObj.create({'partner_id': self.partner_agrolite_id, 'picking_type_id': self.picking_type_out, 'location_id': self.pack_location, 'location_dest_id': self.customer_location})
    move_out = self.MoveObj.create({'name': self.productA.name, 'product_id': self.productA.id, 'product_uom_qty': 3, 'product_uom': self.productA.uom_id.id, 'picking_id': picking_out.id, 'location_id': self.pack_location, 'location_dest_id': self.customer_location})
    picking_pack = self.PickingObj.create({'partner_id': self.partner_agrolite_id, 'picking_type_id': self.picking_type_out, 'location_id': self.stock_location, 'location_dest_id': self.pack_location})
    move_pack = self.MoveObj.create({'name': self.productA.name, 'product_id': self.productA.id, 'product_uom_qty': 3, 'product_uom': self.productA.uom_id.id, 'picking_id': picking_pack.id, 'location_id': self.stock_location, 'location_dest_id': self.pack_location, 'move_dest_id': move_out.id})
    picking_in = self.PickingObj.create({'partner_id': self.partner_delta_id, 'picking_type_id': self.picking_type_in, 'location_id': self.supplier_location, 'location_dest_id': self.stock_location})
    move_in = self.MoveObj.create({'name': self.productA.name, 'product_id': self.productA.id, 'product_uom_qty': 3, 'product_uom': self.productA.uom_id.id, 'picking_id': picking_in.id, 'location_id': self.supplier_location, 'location_dest_id': self.stock_location, 'move_dest_id': move_pack.id})
    for move in picking_in.move_lines:
        self.assertEqual(move.state, 'draft', 'Wrong    state    of    move    line.')
    picking_in.action_confirm()
    for move in picking_in.move_lines:
        self.assertEqual(move.state, 'assigned', 'Wrong    state    of    move    line.')
    for move in picking_pack.move_lines:
        self.assertEqual(move.state, 'draft', 'Wrong    state    of    move    line.')
    picking_pack.action_confirm()
    for move in picking_pack.move_lines:
        self.assertEqual(move.state, 'waiting', 'Wrong    state    of    move    line.')
    for move in picking_out.move_lines:
        self.assertEqual(move.state, 'draft', 'Wrong    state    of    move    line.')
    picking_out.action_confirm()
    for move in picking_out.move_lines:
        self.assertEqual(move.state, 'waiting', 'Wrong    state    of    move    line.')
    picking_in.pack_operation_product_ids.qty_done = 3.0
    picking_in.put_in_pack()
    picking_in_package = picking_in.pack_operation_ids.result_package_id
    picking_in.do_new_transfer()
    for move in picking_in.move_lines:
        self.assertEqual(move.state, 'done', 'Wrong    state    of    move    line.')
    for move in picking_pack.move_lines:
        self.assertEqual(move.state, 'assigned', 'Wrong    state    of    move    line.')
    for pack in picking_pack.pack_operation_pack_ids:
        pack.is_done = True
        pack.on_change_is_done()
    picking_pack.put_in_pack()
    picking_pack_package = picking_pack.pack_operation_ids.result_package_id
    picking_pack.do_new_transfer()
    for move in picking_pack.move_lines:
        self.assertEqual(move.state, 'done', 'Wrong    state    of    move    line.')
    for move in picking_out.move_lines:
        self.assertEqual(move.state, 'assigned', 'Wrong    state    of    move    line.')
    for pack in picking_out.pack_operation_pack_ids:
        pack.is_done = True
        pack.on_change_is_done()
    picking_out.do_new_transfer()
    for move in picking_in.move_lines:
        self.assertEqual(move.state, 'done', 'Wrong    state    of    move    line.')
    for move in picking_pack.move_lines:
        self.assertEqual(move.state, 'done', 'Wrong    state    of    move    line.')
    for move in picking_out.move_lines:
        self.assertEqual(move.state, 'done', 'Wrong    state    of    move    line.')
    self.assertEqual(picking_in_package.parent_id.id, picking_pack_package.id, 'The    package    created    in    the    picking    in    is    not    in    the    one    created    in    picking    pack')
    self.assertEqual(picking_pack_package.location_id.id, self.customer_location, 'The    package    created    in    picking    pack    is    not    in    the    customer    location')
    self.assertEqual(picking_in_package.location_id.id, self.customer_location, 'The    package    created    in    picking    in    is    not    in    the    customer    location')
    quant = self.StockQuantObj.search([('location_id', '=', self.customer_location), ('product_id', '=', self.productA.id)])
    self.assertTrue(quant.id, 'There    is    no    quant    in    customer    location    for    productA')
    self.assertEqual(quant.qty, 3.0, 'The    quant    in    customer    location    for    productA    has    not    a    quantity    of    3.0')
    self.assertEqual(quant.package_id.id, picking_in_package.id, 'The    quant    in    customer    location    is    not    in    its    package    created    in    picking    in')
