@@ -208,34 +208,32 @@ class CartController(object):
)
items_in_cart.filter(to_delete).delete()
commerce.ProductItem.objects.bulk_create(new_items)
def _test_limits(self, product_quantities):
''' Tests that the quantity changes we intend to make do not violate
the limits and flag conditions imposed on the products. '''
errors = []
# Pre-annotate products
products = [p for (p, q) in product_quantities]
r = ProductController.attach_user_remainders(self.cart.user, products)
with_remainders = dict((p, p) for p in r)
remainders = ProductController.user_remainders(self.cart.user)
# Test each product limit here
for product, quantity in product_quantities:
if quantity < 0:
errors.append((product, "Value must be zero or greater."))
limit = with_remainders[product].remainder
limit = remainders[product.id]
if quantity > limit:
errors.append((
product,
"You may only have %d of product: %s" % (
limit, product,
))
# Collect by category
by_cat = collections.defaultdict(list)