Commits

Chris Moffitt committed 215e9f9

Make sure tiered pricing can inherit from the parent. Closes #1194

Comments (0)

Files changed (1)

satchmo/apps/satchmo_ext/tieredpricing/models.py

 class TieredPriceManager(models.Manager):
 
     def by_product_qty(self, tier, product, qty=Decimal('1')):
-        """Get the tiered price for the specified product and quantity."""
+        """Get the tiered price for the specified product and quantity. If it's a product variation, we check the parent too"""
 
         qty_discounts = product.tieredprices.exclude(expires__isnull=False, expires__lt=datetime.date.today()).filter(quantity__lte=qty, pricingtier=tier)
 
         if qty_discounts.count() > 0:
             # Get the price with the quantity closest to the one specified without going over
             return qty_discounts.order_by('-quantity')[0]
+        # If we haven't found a price, see if the parent product has a price tier
+        if 'ProductVariation' in product.get_subtypes():
+            parent_product = product.productvariation.parent.product
+            qty_discounts = parent_product.tieredprices.exclude(expires__isnull=False, expires__lt=datetime.date.today()).filter(quantity__lte=qty, pricingtier=tier)
+            if qty_discounts.count() > 0:
+                # Get the price with the quantity closest to the one specified without going over
+                return qty_discounts.order_by('-quantity')[0]
         raise TieredPrice.DoesNotExist
 
 class TieredPrice(models.Model):