diff --git a/src/lib/billing.ts b/src/lib/billing.ts index 3a6e940..60762e4 100644 --- a/src/lib/billing.ts +++ b/src/lib/billing.ts @@ -1411,7 +1411,19 @@ export async function issueCustomInvoiceDraft(params: { let pdfBuffer: Buffer | null = null; try { - pdfBuffer = await renderInvoicePdf(placeholder, invoiceDraft.lines); + pdfBuffer = await renderInvoicePdf( + placeholder, + // Same pattern as the auto-cron generateInvoice: synthesize + // temporary ids for the PDF renderer. The real DB rows have + // these populated post-insert, but the renderer only reads + // them for React keys (display) and id-comparison-free + // operations, so synthetic values are fine. + invoiceDraft.lines.map((l, i) => ({ + ...l, + id: `tmp-${i}`, + invoiceId: placeholder.id, + })) + ); const filename = `${placeholder.invoiceNumber}.pdf`; await updateInvoicePdf(placeholder.id, pdfBuffer, filename); } catch (e) { @@ -1518,5 +1530,12 @@ export async function renderCustomDraftPreview( refundedTotalChf: 0, createdAt: new Date().toISOString(), }; - return renderInvoicePdf(fakeInvoice, invoiceDraft.lines); + return renderInvoicePdf( + fakeInvoice, + invoiceDraft.lines.map((l, i) => ({ + ...l, + id: `tmp-${i}`, + invoiceId: fakeInvoice.id, + })) + ); }