fix présentation des décimaux
This commit is contained in:
parent
75e0fb9f57
commit
d580e15f5f
@ -1,5 +1,4 @@
|
||||
from datetime import date, timedelta
|
||||
from decimal import Decimal
|
||||
|
||||
from django.contrib import admin, messages
|
||||
from django.shortcuts import redirect
|
||||
@ -9,13 +8,7 @@ from django.utils.safestring import mark_safe
|
||||
import nested_admin
|
||||
|
||||
from . import models
|
||||
|
||||
|
||||
def clean(d):
|
||||
if d == d.to_integral():
|
||||
return d.quantize(Decimal(1))
|
||||
else:
|
||||
return d.quantize(Decimal('1.000')).normalize()
|
||||
from .utils import clean
|
||||
|
||||
|
||||
class MyAdminSite(admin.AdminSite):
|
||||
|
@ -4,6 +4,8 @@ from django.db import models
|
||||
|
||||
from colorfield.fields import ColorField
|
||||
|
||||
from .utils import clean
|
||||
|
||||
|
||||
def upload_to(instance, filename):
|
||||
return "{}/{}".format(uuid4(), filename)
|
||||
@ -69,7 +71,7 @@ class Ingrédient(models.Model):
|
||||
quantité = models.DecimalField(max_digits=6, decimal_places=3)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.fourniture.nom} ({self.quantité} kg)"
|
||||
return f"{self.fourniture.nom} ({clean(self.quantité)} kg)"
|
||||
|
||||
|
||||
class Recette(models.Model):
|
||||
@ -106,7 +108,7 @@ class Réservation(models.Model):
|
||||
commande = models.ForeignKey("Commande", on_delete=models.CASCADE)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.quantité.normalize()} {self.pain}"
|
||||
return f"{clean(self.quantité)} {self.pain}"
|
||||
|
||||
|
||||
class Commande(models.Model):
|
||||
@ -136,6 +138,6 @@ class Coulée(models.Model):
|
||||
fournée = models.ForeignKey("Fournée", on_delete=models.CASCADE)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.pâte} ({self.quantité.normalize()} kg)"
|
||||
return f"{self.pâte} ({clean(self.quantité)} kg)"
|
||||
|
||||
|
||||
|
8
fournée/core/utils.py
Normal file
8
fournée/core/utils.py
Normal file
@ -0,0 +1,8 @@
|
||||
from decimal import Decimal
|
||||
|
||||
|
||||
def clean(d):
|
||||
if d == d.to_integral():
|
||||
return d.quantize(Decimal(1))
|
||||
else:
|
||||
return d.quantize(Decimal('1.000')).normalize()
|
Loading…
Reference in New Issue
Block a user