public static function get_by_buyable($buyable)
 {
     $obj = BuyableStockCalculatedQuantity::get()->filter(array('BuyableID' => $buyable->ID, 'BuyableClassName' => $buyable->ClassName))->First();
     if ($obj) {
         //do nothing
     } else {
         $obj = new BuyableStockCalculatedQuantity();
         $obj->BuyableID = $buyable->ID;
         $obj->BuyableClassName = $buyable->ClassName;
     }
     if ($obj) {
         if (isset($obj->ID) && $obj->exists() && $obj->UnlimitedStock == $buyable->UnlimitedStock) {
             //do nothing
         } else {
             $obj->UnlimitedStock = $buyable->UnlimitedStock;
             //we must write here to calculate quantities
             $obj->write();
         }
         return $obj;
     }
     user_error("Could not find / create BuyableStockCalculatedQuantity for buyable with ID / ClassName " . $buyableID . "/" . $buyableClassName, E_WARNING);
 }