@@ -20,24 +20,31 @@ class ProductController(object):
can_add_with_enabling_conditions calls this method. '''
if category is None and products is None:
raise ValueError("You must provide products or a category")
if category is not None:
all_products = rego.Product.objects.filter(category=category)
all_products = all_products.select_related("category")
else:
all_products = []
if products is not None:
all_products = itertools.chain(all_products, products)
all_products = set(itertools.chain(all_products, products))
cat_quants = dict(
(
category,
CategoryController(category).user_quantity_remaining(user),
)
for category in set(product.category for product in all_products)
passed_limits = set(
product
for product in all_products
if CategoryController(product.category).user_quantity_remaining(
user
) > 0
if cat_quants[product.category] > 0
if cls(product).user_quantity_remaining(user) > 0
failed_and_messages = ConditionController.test_enabling_conditions(
user, products=passed_limits