From e523a4e610c7871b522cb8f0ca766822c58ae955 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Mon, 12 Nov 2018 13:01:10 +0100 Subject: [PATCH] Allow to manually generate invoices like in c131ad8c --- .../templates/pretixcontrol/order/index.html | 10 ++++++++++ src/pretix/control/views/orders.py | 14 ++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/pretix/control/templates/pretixcontrol/order/index.html b/src/pretix/control/templates/pretixcontrol/order/index.html index 45ee16fe90..9fc1a0b0f0 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 %} +
+
+ {% csrf_token %} + +
+ {% endif %} {% elif can_generate_invoice %}
{% trans "Invoices" %}
diff --git a/src/pretix/control/views/orders.py b/src/pretix/control/views/orders.py index 034bea506f..293bc5f8a7 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)