Compare commits

...

2 Commits

5 changed files with 62 additions and 17 deletions

View File

@ -153,9 +153,9 @@ class FournéeAdmin(nested_admin.NestedModelAdmin):
"""Pour chaque pâte on regarde si les coulées sont complètes.
Si elles ne le sont pas, on ajoute ce qui manque."""
for pâte_id, pâte_nom in (
for pâte_id, pâte_nom, pâte_ordre in (
obj.commande_set.values_list(
"réservation__pain__pâte", "réservation__pain__pâte__nom"
"réservation__pain__pâte", "réservation__pain__pâte__nom", "réservation__pain__pâte__ordre"
)
.order_by("réservation__pain__pâte")
.distinct()
@ -169,7 +169,7 @@ class FournéeAdmin(nested_admin.NestedModelAdmin):
pâte_manquante = somme_commandée - somme_coulée
if pâte_manquante > 0:
obj.coulée_set.create(
pâte_id=pâte_id, quantité=pâte_manquante
pâte_id=pâte_id, quantité=pâte_manquante, ordre=pâte_ordre
)
self.message_user(
request,
@ -244,8 +244,8 @@ class FournéeAdmin(nested_admin.NestedModelAdmin):
)
extra_context["ingrédients"] = ingrédients
pains = set(obj.commande_set.exclude(réservation__isnull=True).values_list("pains__nom", flat=True))
totaux = []
pains = models.Pain.objects.filter(pk__in=obj.commande_set.exclude(réservation__isnull=True).values_list("pains", flat=True)).values_list("nom", flat=True)
totaux = [sum(obj.coulée_set.values_list('quantité', flat=True))]
for i, _ in ingrédients:
total = sum([
qté * qté_unit / unit
@ -277,7 +277,7 @@ class FournéeAdmin(nested_admin.NestedModelAdmin):
else:
tmp.append("")
extra_context["divisions"].append(tmp)
totaux = []
totaux = [sum(obj.coulée_set.values_list('quantité', flat=True))]
for p in pains:
total = sum(
obj.commande_set.filter(pains__nom=p).values_list(

View File

@ -0,0 +1,21 @@
# Generated by Django 4.2.11 on 2024-05-12 19:56
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("core", "0004_alter_ingrédient_options_ingrédient_ordre"),
]
operations = [
migrations.AlterModelOptions(
name="recette",
options={"ordering": ["ordre", "nom"]},
),
migrations.AddField(
model_name="recette",
name="ordre",
field=models.SmallIntegerField(default=0),
),
]

View File

@ -0,0 +1,16 @@
# Generated by Django 4.2.11 on 2024-05-12 20:34
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("core", "0005_alter_recette_options_recette_ordre"),
]
operations = [
migrations.AlterModelOptions(
name="pain",
options={"ordering": ["pâte", "-poids", "moulé"]},
),
]

View File

@ -31,10 +31,11 @@ class Ingrédient(models.Model):
class Recette(models.Model):
class Meta:
ordering = ["nom"]
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
@ -42,7 +43,7 @@ class Recette(models.Model):
class Pain(models.Model):
class Meta:
ordering = ["pâte", "poids", "moulé"]
ordering = ["pâte", "-poids", "moulé"]
nom = models.CharField(max_length=64)
pâte = models.ForeignKey("Recette", on_delete=models.CASCADE)

View File

@ -30,9 +30,12 @@
</thead>
<tbody>
<tr>
<th>Totaux</th>
{% for p in totaux_coulées %}
<th scope="col" style="text-align:center">{{ p }}</th>
{% if forloop.first %}
<th>Total pain : {{p}} kg</th>
{% else %}
<th scope="col" style="text-align:center">{{ p }}</th>
{% endif %}
{% endfor %}
</tr>
</tbody>
@ -72,17 +75,21 @@
<tr>
<th></th>
{% for problems, p in pains %}
<th scope="col"{% if problems %} style="color: var(--delete-button-hover-bg);"{% endif %}>{{ p }}{% if problems %}<br>sans coulée{% endif %}</th>
{% endfor %}
</tr>
<tr>
<th>Totaux</th>
{% for p in totaux_divisions %}
<th scope="col" style="text-align:center">{{ p }}</th>
<th scope="col" style="text-align:center{% if problems %}; color: var(--delete-button-hover-bg);{% endif %}">{{ p }}{% if problems %}<br>Sans coulée !!{% endif %}</th>
{% endfor %}
</tr>
</thead>
<tr>
{% for p in totaux_divisions %}
{% if forloop.first %}
<th>Total pain : {{p}} kg</th>
{% else %}
<th scope="col" style="text-align:center">{{ p }}</th>
{% endif %}
{% endfor %}
</tr>
<tbody>
<tr></tr>
{% for commande in divisions %}
<tr>
{% for p in commande %}