Ubercart 3 check the stock before adding to the cart
Someone created a module for that already, needs some fixing IMHO, maybe you can play with that and make something better, I'll definitely be very thankful...