registrasion/controllers/cart.py
def _recalculate_discounts(self):
        ''' Calculates all of the discounts available for this product.'''

        # Delete the existing entries.
        commerce.DiscountItem.objects.filter(cart=self.cart).delete()

        # Order the products such that the most expensive ones are
        # processed first.
        product_items = self.cart.productitem_set.all().select_related(
            "product", "product__category"
        ).order_by("-product__price")

        products = [i.product for i in product_items]
        discounts = DiscountController.available_discounts(
            self.cart.user,
            [],
            products,
        )

        # The highest-value discounts will apply to the highest-value
        # products first, because of the order_by clause
        for item in product_items:
            self._add_discount(item.product, item.quantity, discounts)
def _recalculate_discounts(self):
        ''' Calculates all of the discounts available for this product.'''

        # Delete the existing entries.
        commerce.DiscountItem.objects.filter(cart=self.cart).delete()

        # Order the products such that the most expensive ones are
        # processed first.
        product_items = self.cart.productitem_set.all().select_related(
            "product", "product__category"
        ).order_by("-product__price")

        products = [i.product for i in product_items]
        discounts = DiscountController.available_discounts(
            self.cart.user,
            [],
            products,
        )

        # The highest-value discounts will apply to the highest-value
        # products first, because of the order_by clause
        for item in product_items:
            self._add_discount(item.product, item.quantity, discounts)
Calculates all of the discounts available for this product.