From 85289fe0d1047bba38d429b8cc7431a2b7a36a3c Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Fri, 7 Dec 2018 11:04:41 +0100 Subject: [PATCH] Fix error when marking an expired order as paid --- src/pretix/base/models/orders.py | 2 +- src/pretix/control/forms/orders.py | 4 +++- src/pretix/helpers/money.py | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pretix/base/models/orders.py b/src/pretix/base/models/orders.py index aa967ed32..89bb4c26e 100644 --- a/src/pretix/base/models/orders.py +++ b/src/pretix/base/models/orders.py @@ -208,7 +208,7 @@ class Order(LockModel, LoggedModel): def pending_sum(self): total = self.total if self.status in (Order.STATUS_REFUNDED, Order.STATUS_CANCELED): - total = 0 + total = Decimal('0.00') payment_sum = self.payments.filter( state__in=(OrderPayment.PAYMENT_STATE_CONFIRMED, OrderPayment.PAYMENT_STATE_REFUNDED) ).aggregate(s=Sum('amount'))['s'] or Decimal('0.00') diff --git a/src/pretix/control/forms/orders.py b/src/pretix/control/forms/orders.py index 9af5e17ae..479fa74c2 100644 --- a/src/pretix/control/forms/orders.py +++ b/src/pretix/control/forms/orders.py @@ -1,3 +1,5 @@ +from decimal import Decimal + from django import forms from django.conf import settings from django.core.exceptions import ValidationError @@ -86,7 +88,7 @@ class MarkPaidForm(ConfirmPaymentForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) change_decimal_field(self.fields['amount'], self.instance.event.currency) - self.fields['amount'].initial = max(0, self.instance.pending_sum) + self.fields['amount'].initial = max(Decimal('0.00'), self.instance.pending_sum) class ExporterForm(forms.Form): diff --git a/src/pretix/helpers/money.py b/src/pretix/helpers/money.py index d1c8287c3..238366ba1 100644 --- a/src/pretix/helpers/money.py +++ b/src/pretix/helpers/money.py @@ -19,6 +19,8 @@ class DecimalTextInput(TextInput): return None if isinstance(value, str): return value + if not isinstance(value, Decimal): + value = Decimal(value) return formats.localize_input(value.quantize(Decimal('1') / 10 ** self.places))