Joshua Pokotilow committed 155b676

ProductVariation.get_qty_price ignores deltas when appropriate.

When a ProductVariation's price is explicit for a certain quantity, the delta
derived from option group options should be ignored. As a rule of thumb, deltas
should *never* be applied to ProductVariation prices.

In addition, there were some redundant calls to Price.objects.filter(...), which
I DRYed up a bit by implementing / calling
ProductVariation._get_self_qty_price_list where appropriate.

This changeset is designed to address issue #1382.

  • Participants
  • Parent commits 9537667

Comments (0)

Files changed (1)


     objects = ProductVariationManager()
+    def _get_self_qty_price_list(self, qty=1):
+        return Price.objects.filter(,
     def _get_fullPrice(self):
         """ Get price based on parent ConfigurableProduct """
         # allow explicit setting of prices.
         #qty_discounts = self.price_set.exclude(expires__isnull=False,
-            qty_discounts = Price.objects.filter(,
+            qty_discounts = self._get_self_qty_price_list()
             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].dynamic_price
     def get_qty_price(self, qty, include_discount=True):
+        # if no prices have been set specifically for this variation, we derive a price from the parent
+        # if a price *has* been set (for the appropriate quantity), the delta is ignored, and the price is used as-is
+        should_use_delta = len(self._get_self_qty_price_list(qty)) == 0
         if include_discount:
             price = get_product_quantity_price(
                 self.product, qty,
-                delta=self.price_delta(False),
+                delta=(0, self.price_delta(False))[should_use_delta],
             adjustment = get_product_quantity_adjustments(self, qty, parent=self.parent.product)
     def get_qty_price_list(self):
         """Return a list of tuples (qty, price)"""
-        prices = Price.objects.filter(,
+        prices = self._get_self_qty_price_list()
         if prices.count() > 0:
             # prices directly set, return them
             pricelist = [(price.quantity, price.dynamic_price) for price in prices]