109 lines
3.2 KiB
Python
109 lines
3.2 KiB
Python
from django.db import models
|
|
|
|
from colorfield.fields import ColorField
|
|
|
|
|
|
class Fournée(models.Model):
|
|
class Meta:
|
|
ordering = ["-date"]
|
|
|
|
date = models.DateField()
|
|
pour = models.CharField(max_length=64)
|
|
|
|
def __str__(self):
|
|
return f"Fournée du {self.date: %d-%m-%Y} pour {self.pour}"
|
|
|
|
def masse_commandée(self, pâte_id):
|
|
"Renvoie la masse commandée d'une pâte donnée"
|
|
poids_qté = (
|
|
self.commande_set.exclude(réservation=None)
|
|
.filter(réservation__pain__pâte_id=pâte_id)
|
|
.values('réservation__pain__poids', 'réservation__quantité')
|
|
)
|
|
return sum([
|
|
c['réservation__quantité'] * c['réservation__pain__poids']
|
|
for c in poids_qté
|
|
])
|
|
|
|
class Ingrédient(models.Model):
|
|
class Meta:
|
|
ordering = ["ordre", "-quantité"]
|
|
|
|
recette = models.ForeignKey("Recette", on_delete=models.CASCADE)
|
|
nom = models.CharField(max_length=64)
|
|
quantité = models.DecimalField(max_digits=6, decimal_places=3)
|
|
ordre = models.SmallIntegerField(default=0)
|
|
couleur = ColorField(default='#FFFFFF')
|
|
|
|
def __str__(self):
|
|
return f"{self.nom} ({self.quantité} kg)"
|
|
|
|
|
|
class Recette(models.Model):
|
|
class Meta:
|
|
ordering = ["ordre", "nom"]
|
|
|
|
nom = models.CharField(max_length=64)
|
|
poids_de_base = models.DecimalField(max_digits=6, decimal_places=3)
|
|
ordre = models.SmallIntegerField(default=0)
|
|
|
|
def __str__(self):
|
|
return self.nom
|
|
|
|
|
|
class Pain(models.Model):
|
|
class Meta:
|
|
ordering = ["pâte", "-poids", "moulé"]
|
|
|
|
nom = models.CharField(max_length=64)
|
|
pâte = models.ForeignKey("Recette", on_delete=models.CASCADE)
|
|
poids = models.DecimalField(max_digits=6, decimal_places=3)
|
|
moulé = models.BooleanField()
|
|
|
|
def __str__(self):
|
|
return self.nom
|
|
|
|
|
|
class Réservation(models.Model):
|
|
class Meta:
|
|
ordering = ["pain", "commande__pour", "commande__fournée__date"]
|
|
|
|
quantité = models.DecimalField(max_digits=6, decimal_places=3)
|
|
pain = models.ForeignKey("Pain", on_delete=models.CASCADE)
|
|
commande = models.ForeignKey("Commande", on_delete=models.CASCADE)
|
|
|
|
def __str__(self):
|
|
return f"{self.quantité.normalize()} {self.pain}"
|
|
|
|
|
|
class Commande(models.Model):
|
|
class Meta:
|
|
ordering = ["pour"]
|
|
|
|
pour = models.CharField(max_length=64)
|
|
pains = models.ManyToManyField("Pain", through="Réservation")
|
|
fournée = models.ForeignKey("Fournée", on_delete=models.CASCADE)
|
|
|
|
def __str__(self):
|
|
details = ""
|
|
if self.id and self.réservation_set.exists():
|
|
details = " (" + ", ".join(
|
|
[str(r) for r in self.réservation_set.all()]
|
|
) + ")"
|
|
return f"{self.pour}" + details
|
|
|
|
|
|
class Coulée(models.Model):
|
|
class Meta:
|
|
ordering = ["fournée__date", "ordre", "quantité", "pâte"]
|
|
|
|
ordre = models.SmallIntegerField(default=0)
|
|
quantité = models.DecimalField(max_digits=6, decimal_places=3)
|
|
pâte = models.ForeignKey("Recette", on_delete=models.CASCADE)
|
|
fournée = models.ForeignKey("Fournée", on_delete=models.CASCADE)
|
|
|
|
def __str__(self):
|
|
return f"{self.pâte} ({self.quantité.normalize()} kg)"
|
|
|
|
|