feat(admin): ajoute un calcul de cout matière par fournée

This commit is contained in:
François Poulain 2024-10-09 19:31:48 +02:00
parent 986fc71f20
commit f822316cff
4 changed files with 42 additions and 5 deletions

View File

@ -44,9 +44,10 @@ class FournitureAdmin(admin.ModelAdmin):
"couleur",
"conditionnement",
"emballage",
"prix",
"consommation",
]
list_editable = ["ordre", "couleur", "conditionnement", "emballage"]
list_editable = ["ordre", "couleur", "conditionnement", "prix", "emballage"]
inlines = [
DocumentInline,
]
@ -306,10 +307,18 @@ class FournéeAdmin(nested_admin.NestedModelAdmin):
.values_list("pains", flat=True)
).values_list("nom", flat=True)
totaux = [
[None, sum(obj.coulée_set.values_list('quantité', flat=True))]
[
None,
{
"poids": sum(
obj.coulée_set.values_list('quantité', flat=True)
),
}
]
]
total_prix = 0
for i in ingrédients:
total = clean(sum([
poids = clean(sum([
qté * qté_unit / unit
for qté, qté_unit, unit in
obj.coulée_set.filter(
@ -321,7 +330,10 @@ class FournéeAdmin(nested_admin.NestedModelAdmin):
'pâte__poids_de_base',
)
]))
totaux.append([i, total])
totaux.append([i, poids])
prix = poids * i.prix
total_prix += prix
totaux[0][1]["prix"] = clean(total_prix)
extra_context["totaux_coulées"] = totaux
""" liste des pains, vérifiant s'ils sont coulés """

View File

@ -58,6 +58,9 @@ class Fourniture(models.Model):
max_digits=6, decimal_places=3, default=0
)
emballage = models.CharField(max_length=64, blank=True)
prix = models.DecimalField(
max_digits=6, decimal_places=3, default=0
)
def __str__(self):
return f"{self.nom}"

View File

@ -3,6 +3,8 @@ from django.contrib.admin.templatetags.admin_modify import submit_row
from django.contrib.admin.templatetags.base import InclusionAdminNode
from django.utils.safestring import mark_safe
from ..utils import clean
register = template.Library()
@ -42,3 +44,7 @@ def emballe(quantité, fourniture):
"<br>ou</br>"
f"{quotient + 1} {fourniture.emballage}s moins {retrait} kg"
)
@register.filter
def multiply(value, arg):
return clean(value * arg)

View File

@ -40,7 +40,7 @@
<tr>
{% for i, p in totaux_coulées %}
{% if forloop.first %}
<th>Total pain : {{p}} kg</th>
<th>Total pain : {{p.poids}} kg</th>
{% else %}
{% if i.conditionnement %}
{% emballe p i as alt %}
@ -63,6 +63,22 @@
{% endif %}
{% endfor %}
</tr>
<tr>
{% for i, p in totaux_coulées %}
{% if forloop.first %}
<th>Prix total : {{p.prix}} €</th>
{% else %}
{% if i.prix %}
<th scope="col" style="text-align:center">
{{ p | multiply:i.prix }} €
</th>
{% else %}
<th scope="col">
</th>
{% endif %}
{% endif %}
{% endfor %}
</tr>
</tbody>
</table>
<div style="display:inline-grid">