diff --git a/registrasion/controllers/cart.py b/registrasion/controllers/cart.py index ad4458eab3bfa31e7de09c2403facd939e83ee7d..204dc9f6ada5876671d676215a8fad99c03adf54 100644 --- a/registrasion/controllers/cart.py +++ b/registrasion/controllers/cart.py @@ -399,9 +399,11 @@ class CartController(object): # 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", "product__price" - ) + ).order_by("-product__price") products = [i.product for i in product_items] discounts = DiscountController.available_discounts( @@ -411,8 +413,7 @@ class CartController(object): ) # The highest-value discounts will apply to the highest-value - # products first. - product_items = reversed(product_items) + # products first, because of the order_by clause for item in product_items: self._add_discount(item.product, item.quantity, discounts)