Generate invoice earlier in payment method change process (Z#23179304) (#4763)

* Generate invoice earlier in payment method change process (Z##23179304)

* Resolve review note
This commit is contained in:
Raphael Michel
2025-02-03 17:39:46 +01:00
committed by GitHub
parent 2a3cdd85e8
commit c820d742d4
3 changed files with 33 additions and 22 deletions

View File

@@ -3114,14 +3114,34 @@ def change_payment_provider(order: Order, payment_provider, amount=None, new_pay
}
)
new_invoice_created = False
if recreate_invoices:
# Lock to prevent duplicate invoice creation
order = Order.objects.select_for_update(of=OF_SELF).get(pk=order.pk)
i = order.invoices.filter(is_cancellation=False).last()
if i and order.total != oldtotal and not i.canceled:
has_active_invoice = i and not i.canceled
if has_active_invoice and order.total != oldtotal:
generate_cancellation(i)
generate_invoice(order)
new_invoice_created = True
elif (not has_active_invoice or order.invoice_dirty) and invoice_qualified(order):
if order.event.settings.get('invoice_generate') == 'True' or (
order.event.settings.get('invoice_generate') == 'paid' and
new_payment.payment_provider.requires_invoice_immediately
):
if has_active_invoice:
generate_cancellation(i)
i = generate_invoice(order)
new_invoice_created = True
order.log_action('pretix.event.order.invoice.generated', data={
'invoice': i.pk
})
order.create_transactions()
return old_fee, new_fee, fee, new_payment
return old_fee, new_fee, fee, new_payment, new_invoice_created
@receiver(order_paid, dispatch_uid="pretixbase_order_paid_giftcards")