feat(fournée): résume le nb de plaque pour les divisions

This commit is contained in:
François Poulain 2024-10-10 09:50:42 +02:00
parent a04ac1c0f1
commit b1223c40c5
4 changed files with 34 additions and 9 deletions

View File

@ -22,8 +22,8 @@ admin_site = MyAdminSite(name="admin")
class PainAdmin(admin.ModelAdmin):
list_display = ["nom", "pâte", "poids", "moulé"]
list_editable = ["pâte", "poids", "moulé"]
list_display = ["nom", "pâte", "poids", "moulé", "combien_sur_une_plaque"]
list_editable = ["pâte", "poids", "moulé", "combien_sur_une_plaque"]
list_select_related = ["pâte"]
actions = None
save_as = True
@ -305,7 +305,7 @@ class FournéeAdmin(nested_admin.NestedModelAdmin):
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)
).values_list("nom", "combien_sur_une_plaque")
totaux = [
[
None,
@ -339,13 +339,13 @@ class FournéeAdmin(nested_admin.NestedModelAdmin):
""" liste des pains, vérifiant s'ils sont coulés """
extra_context["pains"] = [
(not obj.coulée_set.filter(pâte__pain__nom=p).exists(), p)
for p in pains
for p, _ in pains
]
""" on créé un tableau pains / commande """
extra_context["divisions"] = []
for c in obj.commande_set.all():
tmp = [c.pour]
for p in pains:
for p, _ in pains:
if c.réservation_set.filter(pain__nom=p).exists():
tmp.append(
clean(sum(
@ -358,13 +358,18 @@ class FournéeAdmin(nested_admin.NestedModelAdmin):
tmp.append("")
extra_context["divisions"].append(tmp)
totaux = [sum(obj.coulée_set.values_list('quantité', flat=True))]
for p in pains:
for p, par_plaque in pains:
total = clean(sum(
obj.commande_set.filter(pains__nom=p).values_list(
"réservation__quantité", flat=True
)
))
totaux.append(total)
if par_plaque:
q, r = divmod(total, par_plaque)
plaques = q + (r > 0)
else:
plaques = None
totaux.append((total, plaques))
extra_context["totaux_divisions"] = totaux
extra_context["fournée"] = obj

View File

@ -0,0 +1,17 @@
# Generated by Django 4.2.13 on 2024-10-10 07:25
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("core", "0019_fourniture_prix"),
]
operations = [
migrations.AddField(
model_name="pain",
name="combien_sur_une_plaque",
field=models.PositiveSmallIntegerField(default=0),
),
]

View File

@ -144,6 +144,7 @@ class Pain(models.Model):
pâte = models.ForeignKey("Recette", on_delete=models.CASCADE)
poids = models.DecimalField(max_digits=6, decimal_places=3)
moulé = models.BooleanField()
combien_sur_une_plaque = models.PositiveSmallIntegerField(default=0)
def __str__(self):
return self.nom

View File

@ -142,7 +142,9 @@
{% if forloop.first %}
<th>Total pain : {{p}} kg</th>
{% else %}
<th scope="col" style="text-align:center">{{ p }}</th>
<th scope="col" style="text-align:center">
{{ p.0 }}{% if p.1 %}<br>({{ p.1 }} plaque{{ p.1|pluralize }}){% endif %}
</th>
{% endif %}
{% endfor %}
</tr>
@ -152,7 +154,7 @@
<tr>
{% for p in commande %}
{% if forloop.first %}<th scope="row">{% else %}<td style="text-align:center">{% endif %}
{{ p }}
{{ p }}
{% if forloop.first %}</th>{% else %}</td>{% endif %}
{% endfor %}
</tr>