# Path: shopkit/stock/exceptions.py
# class NoStockAvailableException(ShopKitExceptionBase):
#     """ 
#     Exception raised by the save method of :class:`StockedCartItemMixinBase` 
#     when no stock is available for the current item.
#     """
#     
#     def __init__(self, item):
#         self.item = item
#     
#     def __unicode__(self):
#         return u'No stock available for item \'%s\'' % self.item


from shopkit.stock.exceptions import NoStockAvailableException
        item is eligible to be saved or not.
        """
        return True


class StockedCartBase(object):
    """
    Base class for shopping carts for which stock is kept.
    """

    def add_item(self, product, quantity=1, **kwargs):
        """
        Attempt to add item to cart.

        This method will raise a :class:`NoStockAvailableException` when
        no stock items are available.
        """

        # Stock is available, just return the superclass value
        cartitem = super(StockedCartBase, self).add_item(product,
                                                         quantity,
                                                         **kwargs)

        # Check whether enough stock is available
        if not cartitem.is_available(cartitem.quantity):
            # Substract the quantity again. Inefficient but necessary for now
            cartitem.quantity -= quantity
            cartitem.save()

            # Raise error

# Path: shopkit/stock/exceptions.py
# class NoStockAvailableException(ShopKitExceptionBase):
#     """ 
#     Exception raised by the save method of :class:`StockedCartItemMixinBase` 
#     when no stock is available for the current item.
#     """
#     
#     def __init__(self, item):
#         self.item = item
#     
#     def __unicode__(self):
#         return u'No stock available for item \'%s\'' % self.item


# Path: shopkit/stock/models.py
from shopkit.stock.exceptions import NoStockAvailableException

        item is eligible to be saved or not.
        """
        return True


class StockedCartBase(object):
    """
    Base class for shopping carts for which stock is kept.
    """

    def add_item(self, product, quantity=1, **kwargs):
        """
        Attempt to add item to cart.

        This method will raise a :class:`NoStockAvailableException` when
        no stock items are available.
        """

        # Stock is available, just return the superclass value
        cartitem = super(StockedCartBase, self).add_item(product,
                                                         quantity,
                                                         **kwargs)

        # Check whether enough stock is available
        if not cartitem.is_available(cartitem.quantity):
            # Substract the quantity again. Inefficient but necessary for now
            cartitem.quantity -= quantity
            cartitem.save()

            # Raise error

            raise NoStockAvailableException(item=cartitem)