diff --git a/src/pretix/control/templates/pretixcontrol/order/index.html b/src/pretix/control/templates/pretixcontrol/order/index.html
index 45ee16fe9..9fc1a0b0f 100644
--- a/src/pretix/control/templates/pretixcontrol/order/index.html
+++ b/src/pretix/control/templates/pretixcontrol/order/index.html
@@ -184,6 +184,16 @@
{% endif %}
{% endfor %}
+ {% if can_generate_invoice %}
+
+
+ {% endif %}
{% elif can_generate_invoice %}
{% trans "Invoices" %}
diff --git a/src/pretix/control/views/orders.py b/src/pretix/control/views/orders.py
index 034bea506..293bc5f8a 100644
--- a/src/pretix/control/views/orders.py
+++ b/src/pretix/control/views/orders.py
@@ -122,6 +122,12 @@ class OrderView(EventPermissionRequiredMixin, DetailView):
ctx = super().get_context_data(**kwargs)
ctx['can_generate_invoice'] = invoice_qualified(self.order) and (
self.request.event.settings.invoice_generate in ('admin', 'user', 'paid', 'True')
+ ) and (
+ not self.order.invoices.exists()
+ or (
+ self.order.status in (Order.STATUS_PAID, Order.STATUS_PENDING)
+ and self.order.invoices.filter(is_cancellation=True).count() >= self.order.invoices.filter(is_cancellation=False).count()
+ )
)
return ctx
@@ -738,9 +744,13 @@ class OrderInvoiceCreate(OrderView):
permission = 'can_change_orders'
def post(self, *args, **kwargs):
- if self.request.event.settings.get('invoice_generate') not in ('admin', 'user', 'paid') or not invoice_qualified(self.order):
+ has_inv = self.order.invoices.exists() and not (
+ self.order.status in (Order.STATUS_PAID, Order.STATUS_PENDING)
+ and self.order.invoices.filter(is_cancellation=True).count() >= self.order.invoices.filter(is_cancellation=False).count()
+ )
+ if self.request.event.settings.get('invoice_generate') not in ('admin', 'user', 'paid', 'True') or not invoice_qualified(self.order):
messages.error(self.request, _('You cannot generate an invoice for this order.'))
- elif self.order.invoices.exists():
+ elif has_inv:
messages.error(self.request, _('An invoice for this order already exists.'))
else:
inv = generate_invoice(self.order)