diff --git a/weblate_web/invoices/models.py b/weblate_web/invoices/models.py index e73751e21e..4b6e217566 100644 --- a/weblate_web/invoices/models.py +++ b/weblate_web/invoices/models.py @@ -474,10 +474,10 @@ def generate_pdf(self) -> None: font_config=font_config, ) - def finalize( + def duplicate( self, *, - kind: InvoiceKind = InvoiceKind.INVOICE, + kind: InvoiceKind, prepaid: bool = True, ) -> Invoice: """Create a final invoice from draft/proforma upon payment.""" @@ -499,6 +499,7 @@ def finalize( quantity=item.quantity, quantity_unit=item.quantity_unit, unit_price=item.unit_price, + package=item.package, ) return invoice diff --git a/weblate_web/management/commands/recurring_payments.py b/weblate_web/management/commands/recurring_payments.py index 288afdbefb..24befc9bb2 100644 --- a/weblate_web/management/commands/recurring_payments.py +++ b/weblate_web/management/commands/recurring_payments.py @@ -26,6 +26,7 @@ from django.core.management.base import BaseCommand from django.utils import timezone +from weblate_web.invoices.models import InvoiceKind from weblate_web.models import Donation, Service, Subscription from weblate_web.payments.models import Payment from weblate_web.payments.utils import send_notification @@ -138,7 +139,11 @@ def peform_payment(payment, past_payments, amount: int | None = None): return # Create repeated payment - repeated = payment.repeat_payment(amount=amount) + if payment.paid_invoice: + invoice = payment.paid_invoice.duplicate(kind=InvoiceKind.DRAFT) + repeated = invoice.create_payment(payment.recurring) + else: + repeated = payment.repeat_payment(amount=amount) # Backend does not support it if not repeated: diff --git a/weblate_web/payments/backends.py b/weblate_web/payments/backends.py index 1771dcbfd4..8d2c12584a 100644 --- a/weblate_web/payments/backends.py +++ b/weblate_web/payments/backends.py @@ -178,7 +178,7 @@ def generate_invoice(self, *, proforma: bool = False) -> None: if proforma and self.payment.draft_invoice.kind == invoice_kind: return # Finalize draft if present - invoice = self.payment.draft_invoice.finalize( + invoice = self.payment.draft_invoice.duplicate( kind=invoice_kind, prepaid=not proforma, )