@classmethod<EOL><INDENT>@BatchController.memoise<EOL>def user_remainders(cls, user):<DEDENT>
products = inventory.Product.objects.all()<EOL>cart_filter = (<EOL>Q(productitem__cart__user=user) &<EOL>Q(productitem__cart__status=commerce.Cart.STATUS_PAID)<EOL>)<EOL>quantity = When(<EOL>cart_filter,<EOL>then='<STR_LIT>'<EOL>)<EOL>quantity_or_zero = Case(<EOL>quantity,<EOL>default=Value(<NUM_LIT:0>),<EOL>)<EOL>remainder = Case(<EOL>When(limit_per_user=None, then=Value(<NUM_LIT>)),<EOL>default=F('<STR_LIT>') - Sum(quantity_or_zero),<EOL>)<EOL>products = products.annotate(remainder=remainder)<EOL>return dict((product.id, product.remainder) for product in products)<EOL>
Return:
    Mapping[int->int]: A dictionary that maps the product ID to the
    user's remainder for that product.