parachève la transformation des ingrédients
This commit is contained in:
parent
2026e7e40a
commit
01685b0bf7
@ -230,10 +230,13 @@ class FournéeAdmin(nested_admin.NestedModelAdmin):
|
||||
extra_context["coulées"] = []
|
||||
for c in obj.coulée_set.all():
|
||||
quantités = [c, ]
|
||||
ingrédients = c.pâte.ingrédient_set.values_list('nom', 'couleur')
|
||||
ingrédients = c.pâte.ingrédient_set.values_list(
|
||||
'fourniture__nom',
|
||||
'fourniture__couleur'
|
||||
)
|
||||
for i, _ in ingrédients:
|
||||
quantités.append((c.quantité / c.pâte.poids_de_base * sum(
|
||||
c.pâte.ingrédient_set.filter(nom=i)
|
||||
c.pâte.ingrédient_set.filter(fourniture__nom=i)
|
||||
.values_list("quantité", flat=True)
|
||||
)).quantize(Decimal('1.000')).normalize())
|
||||
|
||||
@ -259,9 +262,11 @@ class FournéeAdmin(nested_admin.NestedModelAdmin):
|
||||
|
||||
""" on créé un tableau total coulée / ingrédient """
|
||||
ingrédients = [
|
||||
models.Ingrédient.objects.filter(nom=nom).first()
|
||||
models.Fourniture.objects.filter(nom=nom).first()
|
||||
for nom in set(
|
||||
coulées.values_list("pâte__ingrédient__nom", flat=True)
|
||||
coulées.values_list(
|
||||
"pâte__ingrédient__fourniture__nom", flat=True
|
||||
)
|
||||
)
|
||||
]
|
||||
ingrédients.sort(key=lambda x: x.ordre)
|
||||
@ -276,7 +281,9 @@ class FournéeAdmin(nested_admin.NestedModelAdmin):
|
||||
total = sum([
|
||||
qté * qté_unit / unit
|
||||
for qté, qté_unit, unit in
|
||||
obj.coulée_set.filter(pâte__ingrédient__nom=i.nom)
|
||||
obj.coulée_set.filter(
|
||||
pâte__ingrédient__fourniture__nom=i.nom
|
||||
)
|
||||
.values_list(
|
||||
'quantité',
|
||||
'pâte__ingrédient__quantité',
|
||||
|
@ -36,4 +36,6 @@ class Migration(migrations.Migration):
|
||||
("core", "0008_fourniture_alter_ingrédient_options_and_more"),
|
||||
]
|
||||
|
||||
operations = [migrations.RunPython(ingredients_vers_fournitures, fournitures_vers_ingredients)]
|
||||
operations = [migrations.RunPython(
|
||||
ingredients_vers_fournitures, fournitures_vers_ingredients
|
||||
)]
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Generated by Django 4.2.13 on 2024-05-14 08:01
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
@ -43,11 +43,8 @@ class Ingrédient(models.Model):
|
||||
ordering = ["fourniture__ordre", "-quantité"]
|
||||
|
||||
recette = models.ForeignKey("Recette", on_delete=models.CASCADE)
|
||||
nom = models.CharField(max_length=64)
|
||||
fourniture = models.ForeignKey("Fourniture", on_delete=models.CASCADE)
|
||||
quantité = models.DecimalField(max_digits=6, decimal_places=3)
|
||||
ordre = models.SmallIntegerField(default=0)
|
||||
couleur = ColorField(default='#000000')
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.fourniture.nom} ({self.quantité} kg)"
|
||||
|
Loading…
Reference in New Issue
Block a user