From 4c96b34c7c42454878bbfded3034bcdd47245d28 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 31 Mar 2020 21:21:39 +1100 Subject: [PATCH] Override prepare_value method of RoundingDecimalFormField - Remove trailing zeros in form field display --- InvenTree/InvenTree/fields.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/InvenTree/InvenTree/fields.py b/InvenTree/InvenTree/fields.py index b3393ef1eb..7dbf953016 100644 --- a/InvenTree/InvenTree/fields.py +++ b/InvenTree/InvenTree/fields.py @@ -43,7 +43,16 @@ def round_decimal(value, places): class RoundingDecimalFormField(forms.DecimalField): def to_python(self, value): value = super(RoundingDecimalFormField, self).to_python(value) - return round_decimal(value, self.decimal_places) + value = round_decimal(value, self.decimal_places) + return value + + def prepare_value(self, value): + """ + Override the 'prepare_value' method, to remove trailing zeros when displaying. + Why? It looks nice! + """ + + return value.normalize() class RoundingDecimalField(models.DecimalField):