'Testing bill of material with diffrent unit of measure.'

def test_02_different_uom_on_bomlines(self):

    route_manufacture = self.warehouse.manufacture_pull_id.route_id.id
    route_mto = self.warehouse.mto_pull_id.route_id.id
    unit = self.ref('product.product_uom_unit')
    dozen = self.ref('product.product_uom_dozen')
    kg = self.ref('product.product_uom_kgm')
    gm = self.ref('product.product_uom_gram')
    product_A = self.env['product.product'].create({'name': 'Product    A', 'type': 'product', 'tracking': 'lot', 'uom_id': dozen, 'uom_po_id': dozen, 'route_ids': [(6, 0, [route_manufacture, route_mto])]})
    product_B = self.env['product.product'].create({'name': 'Product    B', 'type': 'product', 'tracking': 'lot', 'uom_id': dozen, 'uom_po_id': dozen})
    product_C = self.env['product.product'].create({'name': 'Product    C', 'type': 'product', 'tracking': 'lot', 'uom_id': kg, 'uom_po_id': kg})
    bom_a = self.env['mrp.bom'].create({'product_tmpl_id': product_A.product_tmpl_id.id, 'product_qty': 2, 'product_uom_id': unit, 'bom_line_ids': [(0, 0, {'product_id': product_B.id, 'product_qty': 4, 'product_uom_id': unit}), (0, 0, {'product_id': product_C.id, 'product_qty': 600, 'product_uom_id': gm})]})
    mo_custom_product = self.env['mrp.production'].create({'product_id': product_A.id, 'product_qty': 10, 'product_uom_id': unit, 'bom_id': bom_a.id})
    move_product_b = mo_custom_product.move_raw_ids.filtered((lambda x: (x.product_id == product_B)))
    move_product_c = mo_custom_product.move_raw_ids.filtered((lambda x: (x.product_id == product_C)))
    self.assertEqual(move_product_b.product_uom_qty, 20)
    self.assertEqual(move_product_b.product_uom.id, unit)
    self.assertEqual(move_product_c.product_uom_qty, 3000)
    self.assertEqual(move_product_c.product_uom.id, gm)
    lot_a = self.env['stock.production.lot'].create({'product_id': product_A.id})
    lot_b = self.env['stock.production.lot'].create({'product_id': product_B.id})
    lot_c = self.env['stock.production.lot'].create({'product_id': product_C.id})
    inventory = self.env['stock.inventory'].create({'name': 'Inventory    Product    B    and    C', 'filter': 'partial', 'line_ids': [(0, 0, {'product_id': product_B.id, 'product_uom_id': product_B.uom_id.id, 'product_qty': 3, 'prod_lot_id': lot_b.id, 'location_id': self.source_location_id}), (0, 0, {'product_id': product_C.id, 'product_uom_id': product_C.uom_id.id, 'product_qty': 3, 'prod_lot_id': lot_c.id, 'location_id': self.source_location_id})]})
    inventory.action_done()
    mo_custom_product.action_assign()
    context = {'active_ids': [mo_custom_product.id], 'active_id': mo_custom_product.id}
    product_consume = self.env['mrp.product.produce'].with_context(context).create({'product_qty': 10})
    product_consume.lot_id = lot_a.id
    self.assertEquals(len(product_consume.consume_line_ids), 2)
    product_consume.consume_line_ids.filtered((lambda x: (x.product_id == product_C))).write({'quantity_done': 3000})
    product_consume.consume_line_ids.filtered((lambda x: (x.product_id == product_B))).write({'quantity_done': 20})
    product_consume.do_produce()
    mo_custom_product.post_inventory()
    self.assertEqual(len(move_product_b.quant_ids), 1)
    self.assertEqual(len(move_product_c.quant_ids), 1)
    self.assertEqual(move_product_b.quant_ids.qty, move_product_b.product_qty)
    self.assertEqual(move_product_c.quant_ids.qty, 3)
    self.assertEqual(move_product_c.quant_ids.product_uom_id.id, kg)
