'Testing to do a scrap of consumed material.'

def test_manufacturing_scrap(self):

    (self.product_4 | self.product_2).write({'tracking': 'lot'})
    self.bom_3.bom_line_ids.filtered((lambda x: (x.product_id == self.product_5))).unlink()
    lot_product_4 = self.env['stock.production.lot'].create({'name': '0000000000001', 'product_id': self.product_4.id})
    lot_product_2 = self.env['stock.production.lot'].create({'name': '0000000000002', 'product_id': self.product_2.id})
    stock_inv_product_4 = self.env['stock.inventory'].create({'name': 'Stock    Inventory    for    Stick', 'filter': 'product', 'product_id': self.product_4.id, 'line_ids': [(0, 0, {'product_id': self.product_4.id, 'product_uom_id': self.product_4.uom_id.id, 'product_qty': 8, 'prod_lot_id': lot_product_4.id, 'location_id': self.ref('stock.stock_location_14')})]})
    stock_inv_product_2 = self.env['stock.inventory'].create({'name': 'Stock    Inventory    for    Stone    Tools', 'filter': 'product', 'product_id': self.product_2.id, 'line_ids': [(0, 0, {'product_id': self.product_2.id, 'product_uom_id': self.product_2.uom_id.id, 'product_qty': 12, 'prod_lot_id': lot_product_2.id, 'location_id': self.ref('stock.stock_location_14')})]})
    (stock_inv_product_4 | stock_inv_product_2).prepare_inventory()
    (stock_inv_product_4 | stock_inv_product_2).action_done()
    production_3 = self.env['mrp.production'].create({'name': 'MO-Test003', 'product_id': self.product_6.id, 'product_qty': 12, 'bom_id': self.bom_3.id, 'product_uom_id': self.product_6.uom_id.id})
    production_3.action_assign()
    self.assertEqual(production_3.availability, 'assigned', "Production    order's    availability    should    be    Available.")
    location_id = (((production_3.move_raw_ids.filtered((lambda x: (x.state not in ('done', 'cancel')))) and production_3.location_src_id.id) or production_3.location_dest_id.id),)
    with self.assertRaises(except_orm):
        self.env['stock.scrap'].with_context(active_model='mrp.production', active_id=production_3.id).create({'product_id': self.product_2.id, 'scrap_qty': 1.0, 'product_uom_id': self.product_2.uom_id.id, 'location_id': location_id, 'production_id': production_3.id})
    self.env['stock.scrap'].with_context(active_model='mrp.production', active_id=production_3.id).create({'product_id': self.product_2.id, 'scrap_qty': 1.0, 'product_uom_id': self.product_2.uom_id.id, 'location_id': location_id, 'lot_id': lot_product_2.id, 'production_id': production_3.id})
