From 30031315e6a1f510032213f650dda80f702c19c4 Mon Sep 17 00:00:00 2001 From: Magnus Hagander Date: Mon, 13 Jan 2025 22:13:09 +0100 Subject: [PATCH] Don't crash trying to render non-existant VAT percentages The fractional VAT patch did not properly handle the case when the field could actually be NULL. --- postgresqleu/util/fields.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/postgresqleu/util/fields.py b/postgresqleu/util/fields.py index 8565548a..6e86ceb0 100644 --- a/postgresqleu/util/fields.py +++ b/postgresqleu/util/fields.py @@ -122,7 +122,12 @@ class UserModelChoiceField(ModelChoiceField): class NormalizedDecimalField(models.DecimalField): def from_db_value(self, value, expression, connection): + if value is None: + return value return value.quantize(Decimal(1)) if value == value.to_integral() else value.normalize() def to_python(self, value): - return super().to_python(value).quantize(Decimal(1)) if value == value.to_integral() else value.normalize() + val = super().to_python(value) + if val is None: + return val + return val.quantize(Decimal(1)) if val == val.to_integral() else val.normalize() -- 2.39.5