# Path: registrasion/models/commerce.py
# class Cart(models.Model):
#     class Meta:
# class ProductItem(models.Model):
#     class Meta:
# class DiscountItem(models.Model):
#     class Meta:
# class Invoice(models.Model):
#     class Meta:
# class LineItem(models.Model):
#     class Meta:
# class PaymentBase(models.Model):
#     class Meta:
# class ManualPayment(PaymentBase):
#     class Meta:
# class CreditNote(PaymentBase):
#     class Meta:
# class CleanOnSave(object):
# class CreditNoteApplication(CleanOnSave, PaymentBase):
#     class Meta:
# class CreditNoteRefund(CleanOnSave, models.Model):
# class ManualCreditNoteRefund(CreditNoteRefund):
#     class Meta:
#     def __str__(self):
#     def reserved_carts(cls):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def clean(self):
#     def is_unpaid(self):
#     def is_void(self):
#     def is_paid(self):
#     def is_refunded(self):
#     def total_payments(self):
#     def balance_due(self):
#     def __str__(self):
#     def total_price(self):
#     def __str__(self):
#     def unclaimed(cls):
#     def refunded(cls):
#     def status(self):
#     def is_unclaimed(self):
#     def value(self):
#     def save(self, *a, **k):
#     def clean(self):
#     def clean(self):
#     STATUS_ACTIVE = 1
#     STATUS_PAID = 2
#     STATUS_RELEASED = 3
#     STATUS_TYPES = [
#         (STATUS_ACTIVE, _("Active")),
#         (STATUS_PAID, _("Paid")),
#         (STATUS_RELEASED, _("Released")),
#     ]
#     STATUS_UNPAID = 1
#     STATUS_PAID = 2
#     STATUS_REFUNDED = 3
#     STATUS_VOID = 4
#     STATUS_TYPES = [
#         (STATUS_UNPAID, _("Unpaid")),
#         (STATUS_PAID, _("Paid")),
#         (STATUS_REFUNDED, _("Refunded")),
#         (STATUS_VOID, _("VOID")),
#     ]
# 
# Path: registrasion/models/inventory.py
# class Category(models.Model):
#     class Meta:
# class Product(models.Model):
#     class Meta:
# class Voucher(models.Model):
#     class Meta:
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def normalise_code(cls, code):
#     def save(self, *a, **k):
#     RENDER_TYPE_RADIO = 1
#     RENDER_TYPE_QUANTITY = 2
#     RENDER_TYPE_ITEM_QUANTITY = 3
#     RENDER_TYPE_CHECKBOX = 4
#     CATEGORY_RENDER_TYPES = [
#         (RENDER_TYPE_RADIO, _("Radio button")),
#         (RENDER_TYPE_QUANTITY, _("Quantity boxes")),
#         (RENDER_TYPE_ITEM_QUANTITY, _("Product selector and quantity box")),
#         (RENDER_TYPE_CHECKBOX, _("Checkbox button")),
#     ]
#     RESERVATION_DURATION = datetime.timedelta(hours=1)


import operator
from functools import reduce
from registrasion.models import commerce
from registrasion.models import inventory
from collections import Iterable
from collections import namedtuple
from django.db.models import Case
from django.db.models import Q
from django.db.models import Sum
from django.db.models import When
from django.db.models import Value

        in_cart = Q(productitem__cart__user=self.user)
        in_cart = in_cart & reduce(operator.__or__, status_query)

        quantities_in_cart = When(
            in_cart,
            then="productitem__quantity",
        )

        quantities_or_zero = Case(
            quantities_in_cart,
            default=Value(0),
        )

        products = inventory.Product.objects

        if category:
            products = products.filter(category=category)

        products = products.select_related("category")
        products = products.annotate(quantity=Sum(quantities_or_zero))
        products = products.filter(quantity__gt=0)

        out = []
        for prod in products:
            out.append(ProductAndQuantity(prod, prod.quantity))
        return out

    def items_pending_or_purchased(self):
        ''' Returns the items that this user has purchased or has pending. '''

# Path: registrasion/models/commerce.py
# class Cart(models.Model):
#     class Meta:
# class ProductItem(models.Model):
#     class Meta:
# class DiscountItem(models.Model):
#     class Meta:
# class Invoice(models.Model):
#     class Meta:
# class LineItem(models.Model):
#     class Meta:
# class PaymentBase(models.Model):
#     class Meta:
# class ManualPayment(PaymentBase):
#     class Meta:
# class CreditNote(PaymentBase):
#     class Meta:
# class CleanOnSave(object):
# class CreditNoteApplication(CleanOnSave, PaymentBase):
#     class Meta:
# class CreditNoteRefund(CleanOnSave, models.Model):
# class ManualCreditNoteRefund(CreditNoteRefund):
#     class Meta:
#     def __str__(self):
#     def reserved_carts(cls):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def clean(self):
#     def is_unpaid(self):
#     def is_void(self):
#     def is_paid(self):
#     def is_refunded(self):
#     def total_payments(self):
#     def balance_due(self):
#     def __str__(self):
#     def total_price(self):
#     def __str__(self):
#     def unclaimed(cls):
#     def refunded(cls):
#     def status(self):
#     def is_unclaimed(self):
#     def value(self):
#     def save(self, *a, **k):
#     def clean(self):
#     def clean(self):
#     STATUS_ACTIVE = 1
#     STATUS_PAID = 2
#     STATUS_RELEASED = 3
#     STATUS_TYPES = [
#         (STATUS_ACTIVE, _("Active")),
#         (STATUS_PAID, _("Paid")),
#         (STATUS_RELEASED, _("Released")),
#     ]
#     STATUS_UNPAID = 1
#     STATUS_PAID = 2
#     STATUS_REFUNDED = 3
#     STATUS_VOID = 4
#     STATUS_TYPES = [
#         (STATUS_UNPAID, _("Unpaid")),
#         (STATUS_PAID, _("Paid")),
#         (STATUS_REFUNDED, _("Refunded")),
#         (STATUS_VOID, _("VOID")),
#     ]
# 
# Path: registrasion/models/inventory.py
# class Category(models.Model):
#     class Meta:
# class Product(models.Model):
#     class Meta:
# class Voucher(models.Model):
#     class Meta:
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     def normalise_code(cls, code):
#     def save(self, *a, **k):
#     RENDER_TYPE_RADIO = 1
#     RENDER_TYPE_QUANTITY = 2
#     RENDER_TYPE_ITEM_QUANTITY = 3
#     RENDER_TYPE_CHECKBOX = 4
#     CATEGORY_RENDER_TYPES = [
#         (RENDER_TYPE_RADIO, _("Radio button")),
#         (RENDER_TYPE_QUANTITY, _("Quantity boxes")),
#         (RENDER_TYPE_ITEM_QUANTITY, _("Product selector and quantity box")),
#         (RENDER_TYPE_CHECKBOX, _("Checkbox button")),
#     ]
#     RESERVATION_DURATION = datetime.timedelta(hours=1)


# Path: registrasion/controllers/item.py
import operator
from functools import reduce
from registrasion.models import commerce
from registrasion.models import inventory
from collections import Iterable
from collections import namedtuple
from django.db.models import Case
from django.db.models import Q
from django.db.models import Sum
from django.db.models import When
from django.db.models import Value


        in_cart = Q(productitem__cart__user=self.user)
        in_cart = in_cart & reduce(operator.__or__, status_query)

        quantities_in_cart = When(
            in_cart,
            then="productitem__quantity",
        )

        quantities_or_zero = Case(
            quantities_in_cart,
            default=Value(0),
        )

        products = inventory.Product.objects

        if category:
            products = products.filter(category=category)

        products = products.select_related("category")
        products = products.annotate(quantity=Sum(quantities_or_zero))
        products = products.filter(quantity__gt=0)

        out = []
        for prod in products:
            out.append(ProductAndQuantity(prod, prod.quantity))
        return out

    def items_pending_or_purchased(self):
        ''' Returns the items that this user has purchased or has pending. '''

        status = [commerce.Cart.STATUS_PAID, commerce.Cart.STATUS_ACTIVE]