feat(admin): ajoute un calcul de cout matière par fournée
This commit is contained in:
parent
986fc71f20
commit
f822316cff
@ -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 """
|
||||
|
@ -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}"
|
||||
|
@ -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)
|
||||
|
@ -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">
|
||||
|
Loading…
x
Reference in New Issue
Block a user