feat(fournée): ajout ordre des pates, propagation dans l'ordre des pains ; affichage trié ; affichage des totaux de pain

This commit is contained in:
François Poulain 2024-05-12 22:26:26 +02:00
parent 8831ae1b16
commit 6a2a3b8290
4 changed files with 43 additions and 14 deletions

View File

@ -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

@ -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 %}