Persist rounding mode with order

This commit is contained in:
Raphael Michel
2025-08-11 16:56:17 +02:00
parent e30e738e96
commit 16157fbd07
5 changed files with 28 additions and 15 deletions

View File

@@ -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),
),
]

View File

@@ -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')

View File

@@ -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=[

View File

@@ -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': {

View File

@@ -643,7 +643,7 @@
{% endif %}
{% if django_settings.DEBUG %}
<br/>
<small>
<small class="admin-only">
price = {{ line.price|floatformat:2 }}<br>
rounding_correction = {{ line.price_includes_rounding_correction|floatformat:2 }}<br>
tax_value = {{ line.tax_value|floatformat:2 }}<br>
@@ -693,7 +693,7 @@
{% endif %}
{% if django_settings.DEBUG %}
<br/>
<small>
<small class="admin-only">
price = {{ fee.value|floatformat:2 }}<br>
rounding_correction = {{ fee.value_includes_rounding_correction|floatformat:2 }}<br>
tax_value = {{ fee.tax_value|floatformat:2 }}<br>
@@ -729,6 +729,10 @@
</div>
<div class="col-md-3 col-xs-6 col-md-offset-5 price">
<strong>{{ items.total|money:event.currency }}</strong>
<br/>
<small class="admin-only">
tax_rounding_mode = {{ order.tax_rounding_mode }}
</small>
</div>
<div class="clearfix"></div>
</div>