From 32e6fed1d1323b5607a3325fc8e4cd066287ef19 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Wed, 29 Apr 2026 10:08:20 +0200 Subject: [PATCH] More tax rate handling --- src/pretix/helpers/models.py | 7 +++++-- src/pretix/plugins/reports/accountingreport.py | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/pretix/helpers/models.py b/src/pretix/helpers/models.py index ddaff74cc..1a2bf9346 100644 --- a/src/pretix/helpers/models.py +++ b/src/pretix/helpers/models.py @@ -66,11 +66,14 @@ def _normalize_decimal(d: Decimal) -> Decimal: 20.010 → 20.01 20.100 → 20.1 - But unlike of Decimal.normalize(), 20.000 will not become 2e+1 + But unlike of Decimal.normalize(), 20.000 will not become 2e+1. Very small decimals might still be represented + in scientific notation when printed. """ normalized = d.normalize() sign, digit, exponent = normalized.as_tuple() - return normalized if exponent <= 0 else normalized.quantize(1) + if exponent > 0: + return normalized.quantize(1) + return normalized class NormalizedDecimalField(DecimalField): diff --git a/src/pretix/plugins/reports/accountingreport.py b/src/pretix/plugins/reports/accountingreport.py index 17315eb02..d29887468 100644 --- a/src/pretix/plugins/reports/accountingreport.py +++ b/src/pretix/plugins/reports/accountingreport.py @@ -28,7 +28,7 @@ from decimal import Decimal from django import forms from django.db.models import F, Sum from django.db.models.functions import Coalesce -from django.utils.formats import date_format, localize +from django.utils.formats import date_format from django.utils.html import escape from django.utils.timezone import now from django.utils.translation import gettext as _, gettext_lazy, pgettext_lazy @@ -43,7 +43,7 @@ from pretix.base.exporter import BaseExporter from pretix.base.models import ( GiftCardTransaction, OrderFee, OrderPayment, OrderRefund, Transaction, ) -from pretix.base.templatetags.money import money_filter +from pretix.base.templatetags.money import money_filter, tax_rate_format from pretix.base.timeframes import ( DateFrameField, resolve_timeframe_to_datetime_start_inclusive_end_exclusive, @@ -382,7 +382,7 @@ class ReportExporter(ReportlabExportMixin, BaseExporter): else "", tstyle_right, ), - Paragraph(localize(r["tax_rate"].normalize()) + " %", tstyle_right), + Paragraph(tax_rate_format(r["tax_rate"]) + " %", tstyle_right), Paragraph(str(r["sum_cont"]), tstyle_right), Paragraph( money_filter(r["sum_price"] - r["sum_tax"], currency), tstyle_right @@ -408,7 +408,7 @@ class ReportExporter(ReportlabExportMixin, BaseExporter): [ FontFallbackParagraph(_("Sum"), tstyle), Paragraph("", tstyle_right), - Paragraph(localize(tax_rate.normalize()) + " %", tstyle_right), + Paragraph(tax_rate_format(tax_rate) + " %", tstyle_right), Paragraph("", tstyle_right), Paragraph( money_filter(