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",
|
"couleur",
|
||||||
"conditionnement",
|
"conditionnement",
|
||||||
"emballage",
|
"emballage",
|
||||||
|
"prix",
|
||||||
"consommation",
|
"consommation",
|
||||||
]
|
]
|
||||||
list_editable = ["ordre", "couleur", "conditionnement", "emballage"]
|
list_editable = ["ordre", "couleur", "conditionnement", "prix", "emballage"]
|
||||||
inlines = [
|
inlines = [
|
||||||
DocumentInline,
|
DocumentInline,
|
||||||
]
|
]
|
||||||
@ -306,10 +307,18 @@ class FournéeAdmin(nested_admin.NestedModelAdmin):
|
|||||||
.values_list("pains", flat=True)
|
.values_list("pains", flat=True)
|
||||||
).values_list("nom", flat=True)
|
).values_list("nom", flat=True)
|
||||||
totaux = [
|
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:
|
for i in ingrédients:
|
||||||
total = clean(sum([
|
poids = clean(sum([
|
||||||
qté * qté_unit / unit
|
qté * qté_unit / unit
|
||||||
for qté, qté_unit, unit in
|
for qté, qté_unit, unit in
|
||||||
obj.coulée_set.filter(
|
obj.coulée_set.filter(
|
||||||
@ -321,7 +330,10 @@ class FournéeAdmin(nested_admin.NestedModelAdmin):
|
|||||||
'pâte__poids_de_base',
|
'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
|
extra_context["totaux_coulées"] = totaux
|
||||||
|
|
||||||
""" liste des pains, vérifiant s'ils sont coulés """
|
""" 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
|
max_digits=6, decimal_places=3, default=0
|
||||||
)
|
)
|
||||||
emballage = models.CharField(max_length=64, blank=True)
|
emballage = models.CharField(max_length=64, blank=True)
|
||||||
|
prix = models.DecimalField(
|
||||||
|
max_digits=6, decimal_places=3, default=0
|
||||||
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.nom}"
|
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.contrib.admin.templatetags.base import InclusionAdminNode
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
|
||||||
|
from ..utils import clean
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
@ -42,3 +44,7 @@ def emballe(quantité, fourniture):
|
|||||||
"<br>ou</br>"
|
"<br>ou</br>"
|
||||||
f"{quotient + 1} {fourniture.emballage}s moins {retrait} kg"
|
f"{quotient + 1} {fourniture.emballage}s moins {retrait} kg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def multiply(value, arg):
|
||||||
|
return clean(value * arg)
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
{% for i, p in totaux_coulées %}
|
{% for i, p in totaux_coulées %}
|
||||||
{% if forloop.first %}
|
{% if forloop.first %}
|
||||||
<th>Total pain : {{p}} kg</th>
|
<th>Total pain : {{p.poids}} kg</th>
|
||||||
{% else %}
|
{% else %}
|
||||||
{% if i.conditionnement %}
|
{% if i.conditionnement %}
|
||||||
{% emballe p i as alt %}
|
{% emballe p i as alt %}
|
||||||
@ -63,6 +63,22 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tr>
|
</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>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<div style="display:inline-grid">
|
<div style="display:inline-grid">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user