Models¶
shopkit.discounts.advanced.models
Model base and mixin classes for building discount model and logic.
Todo
Provide a listing/overview of the types of DiscountMixin’s available, how they should be used and... whether they have been tested or not.
-
class
shopkit.discounts.advanced.models.discount_models.AccountedUseDiscountMixin(*args, **kwargs)¶ Bases:
django.db.models.base.ModelMixin class for discounts for which the number of uses is accounted.
-
classmethod
register_use(qs, count=1)¶ Register count uses of discounts in queryset qs.
-
classmethod
-
class
shopkit.discounts.advanced.models.discount_models.CategoryDiscountMixin(*args, **kwargs)¶ Bases:
django.db.models.base.ModelMixin defining discounts based on a single category.
-
classmethod
get_valid_discounts(**kwargs)¶ Return valid discounts for a specified product
-
classmethod
-
class
shopkit.discounts.advanced.models.discount_models.CouponDiscountMixin(*args, **kwargs)¶ Bases:
django.db.models.base.ModelDiscount based on a specified coupon code.
-
static
generate_coupon_code()¶ Generate a coupon code of COUPON_LENGHT characters consisting of the characters in COUPON_CHARACTERS.
Todo
Unittest this function.
-
classmethod
get_valid_discounts(coupon_code=None, **kwargs)¶ Return only items for which no coupon code has been set or ones for which the current coupon code matches that of the discounts.
-
static
-
class
shopkit.discounts.advanced.models.discount_models.DateRangeDiscountMixin(*args, **kwargs)¶ Bases:
django.db.models.base.ModelMixin for discount which are only valid within a given date range.
-
classmethod
get_valid_discounts(**kwargs)¶ Return valid discounts for a specified date, taking the current date if no date is specified. When no start or end date are specified, a discount defaults to be valid.
Todo
Test this code.
-
classmethod
-
class
shopkit.discounts.advanced.models.discount_models.DiscountBase(*args, **kwargs)¶ Bases:
django.db.models.base.ModelBase class for discounts.
-
classmethod
get_all_discounts()¶ Get all discounts, whether valid or not.
-
get_discount(**kwargs)¶ Get the total amount of discount produced by this Discount. This method should be implemented by subclasses of :class:DiscountBase.
-
classmethod
get_valid_discounts(**kwargs)¶ Get all valid discount objects for a given kwargs. By default, all discounts are invalid.
-
is_valid(**kwargs)¶ Check to see whether an individual discount is valid under the given circumstances.
-
classmethod
-
class
shopkit.discounts.advanced.models.discount_models.ItemDiscountAmountMixin(*args, **kwargs)¶ Bases:
django.db.models.base.ModelMixin for absolute amount discounts, valid only for the particular items in this order.
-
get_discount(**kwargs)¶ Get the total amount of discount for the current item.
-
classmethod
get_valid_discounts(**kwargs)¶ We want to be able to discriminate between discounts valid for the whole order and those valid for order items.
Parameters: item_discounts – When True, only items for which item_amount has been specified are valid. When False, only items which have no item_amount specified are let through.
-
-
class
shopkit.discounts.advanced.models.discount_models.ItemDiscountPercentageMixin(*args, **kwargs)¶ Bases:
django.db.models.base.ModelMixin for percentual discounts, valid only for the particular items in this order.
-
get_discount(**kwargs)¶ Get the total amount of discount for the current item.
-
classmethod
get_valid_discounts(**kwargs)¶ We want to be able to discriminate between discounts valid for the whole order and those valid for order items.
Parameters: item_discounts – When True, only items for which item_amount has been specified are valid. When False, only items which have no item_amount specified are let through.
-
-
class
shopkit.discounts.advanced.models.discount_models.LimitedUseDiscountMixin(*args, **kwargs)¶ Bases:
shopkit.discounts.advanced.models.discount_models.AccountedUseDiscountMixinMixin class for discounts which can only be used a limited number of times.
-
get_uses_left()¶ Return the amount of uses left.
-
classmethod
get_valid_discounts(**kwargs)¶ Return currently valid discounts: ones for which either no use limit has been set or for which the amount of uses lies under the limit.
-
-
class
shopkit.discounts.advanced.models.discount_models.ManyCategoryDiscountMixin(*args, **kwargs)¶ Bases:
django.db.models.base.ModelMixin defining discounts based on a collection of categories.
Todo
Test this! There are likely to be bugs...
-
classmethod
get_valid_discounts(**kwargs)¶ Return valid discounts for a specified product
-
classmethod
-
class
shopkit.discounts.advanced.models.discount_models.ManyProductDiscountMixin(*args, **kwargs)¶ Bases:
django.db.models.base.ModelMixin defining discounts based on products.
-
classmethod
get_valid_discounts(**kwargs)¶ Return valid discounts for a specified product
-
classmethod
-
class
shopkit.discounts.advanced.models.discount_models.OrderDiscountAmountMixin(*args, **kwargs)¶ Bases:
django.db.models.base.ModelMixin for absolute amount discounts which act on the total price for an order.
-
get_discount(**kwargs)¶ Get the total amount of discount for the current item.
-
classmethod
get_valid_discounts(**kwargs)¶ We want to be able to discriminate between discounts valid for the whole order and those valid for order items.
Parameters: order_discounts – When True, only items for which order_amount has been specified are valid. When False, only items which have no order_amount specified are let through.
-
-
class
shopkit.discounts.advanced.models.discount_models.OrderDiscountPercentageMixin(*args, **kwargs)¶ Bases:
django.db.models.base.ModelMixin for discounts which apply as a percentage from the total order amount.
-
get_discount(**kwargs)¶ Get the total amount of discount for the current item.
-
classmethod
get_valid_discounts(**kwargs)¶ We want to be able to discriminate between discounts valid for the whole order and those valid for order items.
Parameters: order_discounts – When True, only items for which order_amount has been specified are valid. When False, only items which have no order_amount specified are let through.
-
-
class
shopkit.discounts.advanced.models.discount_models.ProductDiscountMixin(*args, **kwargs)¶ Bases:
django.db.models.base.ModelMixin defining a discount valid for a single product.
Todo
Test this! There are likely to be bugs...
-
classmethod
get_valid_discounts(**kwargs)¶ Return valid discounts for a specified product
-
classmethod
Model base and mixin classes for carts and orders with calculated discounts.
Todo
Provide a listing/overview of the types of DiscountMixin’s available, how they should be used and... whether they have been tested or not.
-
class
shopkit.discounts.advanced.models.order_models.AccountedDiscountedItemMixin¶ Bases:
objectModel mixin class for orders for which the use is automatically accounted upon confirmation.
-
confirm()¶ Register discount usage.
-
-
class
shopkit.discounts.advanced.models.order_models.CalculatedDiscountMixin¶ Bases:
objectBase class for items for which the discount is calculated using a Discount model.
-
get_valid_discounts(**kwargs)¶ Return valid discounts for the given arguments.
-
-
class
shopkit.discounts.advanced.models.order_models.CalculatedItemDiscountMixin¶ Bases:
shopkit.discounts.advanced.models.order_models.CalculatedDiscountMixinMixin class for discounted objects for which an item discount can be calculated by calling get_order_discount and valid discounts can be obtained by calling get_valid_discounts.
-
get_item_discount(**kwargs)¶ Get the total discount for this OrderItem.
-
get_piece_discount(**kwargs)¶ Get the total discount per piece for this OrderItem.
-
get_valid_discounts(**kwargs)¶ Return valid discounts for the current order.
-
-
class
shopkit.discounts.advanced.models.order_models.CalculatedOrderDiscountMixin¶ Bases:
shopkit.discounts.advanced.models.order_models.CalculatedDiscountMixinMixin class for discounted objects for which an order discount can be calculated by calling get_order_discount and valid discounts can be obtained by calling get_valid_discounts.
-
get_order_discount(**kwargs)¶ Get the discount specific for this Order.
-
get_valid_discounts(**kwargs)¶ Return valid discounts for the current order.
-
-
class
shopkit.discounts.advanced.models.order_models.DiscountCouponItemMixin(*args, **kwargs)¶ Bases:
django.db.models.base.ModelModel mixin class for order or cart items for which discounts are calculated based on a coupon code.
-
get_valid_discounts(**kwargs)¶ Return valid discounts for the current item.
-
-
class
shopkit.discounts.advanced.models.order_models.DiscountCouponMixin(*args, **kwargs)¶ Bases:
django.db.models.base.ModelModel mixin class for orders or cart for which discounts are calculated based on a given coupon code.
-
get_valid_discounts(**kwargs)¶ Return valid discounts for the current order.
-
-
class
shopkit.discounts.advanced.models.order_models.DiscountedCartItemMixin(*args, **kwargs)¶ Bases:
shopkit.discounts.advanced.models.order_models.CalculatedItemDiscountMixin,shopkit.discounts.basemodels.DiscountedCartItemBaseMixin class for Cart objects which have their discount calculated.
-
class
shopkit.discounts.advanced.models.order_models.DiscountedCartMixin(*args, **kwargs)¶ Bases:
shopkit.discounts.advanced.models.order_models.CalculatedOrderDiscountMixin,shopkit.discounts.basemodels.DiscountedCartBaseMixin class for Cart objects which have their discount calculated.
-
class
shopkit.discounts.advanced.models.order_models.DiscountedOrderItemMixin(*args, **kwargs)¶ Bases:
shopkit.discounts.advanced.models.order_models.CalculatedItemDiscountMixin,shopkit.discounts.advanced.models.order_models.PersistentDiscountedItemBase,shopkit.discounts.basemodels.DiscountedOrderItemBaseMixin class for OrderItem objects which have their discount calculated.
-
class
shopkit.discounts.advanced.models.order_models.DiscountedOrderMixin(*args, **kwargs)¶ Bases:
shopkit.discounts.advanced.models.order_models.PersistentDiscountedItemBase,shopkit.discounts.basemodels.DiscountedOrderBase,shopkit.discounts.advanced.models.order_models.CalculatedOrderDiscountMixinMixin class for Order objects which have their discount calculated.
-
class
shopkit.discounts.advanced.models.order_models.PersistentDiscountedItemBase(*args, **kwargs)¶ Bases:
django.db.models.base.ModelMixin class for Order‘s and OrderItem‘s for which calculated discounts are persistently stored in a discounts property upon calling the update_discount method.
-
update_discount()¶ Call update_discount on the superclass to calculate the amount of discount, then store valid Discount objects for this order item.
-