|
|
@@ -7,6 +7,7 @@ from django.utils.translation import ugettext as _
|
|
7
|
7
|
|
|
8
|
8
|
from oscar.offer.managers import ActiveOfferManager
|
|
9
|
9
|
|
|
|
10
|
+SITE, VOUCHER, USER, SESSION = ("Site", "Voucher", "User", "Session")
|
|
10
|
11
|
|
|
11
|
12
|
class AbstractConditionalOffer(models.Model):
|
|
12
|
13
|
u"""
|
|
|
@@ -24,7 +25,6 @@ class AbstractConditionalOffer(models.Model):
|
|
24
|
25
|
# to apply this offer needs to be coded
|
|
25
|
26
|
# (d) Session offers - these are temporarily available to a user after some trigger
|
|
26
|
27
|
# event. Eg, users coming from some affiliate site get 10% off.
|
|
27
|
|
- SITE, VOUCHER, USER, SESSION = ("Site", "Voucher", "User", "Session")
|
|
28
|
28
|
TYPE_CHOICES = (
|
|
29
|
29
|
(SITE, "Site offer - available to all users"),
|
|
30
|
30
|
(VOUCHER, "Voucher offer - only available after entering the appropriate voucher code"),
|
|
|
@@ -33,8 +33,8 @@ class AbstractConditionalOffer(models.Model):
|
|
33
|
33
|
)
|
|
34
|
34
|
offer_type = models.CharField(_("Type"), choices=TYPE_CHOICES, default=SITE, max_length=128)
|
|
35
|
35
|
|
|
36
|
|
- condition = models.OneToOneField('offer.Condition')
|
|
37
|
|
- benefit = models.OneToOneField('offer.Benefit')
|
|
|
36
|
+ condition = models.ForeignKey('offer.Condition')
|
|
|
37
|
+ benefit = models.ForeignKey('offer.Benefit')
|
|
38
|
38
|
|
|
39
|
39
|
# Range of availability. Note that if this is a voucher offer, then these
|
|
40
|
40
|
# dates are ignored and only the dates from the voucher are used to determine
|
|
|
@@ -215,7 +215,8 @@ class AbstractVoucher(models.Model):
|
|
215
|
215
|
help_text="""This will be shown in the checkout and basket once the voucher is entered""")
|
|
216
|
216
|
code = models.CharField(_("Code"), max_length=128, db_index=True, unique=True,
|
|
217
|
217
|
help_text="""Case insensitive / No spaces allowed""")
|
|
218
|
|
- offers = models.ManyToManyField('offer.ConditionalOFfer', related_name='vouchers')
|
|
|
218
|
+ offers = models.ManyToManyField('offer.ConditionalOFfer', related_name='vouchers',
|
|
|
219
|
+ limit_choices_to={'offer_type': VOUCHER})
|
|
219
|
220
|
|
|
220
|
221
|
SINGLE_USE, MULTI_USE, ONCE_PER_CUSTOMER = ('Single use', 'Multi-use', 'Once per customer')
|
|
221
|
222
|
USAGE_CHOICES = (
|
|
|
@@ -277,11 +278,11 @@ class AbstractVoucher(models.Model):
|
|
277
|
278
|
message = "You have already used this voucher in a previous order"
|
|
278
|
279
|
return is_available, message
|
|
279
|
280
|
|
|
280
|
|
- def record_usage(self, user):
|
|
|
281
|
+ def record_usage(self, order, user):
|
|
281
|
282
|
u"""
|
|
282
|
283
|
Records a usage of this voucher in an order.
|
|
283
|
284
|
"""
|
|
284
|
|
- self.applications.create(voucher=self, user=user)
|
|
|
285
|
+ self.applications.create(voucher=self, order=order, user=user)
|
|
285
|
286
|
|
|
286
|
287
|
|
|
287
|
288
|
class AbstractVoucherApplication(models.Model):
|
|
|
@@ -292,6 +293,7 @@ class AbstractVoucherApplication(models.Model):
|
|
292
|
293
|
# It is possible for an anonymous user to apply a voucher so we need to allow
|
|
293
|
294
|
# the user to be nullable
|
|
294
|
295
|
user = models.ForeignKey('auth.User', blank=True, null=True)
|
|
|
296
|
+ order = models.ForeignKey('order.Order')
|
|
295
|
297
|
date_created = models.DateField(auto_now_add=True)
|
|
296
|
298
|
|
|
297
|
299
|
class Meta:
|