Commits

Josh VanderLinden committed e326ee2 Merge

Moving the discount stuff to the proper patch

  • Participants
  • Parent commits 9072246, 5dd0896

Comments (0)

Files changed (2)

File combo_discounts

 
 diff -r faaa27e86b41 satchmo/apps/product/templatetags/satchmo_discounts.py
 --- a/satchmo/apps/product/templatetags/satchmo_discounts.py	Mon Aug 23 21:17:23 2010 -0400
-+++ b/satchmo/apps/product/templatetags/satchmo_discounts.py	Mon Aug 23 21:17:52 2010 -0400
++++ b/satchmo/apps/product/templatetags/satchmo_discounts.py	Wed Mar 30 01:06:01 2011 -0400
 @@ -2,6 +2,7 @@
  from django import template
  from livesettings import config_value
      if discount:
 diff -r faaa27e86b41 satchmo/apps/satchmo_ext/discounts/combo/__init__.py
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/satchmo/apps/satchmo_ext/discounts/combo/__init__.py	Mon Aug 23 21:17:52 2010 -0400
-@@ -0,0 +1,31 @@
++++ b/satchmo/apps/satchmo_ext/discounts/combo/__init__.py	Wed Mar 30 01:06:01 2011 -0400
+@@ -0,0 +1,45 @@
 +import logging
 +
 +from l10n.utils import moneyfmt
-+from satchmo_ext.discounts.common import DISCOUNT_AMOUNT, DISCOUNT_PERCENT
 +from satchmo_ext.discounts.signals import pre_recalculate_total
 +
 +from utils import applicable_discounts
 +    all_products = set([li.product for li in instance.orderitem_set.all()])
 +    discounts = applicable_discounts(all_products)
 +
++    greatest_discount = None
++
 +    for discount in discounts:
 +        log.debug('Processing combo discount: %s' % discount)
-+        log.debug('Order discount BEFORE processing: %s' % moneyfmt(instance.discount))
 +
 +        lineitems = instance.orderitem_set.filter(product__id__in=[p.id for p in discount.products.all()])
 +        combo_total = sum([li.line_item_price for li in lineitems])
 +        amount = discount.amount(combo_total)
-+        instance.discount += amount
++
++        if greatest_discount is None or amount > greatest_discount[1]:
++            log.debug('Discount "%s" has a discount greater than the others: %s' % (discount, amount))
++            greatest_discount = (discount, amount)
++        else:
++            log.debug('Discount "%s" does not cut it! %s' % (discount, amount))
++
++    if greatest_discount:
++        discount, amount = greatest_discount
++
++        log.debug('Order discount BEFORE processing: %s' % moneyfmt(instance.discount))
 +
 +        # total is calculated using itemprices. dirty? yes. functional? yes.
++        instance.discount += amount
 +        itemprices.append(amount * -1)
++
 +        log.debug('Order discount AFTER processing: %s' % moneyfmt(instance.discount))
++    else:
++        log.debug('No valid discounts!')
 +
 +pre_recalculate_total.connect(apply_combo_discount)
 +
 diff -r faaa27e86b41 satchmo/apps/satchmo_ext/discounts/combo/admin.py
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/satchmo/apps/satchmo_ext/discounts/combo/admin.py	Mon Aug 23 21:17:52 2010 -0400
++++ b/satchmo/apps/satchmo_ext/discounts/combo/admin.py	Wed Mar 30 01:06:01 2011 -0400
 @@ -0,0 +1,25 @@
 +from django.contrib import admin
 +from models import ComboDiscount, DISCOUNT_AMOUNT, DISCOUNT_PERCENT
 +
 diff -r faaa27e86b41 satchmo/apps/satchmo_ext/discounts/combo/context_processors.py
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/satchmo/apps/satchmo_ext/discounts/combo/context_processors.py	Mon Aug 23 21:17:52 2010 -0400
-@@ -0,0 +1,19 @@
++++ b/satchmo/apps/satchmo_ext/discounts/combo/context_processors.py	Wed Mar 30 01:06:01 2011 -0400
+@@ -0,0 +1,27 @@
++import logging
++
 +from satchmo_store.shop.models import Cart
 +from utils import applicable_discounts, cart_discount_amounts
 +
++log = logging.getLogger('satchmo_ext.discounts.combo.context_processors')
++
 +def combo_discount(request):
 +    """Injects the valid combo discounts into the context"""
 +
 +    cart = Cart.objects.from_request(request)
-+    combo_discounts = {}
-+
 +    all_products = set([i.product for i in cart])
 +
 +    discounts = applicable_discounts(all_products)
 +    amounts = cart_discount_amounts(cart, discounts)
 +    discount_amounts = zip(discounts, amounts)
 +
++    # issue 127 - only one discount per order
++    log.debug('The following discounts may apply to this cart: %s' % (discount_amounts,))
++    discount_amounts.sort(key=lambda t: t[1], reverse=True)
++    discount_amounts = discount_amounts[:1]
++    log.debug('Only applying discount because it saves the user the most money: %s' % (discount_amounts,))
++
 +    return {
 +        'combo_discounts': discount_amounts,
 +    }
 +
 diff -r faaa27e86b41 satchmo/apps/satchmo_ext/discounts/combo/models.py
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/satchmo/apps/satchmo_ext/discounts/combo/models.py	Mon Aug 23 21:17:52 2010 -0400
++++ b/satchmo/apps/satchmo_ext/discounts/combo/models.py	Wed Mar 30 01:06:01 2011 -0400
 @@ -0,0 +1,47 @@
 +from decimal import Decimal
 +import logging
 +
 diff -r faaa27e86b41 satchmo/apps/satchmo_ext/discounts/combo/utils.py
 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-+++ b/satchmo/apps/satchmo_ext/discounts/combo/utils.py	Mon Aug 23 21:17:52 2010 -0400
++++ b/satchmo/apps/satchmo_ext/discounts/combo/utils.py	Wed Mar 30 01:06:01 2011 -0400
 @@ -0,0 +1,40 @@
 +import logging
 +
 +
 diff -r faaa27e86b41 satchmo/apps/satchmo_ext/discounts/signals.py
 --- a/satchmo/apps/satchmo_ext/discounts/signals.py	Mon Aug 23 21:17:23 2010 -0400
-+++ b/satchmo/apps/satchmo_ext/discounts/signals.py	Mon Aug 23 21:17:52 2010 -0400
++++ b/satchmo/apps/satchmo_ext/discounts/signals.py	Wed Mar 30 01:06:01 2011 -0400
 @@ -1,4 +1,5 @@
  from django.dispatch import Signal
  
  
 diff -r faaa27e86b41 satchmo/apps/satchmo_store/shop/models.py
 --- a/satchmo/apps/satchmo_store/shop/models.py	Mon Aug 23 21:17:23 2010 -0400
-+++ b/satchmo/apps/satchmo_store/shop/models.py	Mon Aug 23 21:17:52 2010 -0400
++++ b/satchmo/apps/satchmo_store/shop/models.py	Wed Mar 30 01:06:01 2011 -0400
 @@ -17,7 +17,7 @@
  from payment.fields import PaymentChoiceCharField
  from product.models import Discount, Product, Price, get_product_quantity_adjustments
 # HG changeset patch
-# Parent e08070b169a4ae650fcac0490ca9eec33eb16b0a
+# Parent 0f027c854f13b9dd2613973a43768c630774b5e9
 Only using the one combo discount that will save the user the most money.
 
 diff --git a/.hgignore b/.hgignore
 diff --git a/satchmo/apps/satchmo_ext/discounts/combo/__init__.py b/satchmo/apps/satchmo_ext/discounts/combo/__init__.py
 --- a/satchmo/apps/satchmo_ext/discounts/combo/__init__.py
 +++ b/satchmo/apps/satchmo_ext/discounts/combo/__init__.py
-@@ -1,7 +1,6 @@
- import logging
- 
- from l10n.utils import moneyfmt
--from satchmo_ext.discounts.common import DISCOUNT_AMOUNT, DISCOUNT_PERCENT
- from satchmo_ext.discounts.signals import pre_recalculate_total
- 
- from utils import applicable_discounts
-@@ -14,18 +13,33 @@
-     all_products = set([li.product for li in instance.orderitem_set.all()])
-     discounts = applicable_discounts(all_products)
- 
-+    greatest_discount = None
-+
-     for discount in discounts:
-         log.debug('Processing combo discount: %s' % discount)
--        log.debug('Order discount BEFORE processing: %s' % moneyfmt(instance.discount))
- 
-         lineitems = instance.orderitem_set.filter(product__id__in=[p.id for p in discount.products.all()])
-         combo_total = sum([li.line_item_price for li in lineitems])
-         amount = discount.amount(combo_total)
--        instance.discount += amount
-+
-+        if greatest_discount is None or amount > greatest_discount[1]:
-+            log.debug('Discount "%s" has a discount greater than the others: %s' % (discount, amount))
-+            greatest_discount = (discount, amount)
-+        else:
-+            log.debug('Discount "%s" does not cut it! %s' % (discount, amount))
-+
-+    if greatest_discount:
-+        discount, amount = greatest_discount
-+
-+        log.debug('Order discount BEFORE processing: %s' % moneyfmt(instance.discount))
- 
-         # total is calculated using itemprices. dirty? yes. functional? yes.
-+        instance.discount += amount
-         itemprices.append(amount * -1)
-+
-         log.debug('Order discount AFTER processing: %s' % moneyfmt(instance.discount))
-+    else:
-+        log.debug('No valid discounts!')
+@@ -42,4 +42,3 @@
+         log.debug('No valid discounts!')
  
  pre_recalculate_total.connect(apply_combo_discount)
- 
-diff --git a/satchmo/apps/satchmo_ext/discounts/combo/context_processors.py b/satchmo/apps/satchmo_ext/discounts/combo/context_processors.py
---- a/satchmo/apps/satchmo_ext/discounts/combo/context_processors.py
-+++ b/satchmo/apps/satchmo_ext/discounts/combo/context_processors.py
-@@ -1,18 +1,26 @@
-+import logging
-+
- from satchmo_store.shop.models import Cart
- from utils import applicable_discounts, cart_discount_amounts
- 
-+log = logging.getLogger('satchmo_ext.discounts.combo.context_processors')
-+
- def combo_discount(request):
-     """Injects the valid combo discounts into the context"""
- 
-     cart = Cart.objects.from_request(request)
--    combo_discounts = {}
 -
-     all_products = set([i.product for i in cart])
- 
-     discounts = applicable_discounts(all_products)
-     amounts = cart_discount_amounts(cart, discounts)
-     discount_amounts = zip(discounts, amounts)
- 
-+    # issue 127 - only one discount per order
-+    log.debug('The following discounts may apply to this cart: %s' % (discount_amounts,))
-+    discount_amounts.sort(key=lambda t: t[1], reverse=True)
-+    discount_amounts = discount_amounts[:1]
-+    log.debug('Only applying discount because it saves the user the most money: %s' % (discount_amounts,))
-+
-     return {
-         'combo_discounts': discount_amounts,
-     }
 diff --git a/satchmo/apps/satchmo_store/shop/admin.py b/satchmo/apps/satchmo_store/shop/admin.py
 --- a/satchmo/apps/satchmo_store/shop/admin.py
 +++ b/satchmo/apps/satchmo_store/shop/admin.py