# Path: shopkit/currency/utils.py
# def get_currency_field():
#     """
#     Use this method to get a useable pricefield based on the
#     `SHOPKIT_PRICE_FIELD_NAME` setting::
# 
#         # Get the currently configured currency field, whatever it is
#         from shopkit.currency.utils import get_currency_field
#         PriceField = get_currency_field()
# 
#         class PricedModel(models.Model):
#             ...
#             price = PriceField()
# 
# """
#     from shopkit.currency.settings import PRICE_FIELD_NAME
# 
#     # If we're just documenting, return some bogus value here
#     if PRICE_FIELD_NAME == '#doc':
#         class Bogus(object):
#             def __init__(self, *args, **kwargs):
#                 pass
# 
#         return Bogus
# 
#     module_name, field_name = PRICE_FIELD_NAME.rsplit('.', 1)
# 
#     # Allright, this is ugly as a monkey right here
#     # Ref: http://stackoverflow.com/questions/2724260/why-does-pythons-import-require-fromlist
#     module = __import__(module_name, fromlist=(field_name, ))
#     price_field = getattr(module, field_name)
# 
#     return price_field
# 
# Path: shopkit/core/basemodels.py
# class AbstractPricedItemBase(models.Model):
#     """ Abstract base class for items with a price. This only contains
#         a `get_price` dummy function yielding a NotImplementedError. An
#         actual `price` field is contained in the `PricedItemBase` class.
# 
#         This is because we might want to get our prices somewhere else, ie.
#         using some kind of algorithm, web API or database somewhere.
#     """
# 
#     class Meta:
#         abstract = True
# 
#     def get_price(self, **kwargs):
#         """ Get price for the current product.
# 
#             This method _should_ be implemented in a subclass. """
# 
#         raise NotImplementedError
# 
# Path: shopkit/shipping/settings.py
# ADDRESS_MODEL = getattr(settings, 'SHOPKIT_SHIPPING_ADDRESS_MODEL', None)


import logging
from decimal import Decimal
from django.db import models
from django.utils.translation import ugettext_lazy as _
from shopkit.currency.utils import get_currency_field
from shopkit.core.basemodels import AbstractPricedItemBase
from shopkit.shipping.settings import ADDRESS_MODEL
    def get_total_shipping_costs(self, **kwargs):
        """
        Get the total shipping cost for this `Cart`, summing up the shipping
        costs for the whole order and those for individual items (where
        applicable).
        """
        costs = self.get_order_shipping_costs()

        for item in self.get_items():
            item_costs = item.get_shipping_costs()
            assert isinstance(item_costs, Decimal)
            costs += item_costs

        return costs

    def update_shipping(self):
        """ Update the shipping costs for order and order items. """

        # Make sure we call the superclass here
        superclass = super(ShippedOrderBase, self)
        
        self.order_shipping_costs = superclass.get_order_shipping_costs()

        logger.debug(u'Updating order shipping costs for %s to %s',
                     self, self.order_shipping_costs)

        for item in self.get_items():
            item.update_shipping()



# Path: shopkit/currency/utils.py
# def get_currency_field():
#     """
#     Use this method to get a useable pricefield based on the
#     `SHOPKIT_PRICE_FIELD_NAME` setting::
# 
#         # Get the currently configured currency field, whatever it is
#         from shopkit.currency.utils import get_currency_field
#         PriceField = get_currency_field()
# 
#         class PricedModel(models.Model):
#             ...
#             price = PriceField()
# 
# """
#     from shopkit.currency.settings import PRICE_FIELD_NAME
# 
#     # If we're just documenting, return some bogus value here
#     if PRICE_FIELD_NAME == '#doc':
#         class Bogus(object):
#             def __init__(self, *args, **kwargs):
#                 pass
# 
#         return Bogus
# 
#     module_name, field_name = PRICE_FIELD_NAME.rsplit('.', 1)
# 
#     # Allright, this is ugly as a monkey right here
#     # Ref: http://stackoverflow.com/questions/2724260/why-does-pythons-import-require-fromlist
#     module = __import__(module_name, fromlist=(field_name, ))
#     price_field = getattr(module, field_name)
# 
#     return price_field
# 
# Path: shopkit/core/basemodels.py
# class AbstractPricedItemBase(models.Model):
#     """ Abstract base class for items with a price. This only contains
#         a `get_price` dummy function yielding a NotImplementedError. An
#         actual `price` field is contained in the `PricedItemBase` class.
# 
#         This is because we might want to get our prices somewhere else, ie.
#         using some kind of algorithm, web API or database somewhere.
#     """
# 
#     class Meta:
#         abstract = True
# 
#     def get_price(self, **kwargs):
#         """ Get price for the current product.
# 
#             This method _should_ be implemented in a subclass. """
# 
#         raise NotImplementedError
# 
# Path: shopkit/shipping/settings.py
# ADDRESS_MODEL = getattr(settings, 'SHOPKIT_SHIPPING_ADDRESS_MODEL', None)


# Path: shopkit/shipping/basemodels.py
import logging
from decimal import Decimal
from django.db import models
from django.utils.translation import ugettext_lazy as _
from shopkit.currency.utils import get_currency_field
from shopkit.core.basemodels import AbstractPricedItemBase
from shopkit.shipping.settings import ADDRESS_MODEL

    def get_total_shipping_costs(self, **kwargs):
        """
        Get the total shipping cost for this `Cart`, summing up the shipping
        costs for the whole order and those for individual items (where
        applicable).
        """
        costs = self.get_order_shipping_costs()

        for item in self.get_items():
            item_costs = item.get_shipping_costs()
            assert isinstance(item_costs, Decimal)
            costs += item_costs

        return costs

    def update_shipping(self):
        """ Update the shipping costs for order and order items. """

        # Make sure we call the superclass here
        superclass = super(ShippedOrderBase, self)
        
        self.order_shipping_costs = superclass.get_order_shipping_costs()

        logger.debug(u'Updating order shipping costs for %s to %s',
                     self, self.order_shipping_costs)

        for item in self.get_items():
            item.update_shipping()



if ADDRESS_MODEL: