feat(fournée): ajoute les masses commandées
This commit is contained in:
parent
f822316cff
commit
9ed2726ea9
@ -366,6 +366,7 @@ class FournéeAdmin(nested_admin.NestedModelAdmin):
|
|||||||
))
|
))
|
||||||
totaux.append(total)
|
totaux.append(total)
|
||||||
extra_context["totaux_divisions"] = totaux
|
extra_context["totaux_divisions"] = totaux
|
||||||
|
extra_context["fournée"] = obj
|
||||||
|
|
||||||
return super().change_view(
|
return super().change_view(
|
||||||
request,
|
request,
|
||||||
|
@ -2,6 +2,7 @@ import datetime
|
|||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.db.models import F
|
||||||
|
|
||||||
from colorfield.fields import ColorField
|
from colorfield.fields import ColorField
|
||||||
|
|
||||||
@ -22,6 +23,11 @@ class Fournée(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"Fournée du {self.date: %d-%m-%Y} pour {self.pour}"
|
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):
|
def masse_commandée(self, pâte_id):
|
||||||
"Renvoie la masse commandée d'une pâte donnée"
|
"Renvoie la masse commandée d'une pâte donnée"
|
||||||
poids_qté = (
|
poids_qté = (
|
||||||
@ -163,12 +169,19 @@ class Commande(models.Model):
|
|||||||
pains = models.ManyToManyField("Pain", through="Réservation")
|
pains = models.ManyToManyField("Pain", through="Réservation")
|
||||||
fournée = models.ForeignKey("Fournée", on_delete=models.CASCADE)
|
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):
|
def __str__(self):
|
||||||
details = ""
|
details = ""
|
||||||
if self.id and self.réservation_set.exists():
|
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()]
|
[str(r) for r in self.réservation_set.all()]
|
||||||
) + ")"
|
)
|
||||||
|
details += ")"
|
||||||
return f"{self.pour}" + details
|
return f"{self.pour}" + details
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
{% block after_field_sets %}
|
{% block after_field_sets %}
|
||||||
{% if commandes %}
|
{% if commandes %}
|
||||||
<h2>Résumé des commandes</h2>
|
<h2>Résumé des commandes ({{ fournée.poids_total_commandé }} kg)</h2>
|
||||||
<ul>
|
<ul>
|
||||||
{% for commande in commandes %}
|
{% for commande in commandes %}
|
||||||
<li>{{ commande }}</li>
|
<li>{{ commande }}</li>
|
||||||
|
Loading…
Reference in New Issue
Block a user