|
@@ -1,4 +1,60 @@
|
1
|
1
|
from django.db import models
|
2
|
2
|
|
3
|
|
-
|
4
|
|
-
|
|
3
|
+class AttributeType(models.Model):
|
|
4
|
+ """Defines a product atrribute type"""
|
|
5
|
+ name = models.CharField(max_length = 128)
|
|
6
|
+
|
|
7
|
+ def __unicode__(self):
|
|
8
|
+ return self.name
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+class Type(models.Model):
|
|
12
|
+ """Defines a product type"""
|
|
13
|
+ name = models.CharField(max_length = 128)
|
|
14
|
+ attribute_types = models.ManyToManyField('product.AttributeType')
|
|
15
|
+
|
|
16
|
+ def __unicode__(self):
|
|
17
|
+ return self.name
|
|
18
|
+
|
|
19
|
+class Item(models.Model):
|
|
20
|
+ """The base product object"""
|
|
21
|
+ name = models.CharField(max_length = 128)
|
|
22
|
+ partner_id = models.CharField(max_length = 32)
|
|
23
|
+ type = models.ForeignKey('product.Type')
|
|
24
|
+ date_available = models.DateField()
|
|
25
|
+ date_created = models.DateTimeField()
|
|
26
|
+
|
|
27
|
+ def __unicode__(self):
|
|
28
|
+ return self.name
|
|
29
|
+
|
|
30
|
+ def is_valid(self):
|
|
31
|
+ """
|
|
32
|
+ Returns true if the product is valid.
|
|
33
|
+
|
|
34
|
+ Validity is based on whether the product has all required attribute types
|
|
35
|
+ configured for the product_class it is in.
|
|
36
|
+
|
|
37
|
+ Returns:
|
|
38
|
+ A boolean if the product is valid
|
|
39
|
+ """
|
|
40
|
+ required_attribute_names = []
|
|
41
|
+ for attribute_type in self.type.attribute_types.all():
|
|
42
|
+ required_attribute_names.append(attribute_type.name)
|
|
43
|
+
|
|
44
|
+ for attribute in self.attribute_set.all():
|
|
45
|
+ required_attribute_names.remove(attribute.attribute_type.name)
|
|
46
|
+
|
|
47
|
+ return 0 == len(required_attribute_names)
|
|
48
|
+
|
|
49
|
+class Attribute(models.Model):
|
|
50
|
+ """An individual product attribute"""
|
|
51
|
+ attribute_type = models.ForeignKey('product.AttributeType')
|
|
52
|
+ product = models.ForeignKey('product.Item')
|
|
53
|
+ value = models.CharField(max_length = 256)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+class StockRecord(models.Model):
|
|
57
|
+ """A stock keeping record"""
|
|
58
|
+ product = models.ForeignKey('product.Item')
|
|
59
|
+ price_excl_tax = models.FloatField()
|
|
60
|
+ tax = models.FloatField()
|