You can’t get an answer to such an open ended question.
Where is the avaialble stock wquantity stored?
If you have a stock model then you need a decrement_stock_Level method in your model.
Call this whenever you feel that you need to update the stock levels and your view should just reflect the adjusted value.
You are not going to adjust available quantities until checkout has been successfully completed though (I hope) and you need to ensure that at the point of completing checkout that the chosen quantities are available.
Of course you will need to consider whether or not you need some kind of table lock between checking and updating because in that split second someone else may have completed checkout for the same items.
Think long and hard before implementing a solution and the right way should become obvious