@@ -32,25 +32,25 @@ class CategoryController(object):
return set(i.category for i in available)
def user_quantity_remaining(self, user):
''' Returns the number of items from this category that the user may
add in the current cart. '''
cat_limit = self.category.limit_per_user
if cat_limit is None:
# We don't need to waste the following queries
return 99999999
carts = rego.Cart.objects.filter(
user=user,
active=False,
released=False,
)
items = rego.ProductItem.objects.filter(
cart__in=carts,
product__category=self.category,
cat_count = items.aggregate(Sum("quantity"))["quantity__sum"] or 0
cat_limit - cat_count
return cat_limit - cat_count