|
@@ -2,8 +2,46 @@ from django.contrib.auth.models import User
|
2
|
2
|
from django.db import models
|
3
|
3
|
from django.utils.translation import ugettext as _
|
4
|
4
|
|
|
5
|
+class ConditionalOffer(models.Model):
|
|
6
|
+ name = models.CharField(max_length=128)
|
|
7
|
+ description = models.TextField(blank=True)
|
|
8
|
+ condition = models.ForeignKey('offer.Condition')
|
|
9
|
+ benefit = models.ForeignKey('offer.Benefit')
|
|
10
|
+ start_date = models.DateField()
|
|
11
|
+ # Offers can be open-ended
|
|
12
|
+ end_date = models.DateField(blank=True)
|
|
13
|
+ priority = models.IntegerField()
|
|
14
|
+ created_date = models.DateTimeField(auto_now_add=True)
|
|
15
|
+
|
|
16
|
+class Condition(models.Model):
|
|
17
|
+ COUNT, VALUE = ("Count", "Value")
|
|
18
|
+ TYPE_CHOICES = (
|
|
19
|
+ (COUNT, _("Depends on number of items in basket that are in condition range")),
|
|
20
|
+ (VALUE, _("Depends on value of items in basket that are in condition range")),
|
|
21
|
+ )
|
|
22
|
+ range = models.ForeignKey('offer.Range')
|
|
23
|
+ type = models.CharField(max_length=128, choices=TYPE_CHOICES)
|
|
24
|
+ value = models.FloatField()
|
|
25
|
+
|
|
26
|
+class Benefit(models.Model):
|
|
27
|
+ PERCENTAGE, FIXED = ("Percentage", "Absolute")
|
|
28
|
+ TYPE_CHOICES = (
|
|
29
|
+ (PERCENTAGE, _("Discount is a % of the product's value")),
|
|
30
|
+ (FIXED, _("Discount is a fixed amount off the product's value")),
|
|
31
|
+ )
|
|
32
|
+ range = models.ForeignKey('offer.Range')
|
|
33
|
+ type = models.CharField(max_length=128, choices=TYPE_CHOICES)
|
|
34
|
+ value = models.FloatField()
|
|
35
|
+
|
|
36
|
+class Range(models.Model):
|
|
37
|
+ name = models.CharField(max_length=128)
|
|
38
|
+
|
5
|
39
|
class Voucher(models.Model):
|
|
40
|
+ """
|
|
41
|
+ A voucher
|
|
42
|
+ """
|
6
|
43
|
code = models.CharField(max_length=128)
|
7
|
44
|
start_date = models.DateField()
|
8
|
45
|
end_date = models.DateField()
|
|
46
|
+ offers = models.ManyToManyField('offer.ConditionalOffer')
|
9
|
47
|
created_date = models.DateTimeField(auto_now_add=True)
|