Add safeguards and tests against duplicate cancellations

This commit is contained in:
Raphael Michel
2019-10-24 16:07:34 +02:00
parent fe92af10fb
commit 3f5e835367
4 changed files with 30 additions and 1 deletions

View File

@@ -210,6 +210,8 @@ def build_cancellation(invoice: Invoice):
def generate_cancellation(invoice: Invoice, trigger_pdf=True):
if invoice.refered.exists():
raise ValueError("Invoice should not be canceled twice.")
cancellation = modelcopy(invoice)
cancellation.pk = None
cancellation.invoice_no = None

View File

@@ -156,7 +156,7 @@ def mark_order_expired(order, user=None, auth=None):
order.log_action('pretix.event.order.expired', user=user, auth=auth)
i = order.invoices.filter(is_cancellation=False).last()
if i:
if i and not i.refered.exists():
generate_cancellation(i)
order_expired.send(order.event, order=order)