diff options
author | Magnus Hagander | 2025-01-13 21:13:09 +0000 |
---|---|---|
committer | Magnus Hagander | 2025-01-13 21:18:34 +0000 |
commit | 30031315e6a1f510032213f650dda80f702c19c4 (patch) | |
tree | c9105d979a1af73187da988be84b285aae63e75a /postgresqleu/util/fields.py | |
parent | e5f387701bbbf82eb16808f948ac6d2d7397da5f (diff) |
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.
Diffstat (limited to 'postgresqleu/util/fields.py')
-rw-r--r-- | postgresqleu/util/fields.py | 7 |
1 files changed, 6 insertions, 1 deletions
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() |