|
@@ -6,6 +6,24 @@ from django.db import models
|
|
from .validators import less_than_one
|
|
from .validators import less_than_one
|
|
|
|
|
|
|
|
|
|
|
|
+class Document(models.Model):
|
|
|
|
+ """ A document is a scenario or a record from facts, on 1 month.
|
|
|
|
+ """
|
|
|
|
+ TYPE_FACT = 'fact'
|
|
|
|
+ TYPE_PLAN = 'plan'
|
|
|
|
+
|
|
|
|
+ name = models.CharField(max_length=130)
|
|
|
|
+ comment = models.TextField(blank=True)
|
|
|
|
+ date = models.DateField(auto_now_add=True)
|
|
|
|
+ type = models.CharField(max_length=10, choices=(
|
|
|
|
+ (TYPE_FACT, 'relevé'),
|
|
|
|
+ (TYPE_PLAN, 'scénario/estimation'),
|
|
|
|
+ ))
|
|
|
|
+
|
|
|
|
+ def __str__(self):
|
|
|
|
+ return '{} {:%b %Y}'.format(self.name, self.date)
|
|
|
|
+
|
|
|
|
+
|
|
class AbstractItem(models.Model):
|
|
class AbstractItem(models.Model):
|
|
name = models.CharField(max_length=130)
|
|
name = models.CharField(max_length=130)
|
|
description = models.TextField(blank=True)
|
|
description = models.TextField(blank=True)
|
|
@@ -36,7 +54,16 @@ class AbstractItem(models.Model):
|
|
abstract = True
|
|
abstract = True
|
|
|
|
|
|
|
|
|
|
-class Cost(AbstractItem):
|
|
|
|
|
|
+class AbstractCostingItem(AbstractItem):
|
|
|
|
+ """ A costing item, linked to a document
|
|
|
|
+ """
|
|
|
|
+ document = models.ForeignKey(Document)
|
|
|
|
+
|
|
|
|
+ class Meta:
|
|
|
|
+ abstract = True
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+class Cost(AbstractCostingItem):
|
|
""" A monthtly cost we have to pay
|
|
""" A monthtly cost we have to pay
|
|
"""
|
|
"""
|
|
price = models.FloatField(help_text="Coût mensuel")
|
|
price = models.FloatField(help_text="Coût mensuel")
|
|
@@ -48,7 +75,7 @@ class Cost(AbstractItem):
|
|
verbose_name = 'Coût'
|
|
verbose_name = 'Coût'
|
|
|
|
|
|
|
|
|
|
-class Good(AbstractItem):
|
|
|
|
|
|
+class Good(AbstractCostingItem):
|
|
""" A good, which replacement is provisioned
|
|
""" A good, which replacement is provisioned
|
|
"""
|
|
"""
|
|
price = models.FloatField()
|
|
price = models.FloatField()
|
|
@@ -127,3 +154,11 @@ class Service(AbstractItem):
|
|
|
|
|
|
def get_absolute_url(self):
|
|
def get_absolute_url(self):
|
|
return reverse('detail-service', kwargs={'pk': self.pk})
|
|
return reverse('detail-service', kwargs={'pk': self.pk})
|
|
|
|
+
|
|
|
|
+ def document(self):
|
|
|
|
+ if self.costs.exists():
|
|
|
|
+ return self.costs.first().document
|
|
|
|
+ elif self.goods.exists():
|
|
|
|
+ return self.costs.first().document
|
|
|
|
+ else:
|
|
|
|
+ return None
|