diff --git a/fournée/core/admin.py b/fournée/core/admin.py index 2149ce2..f66abf3 100644 --- a/fournée/core/admin.py +++ b/fournée/core/admin.py @@ -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 """ diff --git a/fournée/core/models.py b/fournée/core/models.py index 189cb0a..372391a 100644 --- a/fournée/core/models.py +++ b/fournée/core/models.py @@ -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}" diff --git a/fournée/core/templatetags/fournée_modify.py b/fournée/core/templatetags/fournée_modify.py index 812b261..b17965e 100644 --- a/fournée/core/templatetags/fournée_modify.py +++ b/fournée/core/templatetags/fournée_modify.py @@ -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): "
ou
" f"{quotient + 1} {fourniture.emballage}s moins {retrait} kg" ) + +@register.filter +def multiply(value, arg): + return clean(value * arg) diff --git a/fournée/templates/admin/fournée_change_form.html b/fournée/templates/admin/fournée_change_form.html index 8aea24a..2049a75 100644 --- a/fournée/templates/admin/fournée_change_form.html +++ b/fournée/templates/admin/fournée_change_form.html @@ -40,7 +40,7 @@ {% for i, p in totaux_coulées %} {% if forloop.first %} - Total pain : {{p}} kg + Total pain : {{p.poids}} kg {% else %} {% if i.conditionnement %} {% emballe p i as alt %} @@ -63,6 +63,22 @@ {% endif %} {% endfor %} + + {% for i, p in totaux_coulées %} + {% if forloop.first %} + Prix total : {{p.prix}} € + {% else %} + {% if i.prix %} + + {{ p | multiply:i.prix }} € + + {% else %} + + + {% endif %} + {% endif %} + {% endfor %} +