Commits

Josh VanderLinden committed 4289974

Added a domestic/international flat rate shipping module

Comments (0)

Files changed (1)

  
      objects = OrderManager()
  
+diff --git a/satchmo/apps/shipping/modules/flat/__init__.py b/satchmo/apps/shipping/modules/dv_flat/__init__.py
+copy from satchmo/apps/shipping/modules/flat/__init__.py
+copy to satchmo/apps/shipping/modules/dv_flat/__init__.py
+diff --git a/satchmo/apps/shipping/modules/flat/config.py b/satchmo/apps/shipping/modules/dv_flat/config.py
+copy from satchmo/apps/shipping/modules/flat/config.py
+copy to satchmo/apps/shipping/modules/dv_flat/config.py
+--- a/satchmo/apps/shipping/modules/flat/config.py
++++ b/satchmo/apps/shipping/modules/dv_flat/config.py
+@@ -2,30 +2,61 @@
+ from livesettings import *
+ 
+ SHIP_MODULES = config_get('SHIPPING', 'MODULES')
+-SHIP_MODULES.add_choice(('shipping.modules.flat', _('Flat rate')))
+-SHIPPING_GROUP = config_get_group('SHIPPING')
++SHIP_MODULES.add_choice(('shipping.modules.dv_flat', _('DVP Flat rate')))
++
++DOM_SHIPPING_GROUP = ConfigurationGroup('DOM_SHIPPING',
++    _('Domestic Flat Rate Shipping'),
++    ordering = 1.1)
++INTL_SHIPPING_GROUP = ConfigurationGroup('INTL_SHIPPING',
++    _('International Flat Rate Shipping'),
++    ordering = 1.1)
+ 
+ config_register_list(
+ 
+-    DecimalValue(SHIPPING_GROUP,
++    DecimalValue(DOM_SHIPPING_GROUP,
+         'FLAT_RATE',
+-        description=_("Flat shipping"),
++        description=_("Domestic Flat shipping"),
+         requires=SHIP_MODULES,
+-        requiresvalue='shipping.modules.flat',
++        requiresvalue='shipping.modules.dv_flat',
+         default="4.00"),
+ 
+-    StringValue(SHIPPING_GROUP,
++    StringValue(DOM_SHIPPING_GROUP,
+         'FLAT_SERVICE',
+-        description=_("Flat Shipping Service"),
+-        help_text=_("Shipping service used with Flat rate shipping"),
++        description=_("Domestic Flat Shipping Service"),
++        help_text=_("Shipping service used with domestic flat rate shipping"),
+         requires=SHIP_MODULES,
+-        requiresvalue='shipping.modules.flat',
++        requiresvalue='shipping.modules.dv_flat',
+         default=u"U.S. Mail"),
+     
+-    StringValue(SHIPPING_GROUP,
++    StringValue(DOM_SHIPPING_GROUP,
+         'FLAT_DAYS',
+-        description=_("Flat Delivery Days"),
++        description=_("Domestic Flat Delivery Days"),
+         requires=SHIP_MODULES,
+-        requiresvalue='shipping.modules.flat',
+-        default="3 - 4 business days")
++        requiresvalue='shipping.modules.dv_flat',
++        default="3 - 4 business days"),
++
++    # ---------------- INTERNATIONAL
++
++    DecimalValue(INTL_SHIPPING_GROUP,
++        'FLAT_RATE',
++        description=_("International Flat shipping"),
++        requires=SHIP_MODULES,
++        requiresvalue='shipping.modules.dv_flat',
++        default="8.00"),
++
++    StringValue(INTL_SHIPPING_GROUP,
++        'FLAT_SERVICE',
++        description=_("International Flat Shipping Service"),
++        help_text=_("Shipping service used with domestic flat rate shipping"),
++        requires=SHIP_MODULES,
++        requiresvalue='shipping.modules.dv_flat',
++        default=u"U.S. Mail"),
++    
++    StringValue(INTL_SHIPPING_GROUP,
++        'FLAT_DAYS',
++        description=_("International Flat Delivery Days"),
++        requires=SHIP_MODULES,
++        requiresvalue='shipping.modules.dv_flat',
++        default="6 - 14 business days")
+ )
++
+diff --git a/satchmo/apps/shipping/modules/flat/shipper.py b/satchmo/apps/shipping/modules/dv_flat/shipper.py
+copy from satchmo/apps/shipping/modules/flat/shipper.py
+copy to satchmo/apps/shipping/modules/dv_flat/shipper.py
+--- a/satchmo/apps/shipping/modules/flat/shipper.py
++++ b/satchmo/apps/shipping/modules/dv_flat/shipper.py
+@@ -1,48 +1,70 @@
+-"""
+-Each shipping option uses the data in an Order object to calculate the shipping cost and return the value
+-"""
+ from decimal import Decimal
+-from django.utils.translation import ugettext, ugettext_lazy
++from django.utils.translation import ugettext, ugettext_lazy as _
+ from livesettings import config_value
+-_ = ugettext_lazy
+ from shipping.modules.base import BaseShipper
+ 
+ class Shipper(BaseShipper):
+-    id = "FlatRate"
++    id = "DVPFlatRate"
++
++    @property
++    def group(self):
++        """Returns the appropriate group for this order"""
++
++        if self.is_international():
++            return 'INTL_SHIPPING'
++        return 'DOM_SHIPPING'
++
++    def is_international(self):
++        """Returns True if this order appears to be international"""
++
++        return self.contact and self.contact.shipping_address and \
++            self.contact.shipping_address.country.iso2_code != 'US'
+ 
+     def __str__(self):
+         """
+         This is mainly helpful for debugging purposes
+         """
+-        return "Flat Rate: %s" % config_value('SHIPPING', 'FLAT_RATE')
++
++        return '%s: %s' % (
++            self.description.replace(' Shipping', ''),
++            config_value(self.group, 'FLAT_RATE')
++        )
+ 
+     def description(self):
+         """
+         A basic description that will be displayed to the user when selecting their shipping options
+         """
+-        return _("Flat Rate Shipping")
++
++        if self.is_international():
++            return _('International Flat Rate Shipping')
++
++        return _('Domestic Flat Rate Shipping')
+ 
+     def cost(self):
+         """
+         Complex calculations can be done here as long as the return value is a dollar figure
+         """
+         assert(self._calculated)
++
+         for cartitem in self.cart.cartitem_set.all():
+             if cartitem.product.is_shippable:
+-                return config_value('SHIPPING', 'FLAT_RATE')
++                return config_value(self.group, 'FLAT_RATE')
++
+         return Decimal("0.00")
+ 
+     def method(self):
+         """
+         Describes the actual delivery service (Mail, FedEx, DHL, UPS, etc)
+         """
+-        return ugettext(config_value('SHIPPING', 'FLAT_SERVICE'))
++
++        return ugettext(config_value(self.group, 'FLAT_SERVICE'))
+ 
+     def expectedDelivery(self):
+         """
+-        Can be a plain string or complex calcuation returning an actual date
++        Can be a plain string or complex calculation returning an actual date
+         """
+-        return ugettext(config_value('SHIPPING', 'FLAT_DAYS'))
++
++        return ugettext(config_value(self.group, 'FLAT_DAYS'))
+ 
+     def valid(self, order=None):
+         """
+@@ -50,5 +72,6 @@
+         For example, may check to see if the recipient is in an allowed country
+         or location.
+         """
++
+         return True
+