'Picking transfer with diffrent unit of meassure.'

def test_10_pickings_transfer_with_different_uom(self):

    picking_in_A = 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})
    self.MoveObj.create({'name': self.DozA.name, 'product_id': self.DozA.id, 'product_uom_qty': 10, 'product_uom': self.DozA.uom_id.id, 'picking_id': picking_in_A.id, 'location_id': self.supplier_location, 'location_dest_id': self.stock_location})
    self.MoveObj.create({'name': self.SDozA.name, 'product_id': self.SDozA.id, 'product_uom_qty': 10.5, 'product_uom': self.SDozA.uom_id.id, 'picking_id': picking_in_A.id, 'location_id': self.supplier_location, 'location_dest_id': self.stock_location})
    self.MoveObj.create({'name': self.SDozARound.name, 'product_id': self.SDozARound.id, 'product_uom_qty': 10.5, 'product_uom': self.SDozARound.uom_id.id, 'picking_id': picking_in_A.id, 'location_id': self.supplier_location, 'location_dest_id': self.stock_location})
    self.MoveObj.create({'name': self.kgB.name, 'product_id': self.kgB.id, 'product_uom_qty': 0.02, 'product_uom': self.kgB.uom_id.id, 'picking_id': picking_in_A.id, 'location_id': self.supplier_location, 'location_dest_id': self.stock_location})
    self.MoveObj.create({'name': self.gB.name, 'product_id': self.gB.id, 'product_uom_qty': 525.3, 'product_uom': self.gB.uom_id.id, 'picking_id': picking_in_A.id, 'location_id': self.supplier_location, 'location_dest_id': self.stock_location})
    for move in picking_in_A.move_lines:
        self.assertEqual(move.state, 'draft', 'Move    state    must    be    draft.')
    picking_in_A.action_confirm()
    for move in picking_in_A.move_lines:
        self.assertEqual(move.state, 'assigned', 'Move    state    must    be    draft.')
    picking_in_A.do_prepare_partial()
    PackSdozAround = self.StockPackObj.search([('product_id', '=', self.SDozARound.id), ('picking_id', '=', picking_in_A.id)], limit=1)
    self.assertEqual(PackSdozAround.product_qty, 11, ('Wrong    quantity    in    pack    operation    (%s    found    instead    of    11)' % PackSdozAround.product_qty))
    picking_in_A.do_transfer()
    quants = self.StockQuantObj.search([('product_id', '=', self.DozA.id), ('location_id', '=', self.stock_location)])
    total_qty = [quant.qty for quant in quants]
    self.assertEqual(sum(total_qty), 10, ('Expecting    10    Dozen    ,    got    %.4f    Dozen    on    location    stock!' % sum(total_qty)))
    self.assertEqual(self.DozA.qty_available, 10, ('Wrong    quantity    available    (%s    found    instead    of    10)' % self.DozA.qty_available))
    quants = self.StockQuantObj.search([('product_id', '=', self.SDozA.id), ('location_id', '=', self.stock_location)])
    total_qty = [quant.qty for quant in quants]
    self.assertEqual(sum(total_qty), 10.5, ('Expecting    10.5    SDozen    ,    got    %.4f    SDozen    on    location    stock!' % sum(total_qty)))
    self.assertEqual(self.SDozA.qty_available, 10.5, ('Wrong    quantity    available    (%s    found    instead    of    10.5)' % self.SDozA.qty_available))
    quants = self.StockQuantObj.search([('product_id', '=', self.SDozARound.id), ('location_id', '=', self.stock_location)])
    total_qty = [quant.qty for quant in quants]
    self.assertEqual(sum(total_qty), 11, ('Expecting    11    SDozenRound    ,    got    %.4f    SDozenRound    on    location    stock!' % sum(total_qty)))
    self.assertEqual(self.SDozARound.qty_available, 11, ('Wrong    quantity    available    (%s    found    instead    of    11)' % self.SDozARound.qty_available))
    quants = self.StockQuantObj.search([('product_id', '=', self.gB.id), ('location_id', '=', self.stock_location)])
    total_qty = [quant.qty for quant in quants]
    self.assertEqual(sum(total_qty), 525.3, ('Expecting    525.3    gram    ,    got    %.4f    gram    on    location    stock!' % sum(total_qty)))
    self.assertEqual(self.gB.qty_available, 525.3, ('Wrong    quantity    available    (%s    found    instead    of    525.3' % self.gB.qty_available))
    quants = self.StockQuantObj.search([('product_id', '=', self.kgB.id), ('location_id', '=', self.stock_location)])
    total_qty = [quant.qty for quant in quants]
    self.assertEqual(sum(total_qty), 0.02, ('Expecting    0.020    kg    ,    got    %.4f    kg    on    location    stock!' % sum(total_qty)))
    self.assertEqual(self.kgB.qty_available, 0.02, ('Wrong    quantity    available    (%s    found    instead    of    0.020)' % self.kgB.qty_available))
    picking_in_B = 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})
    self.MoveObj.create({'name': self.DozA.name, 'product_id': self.DozA.id, 'product_uom_qty': 120, 'product_uom': self.uom_unit.id, 'picking_id': picking_in_B.id, 'location_id': self.supplier_location, 'location_dest_id': self.stock_location})
    self.MoveObj.create({'name': self.SDozA.name, 'product_id': self.SDozA.id, 'product_uom_qty': 1512, 'product_uom': self.uom_unit.id, 'picking_id': picking_in_B.id, 'location_id': self.supplier_location, 'location_dest_id': self.stock_location})
    self.MoveObj.create({'name': self.SDozARound.name, 'product_id': self.SDozARound.id, 'product_uom_qty': 1584, 'product_uom': self.uom_unit.id, 'picking_id': picking_in_B.id, 'location_id': self.supplier_location, 'location_dest_id': self.stock_location})
    self.MoveObj.create({'name': self.kgB.name, 'product_id': self.kgB.id, 'product_uom_qty': 20.0, 'product_uom': self.uom_gm.id, 'picking_id': picking_in_B.id, 'location_id': self.supplier_location, 'location_dest_id': self.stock_location})
    self.MoveObj.create({'name': self.gB.name, 'product_id': self.gB.id, 'product_uom_qty': 0.525, 'product_uom': self.uom_kg.id, 'picking_id': picking_in_B.id, 'location_id': self.supplier_location, 'location_dest_id': self.stock_location})
    for move in picking_in_B.move_lines:
        self.assertEqual(move.state, 'draft', 'Wrong    state    of    move    line.')
    picking_in_B.action_confirm()
    for move in picking_in_B.move_lines:
        self.assertEqual(move.state, 'assigned', 'Wrong    state    of    move    line.')
    picking_in_B.do_prepare_partial()
    PackdozA = self.StockPackObj.search([('product_id', '=', self.DozA.id), ('picking_id', '=', picking_in_B.id)], limit=1)
    self.assertEqual(PackdozA.product_qty, 120, ('Wrong    quantity    in    pack    operation    (%s    found    instead    of    120)' % PackdozA.product_qty))
    self.assertEqual(PackdozA.product_uom_id.id, self.uom_unit.id, 'Wrong    uom    in    pack    operation    for    product    DozA.')
    PackSdozA = self.StockPackObj.search([('product_id', '=', self.SDozA.id), ('picking_id', '=', picking_in_B.id)], limit=1)
    self.assertEqual(PackSdozA.product_qty, 1512, ('Wrong    quantity    in    pack    operation    (%s    found    instead    of    1512)' % PackSdozA.product_qty))
    self.assertEqual(PackSdozA.product_uom_id.id, self.uom_unit.id, 'Wrong    uom    in    pack    operation    for    product    SDozA.')
    PackSdozAround = self.StockPackObj.search([('product_id', '=', self.SDozARound.id), ('picking_id', '=', picking_in_B.id)], limit=1)
    self.assertEqual(PackSdozAround.product_qty, 1584, ('Wrong    quantity    in    pack    operation    (%s    found    instead    of    1584)' % PackSdozAround.product_qty))
    self.assertEqual(PackSdozAround.product_uom_id.id, self.uom_unit.id, 'Wrong    uom    in    pack    operation    for    product    SDozARound.')
    packgB = self.StockPackObj.search([('product_id', '=', self.gB.id), ('picking_id', '=', picking_in_B.id)], limit=1)
    self.assertEqual(packgB.product_qty, 525, ('Wrong    quantity    in    pack    operation    (%s    found    instead    of    525)' % packgB.product_qty))
    self.assertEqual(packgB.product_uom_id.id, self.uom_gm.id, 'Wrong    uom    in    pack    operation    for    product    gB.')
    packkgB = self.StockPackObj.search([('product_id', '=', self.kgB.id), ('picking_id', '=', picking_in_B.id)], limit=1)
    self.assertEqual(packkgB.product_qty, 20.0, ('Wrong    quantity    in    pack    operation    (%s    found    instead    of    20)' % packkgB.product_qty))
    self.assertEqual(packkgB.product_uom_id.id, self.uom_gm.id, 'Wrong    uom    in    pack    operation    for    product    kgB')
    self.StockPackObj.search([('product_id', '=', self.kgB.id), ('picking_id', '=', picking_in_B.id)]).write({'product_qty': 0.02, 'product_uom_id': self.uom_kg.id})
    self.StockPackObj.search([('product_id', '=', self.gB.id), ('picking_id', '=', picking_in_B.id)]).write({'product_qty': 525.3, 'product_uom_id': self.uom_gm.id})
    self.StockPackObj.search([('product_id', '=', self.DozA.id), ('picking_id', '=', picking_in_B.id)]).write({'product_qty': 4, 'product_uom_id': self.uom_dozen.id})
    self.StockPackObj.create({'product_id': self.DozA.id, 'product_qty': 48, 'product_uom_id': self.uom_unit.id, 'location_id': self.supplier_location, 'location_dest_id': self.stock_location, 'picking_id': picking_in_B.id})
    picking_in_B.do_transfer()
    self.assertEqual(picking_in_B.state, 'done', 'Incoming    shipment    state    should    be    done.')
    for move in picking_in_B.move_lines:
        self.assertEqual(move.state, 'done', 'Wrong    state    of    move    line.')
    self.assertEqual(len(picking_in_B.move_lines), 6, 'Wrong    number    of    move    lines')
    moves_DozA = self.MoveObj.search([('product_id', '=', self.DozA.id), ('picking_id', '=', picking_in_B.id)], limit=1)
    self.assertEqual(moves_DozA.product_uom_qty, 96, ('Wrong    move    quantity    (%s    found    instead    of    96)' % moves_DozA.product_uom_qty))
    self.assertEqual(moves_DozA.product_uom.id, self.uom_unit.id, 'Wrong    uom    in    move    for    product    DozA.')
    moves_SDozA = self.MoveObj.search([('product_id', '=', self.SDozA.id), ('picking_id', '=', picking_in_B.id)], limit=1)
    self.assertEqual(moves_SDozA.product_uom_qty, 1512, ('Wrong    move    quantity    (%s    found    instead    of    1512)' % moves_SDozA.product_uom_qty))
    self.assertEqual(moves_SDozA.product_uom.id, self.uom_unit.id, 'Wrong    uom    in    move    for    product    SDozA.')
    moves_SDozARound = self.MoveObj.search([('product_id', '=', self.SDozARound.id), ('picking_id', '=', picking_in_B.id)], limit=1)
    self.assertEqual(moves_SDozARound.product_uom_qty, 1584, ('Wrong    move    quantity    (%s    found    instead    of    1584)' % moves_SDozARound.product_uom_qty))
    self.assertEqual(moves_SDozARound.product_uom.id, self.uom_unit.id, 'Wrong    uom    in    move    for    product    SDozARound.')
    moves_kgB = self.MoveObj.search([('product_id', '=', self.kgB.id), ('picking_id', '=', picking_in_B.id)], limit=1)
    self.assertEqual(moves_kgB.product_uom_qty, 20, ('Wrong    quantity    in    move    (%s    found    instead    of    20)' % moves_kgB.product_uom_qty))
    self.assertEqual(moves_kgB.product_uom.id, self.uom_gm.id, 'Wrong    uom    in    move    for    product    kgB.')
    moves_gB_kg = self.MoveObj.search([('product_id', '=', self.gB.id), ('picking_id', '=', picking_in_B.id), ('product_uom', '=', self.uom_kg.id)], limit=1)
    self.assertEqual(moves_gB_kg.product_uom_qty, 0.525, ('Wrong    move    quantity    (%s    found    instead    of    0.525)' % moves_gB_kg.product_uom_qty))
    self.assertEqual(moves_gB_kg.product_uom.id, self.uom_kg.id, 'Wrong    uom    in    move    for    product    gB.')
    moves_gB_g = self.MoveObj.search([('product_id', '=', self.gB.id), ('picking_id', '=', picking_in_B.id), ('product_uom', '=', self.uom_gm.id)], limit=1)
    self.assertEqual(moves_gB_g.product_uom_qty, 0.3, ('Wrong    move    quantity    (%s    found    instead    of    0.3)' % moves_gB_g.product_uom_qty))
    self.assertEqual(moves_gB_g.product_uom.id, self.uom_gm.id, 'Wrong    uom    in    move    for    product    gB.')
    bo_in_B = self.PickingObj.search([('backorder_id', '=', picking_in_B.id)])
    self.assertEqual(len(bo_in_B), 1, 'Back    order    should    be    created.')
    self.assertEqual(len(bo_in_B.move_lines), 1, 'Wrong    number    of    move    lines')
    moves_DozA = self.MoveObj.search([('product_id', '=', self.DozA.id), ('picking_id', '=', bo_in_B.id)], limit=1)
    self.assertEqual(moves_DozA.product_uom_qty, 24.0, ('Wrong    move    quantity    (%s    found    instead    of    0.525)' % moves_DozA.product_uom_qty))
    self.assertEqual(moves_DozA.product_uom.id, self.uom_unit.id, 'Wrong    uom    in    move    for    product    DozA.')
    quants = self.StockQuantObj.search([('product_id', '=', self.DozA.id), ('location_id', '=', self.stock_location)])
    total_qty = [quant.qty for quant in quants]
    self.assertEqual(sum(total_qty), 18, ('Expecting    18    Dozen    ,    got    %.4f    Dozen    on    location    stock!' % sum(total_qty)))
    self.assertEqual(self.DozA.qty_available, 18, ('Wrong    quantity    available    (%s    found    instead    of    18)' % self.DozA.qty_available))
    quants = self.StockQuantObj.search([('product_id', '=', self.SDozA.id), ('location_id', '=', self.stock_location)])
    total_qty = [quant.qty for quant in quants]
    self.assertEqual(sum(total_qty), 21, ('Expecting    18    SDozen    ,    got    %.4f    SDozen    on    location    stock!' % sum(total_qty)))
    self.assertEqual(self.SDozA.qty_available, 21, ('Wrong    quantity    available    (%s    found    instead    of    21)' % self.SDozA.qty_available))
    quants = self.StockQuantObj.search([('product_id', '=', self.SDozARound.id), ('location_id', '=', self.stock_location)])
    total_qty = [quant.qty for quant in quants]
    self.assertEqual(sum(total_qty), 22, ('Expecting    22    SDozenRound    ,    got    %.4f    SDozenRound    on    location    stock!' % sum(total_qty)))
    self.assertEqual(self.SDozARound.qty_available, 22, ('Wrong    quantity    available    (%s    found    instead    of    22)' % self.SDozARound.qty_available))
    quants = self.StockQuantObj.search([('product_id', '=', self.gB.id), ('location_id', '=', self.stock_location)])
    total_qty = [quant.qty for quant in quants]
    self.assertEqual(sum(total_qty), 1050.6, ('Expecting    1050.6    Gram    ,    got    %.4f    Gram    on    location    stock!' % sum(total_qty)))
    self.assertEqual(self.gB.qty_available, 1050.6, ('Wrong    quantity    available    (%s    found    instead    of    1050.6)' % self.gB.qty_available))
    quants = self.StockQuantObj.search([('product_id', '=', self.kgB.id), ('location_id', '=', self.stock_location)])
    total_qty = [quant.qty for quant in quants]
    self.assertEqual(sum(total_qty), 0.04, ('Expecting    0.040    kg    ,    got    %.4f    kg    on    location    stock!' % sum(total_qty)))
    self.assertEqual(self.kgB.qty_available, 0.04, ('Wrong    quantity    available    (%s    found    instead    of    0.040)' % self.kgB.qty_available))
    before_out_quantity = self.kgB.qty_available
    picking_out = 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.customer_location})
    self.MoveObj.create({'name': self.kgB.name, 'product_id': self.kgB.id, 'product_uom_qty': 0.966, 'product_uom': self.uom_gm.id, 'picking_id': picking_out.id, 'location_id': self.stock_location, 'location_dest_id': self.customer_location})
    self.MoveObj.create({'name': self.kgB.name, 'product_id': self.kgB.id, 'product_uom_qty': 0.034, 'product_uom': self.uom_gm.id, 'picking_id': picking_out.id, 'location_id': self.stock_location, 'location_dest_id': self.customer_location})
    picking_out.action_confirm()
    picking_out.action_assign()
    picking_out.do_prepare_partial()
    picking_out.do_transfer()
    quantity_diff = (before_out_quantity - self.kgB.qty_available)
    self.assertEqual(float_round(quantity_diff, precision_rounding=0.0001), 0.001, 'Wrong    quantity    diffrence.')
    self.assertEqual(self.kgB.qty_available, 0.039, ('Wrong    quantity    available    (%s    found    instead    of    0.039)' % self.kgB.qty_available))
    picking_out = 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.customer_location})
    self.MoveObj.create({'name': self.DozA.name, 'product_id': self.DozA.id, 'product_uom_qty': 54, 'product_uom': self.uom_unit.id, 'picking_id': picking_out.id, 'location_id': self.stock_location, 'location_dest_id': self.customer_location})
    self.MoveObj.create({'name': self.SDozA.name, 'product_id': self.SDozA.id, 'product_uom_qty': 288, 'product_uom': self.uom_unit.id, 'picking_id': picking_out.id, 'location_id': self.stock_location, 'location_dest_id': self.customer_location})
    self.MoveObj.create({'name': self.SDozARound.name, 'product_id': self.SDozARound.id, 'product_uom_qty': 360, 'product_uom': self.uom_unit.id, 'picking_id': picking_out.id, 'location_id': self.stock_location, 'location_dest_id': self.customer_location})
    self.MoveObj.create({'name': self.gB.name, 'product_id': self.gB.id, 'product_uom_qty': 0.503, 'product_uom': self.uom_kg.id, 'picking_id': picking_out.id, 'location_id': self.stock_location, 'location_dest_id': self.customer_location})
    self.MoveObj.create({'name': self.kgB.name, 'product_id': self.kgB.id, 'product_uom_qty': 20, 'product_uom': self.uom_gm.id, 'picking_id': picking_out.id, 'location_id': self.stock_location, 'location_dest_id': self.customer_location})
    picking_out.action_confirm()
    for move in picking_out.move_lines:
        self.assertEqual(move.state, 'confirmed', 'Wrong    state    of    move    line.')
    picking_out.action_assign()
    for move in picking_out.move_lines:
        self.assertEqual(move.state, 'assigned', 'Wrong    state    of    move    line.')
    DozA_qty = self.MoveObj.search([('product_id', '=', self.DozA.id), ('picking_id', '=', picking_out.id)], limit=1).reserved_availability
    self.assertEqual(DozA_qty, 4.5, ('Wrong    move    quantity    availability    (%s    found    instead    of    4.5)' % DozA_qty))
    SDozA_qty = self.MoveObj.search([('product_id', '=', self.SDozA.id), ('picking_id', '=', picking_out.id)], limit=1).reserved_availability
    self.assertEqual(SDozA_qty, 2, ('Wrong    move    quantity    availability    (%s    found    instead    of    2)' % SDozA_qty))
    SDozARound_qty = self.MoveObj.search([('product_id', '=', self.SDozARound.id), ('picking_id', '=', picking_out.id)], limit=1).reserved_availability
    self.assertEqual(SDozARound_qty, 3, ('Wrong    move    quantity    availability    (%s    found    instead    of    3)' % SDozARound_qty))
    gB_qty = self.MoveObj.search([('product_id', '=', self.gB.id), ('picking_id', '=', picking_out.id)], limit=1).reserved_availability
    self.assertEqual(gB_qty, 503, ('Wrong    move    quantity    availability    (%s    found    instead    of    503)' % gB_qty))
    kgB_qty = self.MoveObj.search([('product_id', '=', self.kgB.id), ('picking_id', '=', picking_out.id)], limit=1).reserved_availability
    self.assertEqual(kgB_qty, 0.02, ('Wrong    move    quantity    availability    (%s    found    instead    of    0.020)' % kgB_qty))
    picking_out.do_prepare_partial()
    picking_out.do_transfer()
    quants = self.StockQuantObj.search([('product_id', '=', self.DozA.id), ('location_id', '=', self.stock_location)])
    total_qty = [quant.qty for quant in quants]
    self.assertEqual(sum(total_qty), 13.5, ('Expecting    13.5    Dozen    ,    got    %.4f    Dozen    on    location    stock!' % sum(total_qty)))
    self.assertEqual(self.DozA.qty_available, 13.5, ('Wrong    quantity    available    (%s    found    instead    of    13.5)' % self.DozA.qty_available))
    quants = self.StockQuantObj.search([('product_id', '=', self.SDozA.id), ('location_id', '=', self.stock_location)])
    total_qty = [quant.qty for quant in quants]
    self.assertEqual(sum(total_qty), 19, ('Expecting    19    SDozen    ,    got    %.4f    SDozen    on    location    stock!' % sum(total_qty)))
    self.assertEqual(self.SDozA.qty_available, 19, ('Wrong    quantity    available    (%s    found    instead    of    19)' % self.SDozA.qty_available))
    quants = self.StockQuantObj.search([('product_id', '=', self.SDozARound.id), ('location_id', '=', self.stock_location)])
    total_qty = [quant.qty for quant in quants]
    self.assertEqual(sum(total_qty), 19, ('Expecting    19    SDozRound    ,    got    %.4f    SDozRound    on    location    stock!' % sum(total_qty)))
    self.assertEqual(self.SDozARound.qty_available, 19, ('Wrong    quantity    available    (%s    found    instead    of    19)' % self.SDozARound.qty_available))
    quants = self.StockQuantObj.search([('product_id', '=', self.gB.id), ('location_id', '=', self.stock_location)])
    total_qty = [quant.qty for quant in quants]
    self.assertEqual(float_round(sum(total_qty), precision_rounding=0.0001), 547.6, ('Expecting    547.6    g    ,    got    %.4f    g    on    location    stock!' % sum(total_qty)))
    self.assertEqual(self.gB.qty_available, 547.6, ('Wrong    quantity    available    (%s    found    instead    of    547.6)' % self.gB.qty_available))
    quants = self.StockQuantObj.search([('product_id', '=', self.kgB.id), ('location_id', '=', self.stock_location)])
    total_qty = [quant.qty for quant in quants]
    self.assertEqual(sum(total_qty), 0.019, ('Expecting    0.019    kg    ,    got    %.4f    kg    on    location    stock!' % sum(total_qty)))
    self.assertEqual(self.kgB.qty_available, 0.019, ('Wrong    quantity    available    (%s    found    instead    of    0.019)' % self.kgB.qty_available))
    bo_in_B.do_prepare_partial()
    bo_in_B.do_transfer()
    quants = self.StockQuantObj.search([('product_id', '=', self.DozA.id), ('location_id', '=', self.stock_location)])
    total_qty = [quant.qty for quant in quants]
    self.assertEqual(sum(total_qty), 15.5, ('Expecting    15.5    Dozen    ,    got    %.4f    Dozen    on    location    stock!' % sum(total_qty)))
    self.assertEqual(self.DozA.qty_available, 15.5, ('Wrong    quantity    available    (%s    found    instead    of    15.5)' % self.DozA.qty_available))
    productKG = self.ProductObj.create({'name': 'Product    KG', 'uom_id': self.uom_kg.id, 'uom_po_id': self.uom_kg.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})
    self.MoveObj.create({'name': productKG.name, 'product_id': productKG.id, 'product_uom_qty': 1.0, 'product_uom': self.uom_tone.id, 'picking_id': picking_in.id, 'location_id': self.supplier_location, 'location_dest_id': self.stock_location})
    self.assertEqual(picking_in.state, 'draft', 'Incoming    shipment    state    should    be    draft.')
    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.')
    picking_in.do_prepare_partial()
    packKG = self.StockPackObj.search([('product_id', '=', productKG.id), ('picking_id', '=', picking_in.id)], limit=1)
    self.assertEqual(packKG.product_qty, 1000, ('Wrong    product    quantity    in    pack    operation    (%s    found    instead    of    1000)' % packKG.product_qty))
    self.assertEqual(packKG.product_uom_id.id, self.uom_kg.id, 'Wrong    product    uom    in    pack    operation.')
    picking_in.do_transfer()
    self.assertEqual(picking_in.state, 'done', ('Incoming    shipment    state:    %s    instead    of    %s' % (picking_in.state, 'done')))
    for move in picking_in.move_lines:
        self.assertEqual(move.state, 'done', 'Wrong    state    of    move    lines.')
    self.assertEqual(len(picking_in.move_lines), 1, 'Wrong    number    of    move    lines')
    move = self.MoveObj.search([('product_id', '=', productKG.id), ('picking_id', '=', picking_in.id)], limit=1)
    self.assertEqual(move.product_uom_qty, 1, 'Wrong    product    quantity    in    done    move.')
    self.assertEqual(move.product_uom.id, self.uom_tone.id, 'Wrong    unit    of    measure    in    done    move.')
    self.assertEqual(productKG.qty_available, 1000, ('Wrong    quantity    available    of    product    (%s    found    instead    of    1000)' % productKG.qty_available))
    picking_out = 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.customer_location})
    self.MoveObj.create({'name': productKG.name, 'product_id': productKG.id, 'product_uom_qty': 2.5, 'product_uom': self.uom_gm.id, 'picking_id': picking_out.id, 'location_id': self.stock_location, 'location_dest_id': self.customer_location})
    picking_out.action_confirm()
    picking_out.action_assign()
    picking_out.do_prepare_partial()
    pack_opt = self.StockPackObj.search([('product_id', '=', productKG.id), ('picking_id', '=', picking_out.id)], limit=1)
    pack_opt.write({'product_qty': 0.5})
    picking_out.do_transfer()
    quants = self.StockQuantObj.search([('product_id', '=', productKG.id), ('location_id', '=', self.stock_location)])
    total_qty = [quant.qty for quant in quants]
    self.assertEqual(sum(total_qty), 999.9995, ('Expecting    999.9995    kg    ,    got    %.4f    kg    on    location    stock!' % sum(total_qty)))
    bo_out_1 = self.PickingObj.search([('backorder_id', '=', picking_out.id)])
    self.assertEqual(len(bo_out_1), 1, 'Back    order    should    be    created.')
    self.assertEqual(len(bo_out_1.move_lines), 1, 'Wrong    number    of    move    lines')
    moves_KG = self.MoveObj.search([('product_id', '=', productKG.id), ('picking_id', '=', bo_out_1.id)], limit=1)
    self.assertEqual(moves_KG.product_uom_qty, 2.0, ('Wrong    move    quantity    (%s    found    instead    of    2.0)' % moves_KG.product_uom_qty))
    self.assertEqual(moves_KG.product_uom.id, self.uom_gm.id, 'Wrong    uom    in    move    for    product    KG.')
    bo_out_1.action_assign()
    bo_out_1.do_prepare_partial()
    pack_opt = self.StockPackObj.search([('product_id', '=', productKG.id), ('picking_id', '=', bo_out_1.id)], limit=1)
    pack_opt.write({'product_qty': 0.5})
    bo_out_1.do_transfer()
    quants = self.StockQuantObj.search([('product_id', '=', productKG.id), ('location_id', '=', self.stock_location)])
    total_qty = [quant.qty for quant in quants]
    self.assertEqual(sum(total_qty), 999.999, ('Expecting    999.9990    kg    ,    got    %.4f    kg    on    location    stock!' % sum(total_qty)))
    bo_out_2 = self.PickingObj.search([('backorder_id', '=', bo_out_1.id)])
    self.assertEqual(len(bo_out_2), 1, 'Back    order    should    be    created.')
    self.assertEqual(len(bo_out_2.move_lines), 1, 'Wrong    number    of    move    lines')
    moves_KG = self.MoveObj.search([('product_id', '=', productKG.id), ('picking_id', '=', bo_out_2.id)], limit=1)
    self.assertEqual(moves_KG.product_uom_qty, 1.5, ('Wrong    move    quantity    (%s    found    instead    of    1.5)' % moves_KG.product_uom_qty))
    self.assertEqual(moves_KG.product_uom.id, self.uom_gm.id, 'Wrong    uom    in    move    for    product    KG.')
    bo_out_2.action_assign()
    bo_out_2.do_prepare_partial()
    pack_opt = self.StockPackObj.search([('product_id', '=', productKG.id), ('picking_id', '=', bo_out_2.id)], limit=1)
    pack_opt.write({'product_qty': 0.5})
    bo_out_2.do_transfer()
    quants = self.StockQuantObj.search([('product_id', '=', productKG.id), ('location_id', '=', self.stock_location)])
    total_qty = [quant.qty for quant in quants]
    self.assertEqual(sum(total_qty), 999.9985, ('Expecting    999.9985    kg    ,    got    %.4f    kg    on    location    stock!' % sum(total_qty)))
    bo_out_3 = self.PickingObj.search([('backorder_id', '=', bo_out_2.id)])
    self.assertEqual(len(bo_out_3), 1, 'Back    order    should    be    created.')
    self.assertEqual(len(bo_out_3.move_lines), 1, 'Wrong    number    of    move    lines')
    moves_KG = self.MoveObj.search([('product_id', '=', productKG.id), ('picking_id', '=', bo_out_3.id)], limit=1)
    self.assertEqual(moves_KG.product_uom_qty, 1, ('Wrong    move    quantity    (%s    found    instead    of    1.0)' % moves_KG.product_uom_qty))
    self.assertEqual(moves_KG.product_uom.id, self.uom_gm.id, 'Wrong    uom    in    move    for    product    KG.')
    bo_out_3.action_assign()
    bo_out_3.do_prepare_partial()
    pack_opt = self.StockPackObj.search([('product_id', '=', productKG.id), ('picking_id', '=', bo_out_3.id)], limit=1)
    pack_opt.write({'product_qty': 0.5})
    bo_out_3.do_transfer()
    quants = self.StockQuantObj.search([('product_id', '=', productKG.id), ('location_id', '=', self.stock_location)])
    total_qty = [quant.qty for quant in quants]
    self.assertEqual(sum(total_qty), 999.998, ('Expecting    999.9980    kg    ,    got    %.4f    kg    on    location    stock!' % sum(total_qty)))
    bo_out_4 = self.PickingObj.search([('backorder_id', '=', bo_out_3.id)])
    self.assertEqual(len(bo_out_4), 1, 'Back    order    should    be    created.')
    self.assertEqual(len(bo_out_4.move_lines), 1, 'Wrong    number    of    move    lines')
    moves_KG = self.MoveObj.search([('product_id', '=', productKG.id), ('picking_id', '=', bo_out_4.id)], limit=1)
    self.assertEqual(moves_KG.product_uom_qty, 0.5, ('Wrong    move    quantity    (%s    found    instead    of    0.5)' % moves_KG.product_uom_qty))
    self.assertEqual(moves_KG.product_uom.id, self.uom_gm.id, 'Wrong    uom    in    move    for    product    KG.')
    bo_out_4.action_assign()
    bo_out_4.do_prepare_partial()
    pack_opt = self.StockPackObj.search([('product_id', '=', productKG.id), ('picking_id', '=', bo_out_4.id)], limit=1)
    pack_opt.write({'product_qty': 0.5})
    bo_out_4.do_transfer()
    quants = self.StockQuantObj.search([('product_id', '=', productKG.id), ('location_id', '=', self.stock_location)])
    total_qty = [quant.qty for quant in quants]
    self.assertEqual(sum(total_qty), 999.9975, ('Expecting    999.9975    kg    ,    got    %.4f    kg    on    location    stock!' % sum(total_qty)))
