Compare commits
2 Commits
986fc71f20
...
9ed2726ea9
Author | SHA1 | Date | |
---|---|---|---|
9ed2726ea9 | |||
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 """
|
||||
@ -354,6 +366,7 @@ class FournéeAdmin(nested_admin.NestedModelAdmin):
|
||||
))
|
||||
totaux.append(total)
|
||||
extra_context["totaux_divisions"] = totaux
|
||||
extra_context["fournée"] = obj
|
||||
|
||||
return super().change_view(
|
||||
request,
|
||||
|
@ -2,6 +2,7 @@ import datetime
|
||||
from uuid import uuid4
|
||||
|
||||
from django.db import models
|
||||
from django.db.models import F
|
||||
|
||||
from colorfield.fields import ColorField
|
||||
|
||||
@ -22,6 +23,11 @@ class Fournée(models.Model):
|
||||
def __str__(self):
|
||||
return f"Fournée du {self.date: %d-%m-%Y} pour {self.pour}"
|
||||
|
||||
def poids_total_commandé(self):
|
||||
return clean(sum(
|
||||
[c.poids_total_commandé() for c in self.commande_set.all()]
|
||||
))
|
||||
|
||||
def masse_commandée(self, pâte_id):
|
||||
"Renvoie la masse commandée d'une pâte donnée"
|
||||
poids_qté = (
|
||||
@ -58,6 +64,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}"
|
||||
@ -160,12 +169,19 @@ class Commande(models.Model):
|
||||
pains = models.ManyToManyField("Pain", through="Réservation")
|
||||
fournée = models.ForeignKey("Fournée", on_delete=models.CASCADE)
|
||||
|
||||
def poids_total_commandé(self):
|
||||
return sum([r.poids for r in self.réservation_set.annotate(
|
||||
poids=F('quantité')*F('pain__poids')
|
||||
)])
|
||||
|
||||
def __str__(self):
|
||||
details = ""
|
||||
if self.id and self.réservation_set.exists():
|
||||
details = " (" + ", ".join(
|
||||
details = f" ({clean(self.poids_total_commandé())} kg : "
|
||||
details += ", ".join(
|
||||
[str(r) for r in self.réservation_set.all()]
|
||||
) + ")"
|
||||
)
|
||||
details += ")"
|
||||
return f"{self.pour}" + details
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
{% block after_field_sets %}
|
||||
{% if commandes %}
|
||||
<h2>Résumé des commandes</h2>
|
||||
<h2>Résumé des commandes ({{ fournée.poids_total_commandé }} kg)</h2>
|
||||
<ul>
|
||||
{% for commande in commandes %}
|
||||
<li>{{ commande }}</li>
|
||||
@ -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…
Reference in New Issue
Block a user