From: Magnus Hagander Date: Mon, 13 Jan 2025 21:13:09 +0000 (+0100) Subject: Don't crash trying to render non-existant VAT percentages X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=30031315e6a1f510032213f650dda80f702c19c4;p=pgeu-system.git 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. --- 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()