@@ -354,141 +354,154 @@ class IncludedProductDiscount(DiscountBase):
enabling_products = models.ManyToManyField(
Product,
verbose_name=_("Including product"),
help_text=_("If one of these products are purchased, the discounts "
"below will be enabled."),
)
class RoleDiscount(object):
''' Discounts that are enabled because the active user has a specific
role. This is for e.g. volunteers who can get a discount ticket. '''
# TODO: implement RoleDiscount
pass
@python_2_unicode_compatible
class EnablingConditionBase(models.Model):
''' This defines a condition which allows products or categories to
be made visible. If there is at least one mandatory enabling condition
defined on a Product or Category, it will only be enabled if *all*
mandatory conditions are met, otherwise, if there is at least one enabling
condition defined on a Product or Category, it will only be enabled if at
least one condition is met. '''
# TODO: rename to EnablingConditionBase once https://code.djangoproject.com/ticket/26488
# is solved.
# TODO: rename to EnablingConditionBase once
# https://code.djangoproject.com/ticket/26488 is solved.
objects = InheritanceManager()
def __str__(self):
return self.description
def effects(self):
''' Returns all of the items enabled by this condition. '''
return itertools.chain(self.products.all(), self.categories.all())
description = models.CharField(max_length=255)
mandatory = models.BooleanField(
default=False,
help_text=_("If there is at least one mandatory condition defined on "
"a product or category, all such conditions must be met. "
"Otherwise, at least one non-mandatory condition must be "
"met."),
products = models.ManyToManyField(
blank=True,
help_text=_("Products that are enabled if this condition is met."),
categories = models.ManyToManyField(
Category,
help_text=_("Categories whose products are enabled if this condition "
"is met."),
class TimeOrStockLimitFlag(EnablingConditionBase):
''' Registration product ceilings '''
class Meta:
verbose_name = _("ceiling")
verbose_name = _("flag (time/stock limit)")
verbose_name_plural = _("flags (time/stock limit)")
start_time = models.DateTimeField(
null=True,
help_text=_("Products included in this condition will only be "
"available after this time."),
end_time = models.DateTimeField(
"available before this time."),
limit = models.PositiveIntegerField(
help_text=_("The number of items under this grouping that can be "
"purchased."),
class ProductFlag(EnablingConditionBase):
''' The condition is met because a specific product is purchased. '''
verbose_name = _("flag (dependency on product)")
verbose_name_plural = _("flags (dependency on product)")
return "Enabled by products: " + str(self.enabling_products.all())
help_text=_("If one of these products are purchased, this condition "
class CategoryFlag(EnablingConditionBase):
''' The condition is met because a product in a particular product is
purchased. '''
verbose_name = _("flag (dependency on product from category)")
verbose_name_plural = _("flags (dependency on product from category)")
return "Enabled by product in category: " + str(self.enabling_category)
enabling_category = models.ForeignKey(
help_text=_("If a product from this category is purchased, this "
"condition is met."),
class VoucherFlag(EnablingConditionBase):
''' The condition is met because a Voucher is present. This is for e.g.
enabling sponsor tickets. '''
verbose_name = _("flag (dependency on voucher)")
verbose_name_plural = _("flags (dependency on voucher)")
return "Enabled by voucher: %s" % self.voucher
voucher = models.OneToOneField(Voucher)
# @python_2_unicode_compatible
class RoleFlag(object):
''' The condition is met because the active user has a particular Role.
This is for e.g. enabling Team tickets. '''
# TODO: implement RoleFlag
# Commerce Models
class Cart(models.Model):
''' Represents a set of product items that have been purchased, or are
pending purchase. '''
index_together = [
("active", "time_last_updated"),