Recently I have been working on a project using Drupal Commerce to build a Jewelry online shop for client. At one point we needed to find a way to adjust the stock of a product that is referenced by another product through the use of Entity Reference field, and unforutnately the current implementation of DC does not provided the needed feature in Rules, hence we had to do it through Code.
After some testing, turned out the stock data is not simply stored in just 1 table (or perhaps there was something that we did wrong? :P), though thanks to the awesome work from Commerce Guys they have already implemented some very useful functions that will ease the pain digging through the data structure. The following steps already assume that you have commerce_stock module installed already.