# 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/conditions.py
# class TimeOrStockLimitCondition(models.Model):
#     class Meta:
# class VoucherCondition(models.Model):
#     class Meta:
# class IncludedProductCondition(models.Model):
#     class Meta:
# class SpeakerCondition(models.Model):
#     class Meta:
# class GroupMemberCondition(models.Model):
#     class Meta:
# class DiscountBase(models.Model):
#     class Meta:
# class DiscountForProduct(models.Model):
#     class Meta:
# class DiscountForCategory(models.Model):
#     class Meta:
# class TimeOrStockLimitDiscount(TimeOrStockLimitCondition, DiscountBase):
#     class Meta:
# class VoucherDiscount(VoucherCondition, DiscountBase):
#     class Meta:
# class IncludedProductDiscount(IncludedProductCondition, DiscountBase):
#     class Meta:
# class SpeakerDiscount(SpeakerCondition, DiscountBase):
#     class Meta:
# class GroupMemberDiscount(GroupMemberCondition, DiscountBase):
#     class Meta:
# class FlagBase(models.Model):
# class TimeOrStockLimitFlag(TimeOrStockLimitCondition, FlagBase):
#     class Meta:
# class ProductFlag(IncludedProductCondition, FlagBase):
#     class Meta:
# class CategoryFlag(FlagBase):
#     class Meta:
# class VoucherFlag(VoucherCondition, FlagBase):
#     class Meta:
# class SpeakerFlag(SpeakerCondition, FlagBase):
#     class Meta:
# class GroupMemberFlag(GroupMemberCondition, FlagBase):
#     class Meta:
#     def __str__(self):
#     def effects(self):
#     def __str__(self):
#     def clean(self):
#     def __str__(self):
#     def clean(self):
#     def __str__(self):
#     def effects(self):
#     def is_disable_if_false(self):
#     def is_enable_if_true(self):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     DISABLE_IF_FALSE = 1
#     ENABLE_IF_TRUE = 2


from django.db.models import Case
from django.db.models import F, Q
from django.db.models import Sum
from django.db.models import Value
from django.db.models import When
from django.utils import timezone
from registrasion.models import commerce
from registrasion.models import conditions
    @classmethod
    def _calculate_quantities(cls, user):
        reserved_carts = cls._relevant_carts(user)

        # Calculate category lines
        item_cats = F('categories__product__productitem__product__category')
        reserved_category_products = (
            Q(categories=item_cats) &
            Q(categories__product__productitem__cart__in=reserved_carts)
        )

        # Calculate product lines
        reserved_products = (
            Q(products=F('products__productitem__product')) &
            Q(products__productitem__cart__in=reserved_carts)
        )

        category_quantity_in_reserved_carts = When(
            reserved_category_products,
            then="categories__product__productitem__quantity",
        )

        product_quantity_in_reserved_carts = When(
            reserved_products,
            then="products__productitem__quantity",
        )

        quantity_or_zero = Case(
            category_quantity_in_reserved_carts,
            product_quantity_in_reserved_carts,

# 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/conditions.py
# class TimeOrStockLimitCondition(models.Model):
#     class Meta:
# class VoucherCondition(models.Model):
#     class Meta:
# class IncludedProductCondition(models.Model):
#     class Meta:
# class SpeakerCondition(models.Model):
#     class Meta:
# class GroupMemberCondition(models.Model):
#     class Meta:
# class DiscountBase(models.Model):
#     class Meta:
# class DiscountForProduct(models.Model):
#     class Meta:
# class DiscountForCategory(models.Model):
#     class Meta:
# class TimeOrStockLimitDiscount(TimeOrStockLimitCondition, DiscountBase):
#     class Meta:
# class VoucherDiscount(VoucherCondition, DiscountBase):
#     class Meta:
# class IncludedProductDiscount(IncludedProductCondition, DiscountBase):
#     class Meta:
# class SpeakerDiscount(SpeakerCondition, DiscountBase):
#     class Meta:
# class GroupMemberDiscount(GroupMemberCondition, DiscountBase):
#     class Meta:
# class FlagBase(models.Model):
# class TimeOrStockLimitFlag(TimeOrStockLimitCondition, FlagBase):
#     class Meta:
# class ProductFlag(IncludedProductCondition, FlagBase):
#     class Meta:
# class CategoryFlag(FlagBase):
#     class Meta:
# class VoucherFlag(VoucherCondition, FlagBase):
#     class Meta:
# class SpeakerFlag(SpeakerCondition, FlagBase):
#     class Meta:
# class GroupMemberFlag(GroupMemberCondition, FlagBase):
#     class Meta:
#     def __str__(self):
#     def effects(self):
#     def __str__(self):
#     def clean(self):
#     def __str__(self):
#     def clean(self):
#     def __str__(self):
#     def effects(self):
#     def is_disable_if_false(self):
#     def is_enable_if_true(self):
#     def __str__(self):
#     def __str__(self):
#     def __str__(self):
#     DISABLE_IF_FALSE = 1
#     ENABLE_IF_TRUE = 2


# Path: registrasion/controllers/conditions.py
from django.db.models import Case
from django.db.models import F, Q
from django.db.models import Sum
from django.db.models import Value
from django.db.models import When
from django.utils import timezone
from registrasion.models import commerce
from registrasion.models import conditions

    @classmethod
    def _calculate_quantities(cls, user):
        reserved_carts = cls._relevant_carts(user)

        # Calculate category lines
        item_cats = F('categories__product__productitem__product__category')
        reserved_category_products = (
            Q(categories=item_cats) &
            Q(categories__product__productitem__cart__in=reserved_carts)
        )

        # Calculate product lines
        reserved_products = (
            Q(products=F('products__productitem__product')) &
            Q(products__productitem__cart__in=reserved_carts)
        )

        category_quantity_in_reserved_carts = When(
            reserved_category_products,
            then="categories__product__productitem__quantity",
        )

        product_quantity_in_reserved_carts = When(
            reserved_products,
            then="products__productitem__quantity",
        )

        quantity_or_zero = Case(
            category_quantity_in_reserved_carts,
            product_quantity_in_reserved_carts,

            default=Value(0),