Voucher¶
Oscar ships with broad support for vouchers, which are handled by this app.
In addition to individual vouchers, vouchers can also be managed as sets.
VoucherSets can typically be used for automatically generated vouchers based on loyalty criteria. They can also be used to quickly create a large set of vouchers with a shared condition and benefit. They also allow shared management of such sets, so you can easily extend, restrict, enable or disable them at once.
Abstract models¶
-
class
oscar.apps.voucher.abstract_models.
AbstractVoucher
(*args, **kwargs)[source]¶ A voucher. This is simply a link to a collection of offers.
Note that there are three possible “usage” modes: (a) Single use (b) Multi-use (c) Once per customer
Oscar enforces those modes by creating VoucherApplication instances when a voucher is used for an order.
-
property
benefit
¶ Returns the first offer’s benefit instance.
A voucher is commonly only linked to one offer. In that case, this helper can be used for convenience.
-
clean
()[source]¶ Hook for doing any extra model-wide validation after clean() has been called on every field by self.clean_fields. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.
-
is_available_for_basket
(basket)[source]¶ Tests whether this voucher is available to the passed basket.
Returns a tuple of a boolean for whether it is successful, and a availability message.
-
is_available_to_user
(user=None)[source]¶ Test whether this voucher is available to the passed user.
Returns a tuple of a boolean for whether it is successful, and a availability message.
-
save
(*args, **kwargs)[source]¶ Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
-
property
-
class
oscar.apps.voucher.abstract_models.
AbstractVoucherApplication
(*args, **kwargs)[source]¶ For tracking how often a voucher has been used in an order.
This is used to enforce the voucher usage mode in Voucher.is_available_to_user, and created in Voucher.record_usage.
-
class
oscar.apps.voucher.abstract_models.
AbstractVoucherSet
(*args, **kwargs)[source]¶ A collection of vouchers (potentially auto-generated)
a VoucherSet is a group of voucher that are generated automatically.
count: the minimum number of vouchers in the set. If this is kept at
zero, vouchers are created when and as needed.
code_length: the length of the voucher code. Codes are by default created
with groups of 4 characters: XXXX-XXXX-XXXX. The dashes (-) do not count for the code_length.
start_datetime
andend_datetime
together define the validity range for all vouchers in the set.
-
save
(*args, **kwargs)[source]¶ Save the current instance. Override this in a subclass if you want to control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.
Views¶
None.