From 16157fbd07d9759478349821ba1cc791cfd39153 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Mon, 11 Aug 2025 16:56:17 +0200 Subject: [PATCH] Persist rounding mode with order --- ...e_includes_rounding_correction_and_more.py | 5 +++++ src/pretix/base/models/orders.py | 7 ++++++- src/pretix/base/services/orders.py | 4 ++-- src/pretix/base/settings.py | 19 +++++++++---------- .../templates/pretixcontrol/order/index.html | 8 ++++++-- 5 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/pretix/base/migrations/0285_cartposition_price_includes_rounding_correction_and_more.py b/src/pretix/base/migrations/0285_cartposition_price_includes_rounding_correction_and_more.py index fda9c90c84..bfd0c08c05 100644 --- a/src/pretix/base/migrations/0285_cartposition_price_includes_rounding_correction_and_more.py +++ b/src/pretix/base/migrations/0285_cartposition_price_includes_rounding_correction_and_more.py @@ -73,4 +73,9 @@ class Migration(migrations.Migration): decimal_places=2, default=Decimal("0.00"), max_digits=13 ), ), + migrations.AddField( + model_name="order", + name="tax_rounding_mode", + field=models.CharField(default="line", max_length=100), + ), ] diff --git a/src/pretix/base/models/orders.py b/src/pretix/base/models/orders.py index 4ff5d0a14b..f3743392e1 100644 --- a/src/pretix/base/models/orders.py +++ b/src/pretix/base/models/orders.py @@ -81,7 +81,7 @@ from pretix.base.email import get_email_context from pretix.base.i18n import language from pretix.base.models import Customer, User from pretix.base.reldate import RelativeDateWrapper -from pretix.base.settings import PERSON_NAME_SCHEMES +from pretix.base.settings import PERSON_NAME_SCHEMES, ROUNDING_MODES from pretix.base.signals import allow_ticket_download, order_gracefully_delete from pretix.base.timemachine import time_machine_now @@ -324,6 +324,11 @@ class Order(LockModel, LoggedModel): # Invoice needs to be re-issued when the order is paid again default=False, ) + tax_rounding_mode = models.CharField( + max_length=100, + choices=ROUNDING_MODES, + default="line", + ) objects = ScopedManager(OrderQuerySet.as_manager().__class__, organizer='event__organizer') diff --git a/src/pretix/base/services/orders.py b/src/pretix/base/services/orders.py index e46a2b648b..d1f89a99dd 100644 --- a/src/pretix/base/services/orders.py +++ b/src/pretix/base/services/orders.py @@ -1039,6 +1039,7 @@ def _create_order(event: Event, *, email: str, positions: List[CartPosition], no sales_channel=sales_channel, customer=customer, valid_if_pending=valid_if_pending, + tax_rounding_mode=event.settings.tax_rounding, ) if customer: order.email_known_to_work = customer.is_verified @@ -2751,8 +2752,7 @@ class OrderChangeManager: if fee_changed: fees = list(self.order.fees.all()) - print("round", positions, fees) - changed = apply_rounding(self.order.event.settings.tax_rounding, self.order.event.currency, [*positions, *fees]) + changed = apply_rounding(self.order.tax_rounding_mode, self.order.event.currency, [*positions, *fees]) for l in changed: if isinstance(l, OrderPosition): l.save(update_fields=[ diff --git a/src/pretix/base/settings.py b/src/pretix/base/settings.py index 1bb929a542..45b85fec1a 100644 --- a/src/pretix/base/settings.py +++ b/src/pretix/base/settings.py @@ -78,6 +78,13 @@ from pretix.control.forms import ( from pretix.helpers.countries import CachedCountries +ROUNDING_MODES = ( + ('line', _('Rounding every line individually')), + ('sum_by_net', _('Rounding by order total, keeping net prices stable')), + ('sum_by_gross', _('Rounding by order total, keeping gross prices stable')), +) + + def country_choice_kwargs(): allcountries = list(CachedCountries()) allcountries.insert(0, ('', _('Select country'))) @@ -473,18 +480,10 @@ DEFAULTS = { 'form_kwargs': dict( label=_("Rounding of taxes"), widget=forms.RadioSelect, - choices=( - ('line', _('Rounding every line individually')), - ('sum_by_net', _('Rounding by order total, keeping net prices stable')), - ('sum_by_gross', _('Rounding by order total, keeping gross prices stable')), - ), + choices=ROUNDING_MODES, ), 'serializer_kwargs': dict( - choices=( - ('line', _('Rounding every line individually')), - ('sum_by_net', _('Rounding by order total, keeping net prices stable')), - ('sum_by_gross', _('Rounding by order total, keeping gross prices stable')), - ), + choices=ROUNDING_MODES, ), }, 'invoice_address_asked': { diff --git a/src/pretix/control/templates/pretixcontrol/order/index.html b/src/pretix/control/templates/pretixcontrol/order/index.html index d87522da60..32b758b342 100644 --- a/src/pretix/control/templates/pretixcontrol/order/index.html +++ b/src/pretix/control/templates/pretixcontrol/order/index.html @@ -643,7 +643,7 @@ {% endif %} {% if django_settings.DEBUG %}
- + price = {{ line.price|floatformat:2 }}
rounding_correction = {{ line.price_includes_rounding_correction|floatformat:2 }}
tax_value = {{ line.tax_value|floatformat:2 }}
@@ -693,7 +693,7 @@ {% endif %} {% if django_settings.DEBUG %}
- + price = {{ fee.value|floatformat:2 }}
rounding_correction = {{ fee.value_includes_rounding_correction|floatformat:2 }}
tax_value = {{ fee.tax_value|floatformat:2 }}
@@ -729,6 +729,10 @@
{{ items.total|money:event.currency }} +
+ + tax_rounding_mode = {{ order.tax_rounding_mode }} +