2024-05-15 12:38:38 +02:00
|
|
|
from uuid import uuid4
|
|
|
|
|
2024-04-30 12:27:17 +02:00
|
|
|
from django.db import models
|
|
|
|
|
2024-05-13 22:02:49 +02:00
|
|
|
from colorfield.fields import ColorField
|
|
|
|
|
2024-05-15 15:50:11 +02:00
|
|
|
from .utils import clean
|
|
|
|
|
2024-04-30 12:27:17 +02:00
|
|
|
|
2024-05-15 12:38:38 +02:00
|
|
|
def upload_to(instance, filename):
|
|
|
|
return "{}/{}".format(uuid4(), filename)
|
|
|
|
|
|
|
|
|
2024-04-30 12:27:17 +02:00
|
|
|
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"
|
2024-05-13 22:09:10 +02:00
|
|
|
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é
|
|
|
|
])
|
2024-04-30 12:27:17 +02:00
|
|
|
|
2024-05-14 10:00:02 +02:00
|
|
|
|
2024-05-15 12:38:38 +02:00
|
|
|
class Document(models.Model):
|
|
|
|
class Meta:
|
|
|
|
ordering = ["nom"]
|
|
|
|
|
|
|
|
fourniture = models.ForeignKey("Fourniture", on_delete=models.CASCADE)
|
2024-05-16 08:54:05 +02:00
|
|
|
nom = models.CharField(max_length=64)
|
2024-05-15 12:38:38 +02:00
|
|
|
fichier = models.FileField(upload_to=upload_to)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return f"{self.nom}"
|
|
|
|
|
|
|
|
|
2024-05-14 10:00:02 +02:00
|
|
|
class Fourniture(models.Model):
|
|
|
|
class Meta:
|
|
|
|
ordering = ["ordre"]
|
|
|
|
|
2024-05-14 12:57:26 +02:00
|
|
|
nom = models.CharField(max_length=64, unique=True)
|
2024-05-14 10:00:02 +02:00
|
|
|
ordre = models.SmallIntegerField(default=0)
|
|
|
|
couleur = ColorField(default='#000000')
|
2024-05-15 12:39:18 +02:00
|
|
|
conditionnement = models.DecimalField(
|
|
|
|
max_digits=6, decimal_places=3, default=0
|
|
|
|
)
|
2024-05-14 19:35:42 +02:00
|
|
|
emballage = models.CharField(max_length=64, blank=True)
|
2024-05-14 10:00:02 +02:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return f"{self.nom}"
|
|
|
|
|
|
|
|
|
2024-04-30 12:27:17 +02:00
|
|
|
class Ingrédient(models.Model):
|
|
|
|
class Meta:
|
2024-05-14 10:00:02 +02:00
|
|
|
ordering = ["fourniture__ordre", "-quantité"]
|
2024-04-30 12:27:17 +02:00
|
|
|
|
|
|
|
recette = models.ForeignKey("Recette", on_delete=models.CASCADE)
|
2024-05-14 10:03:00 +02:00
|
|
|
fourniture = models.ForeignKey("Fourniture", on_delete=models.CASCADE)
|
2024-04-30 12:27:17 +02:00
|
|
|
quantité = models.DecimalField(max_digits=6, decimal_places=3)
|
|
|
|
|
|
|
|
def __str__(self):
|
2024-05-15 15:50:11 +02:00
|
|
|
return f"{self.fourniture.nom} ({clean(self.quantité)} kg)"
|
2024-04-30 12:27:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Recette(models.Model):
|
|
|
|
class Meta:
|
2024-05-12 22:26:26 +02:00
|
|
|
ordering = ["ordre", "nom"]
|
2024-04-30 12:27:17 +02:00
|
|
|
|
|
|
|
nom = models.CharField(max_length=64)
|
|
|
|
poids_de_base = models.DecimalField(max_digits=6, decimal_places=3)
|
2024-05-12 22:26:26 +02:00
|
|
|
ordre = models.SmallIntegerField(default=0)
|
2024-04-30 12:27:17 +02:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.nom
|
|
|
|
|
|
|
|
|
|
|
|
class Pain(models.Model):
|
|
|
|
class Meta:
|
2024-05-12 22:26:26 +02:00
|
|
|
ordering = ["pâte", "-poids", "moulé"]
|
2024-04-30 12:27:17 +02:00
|
|
|
|
|
|
|
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):
|
2024-05-15 15:50:11 +02:00
|
|
|
return f"{clean(self.quantité)} {self.pain}"
|
2024-04-30 12:27:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
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):
|
2024-05-15 15:50:11 +02:00
|
|
|
return f"{self.pâte} ({clean(self.quantité)} kg)"
|
2024-04-30 12:27:17 +02:00
|
|
|
|
|
|
|
|