fix(02-04): set invoice status to SENT on generation

Invoices were created with default DRAFT status, but PaymentService queries
for SENT/PARTIAL/OVERDUE. This broke the generate → pay flow. Now invoices
are immediately SENT with issuedAt timestamp on generation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
kevin-asprec
2026-03-05 00:07:46 +08:00
parent 816ac5360f
commit a821733b28
2 changed files with 8 additions and 6 deletions

View File

@@ -365,7 +365,7 @@ describe("Invoice generation — POSTPAID", () => {
const invoice = result!.invoice as Record<string, unknown>; const invoice = result!.invoice as Record<string, unknown>;
expect(Number(invoice.totalAmount)).toBeCloseTo(49.99); expect(Number(invoice.totalAmount)).toBeCloseTo(49.99);
expect(Number(invoice.subtotal)).toBeCloseTo(49.99); expect(Number(invoice.subtotal)).toBeCloseTo(49.99);
expect(invoice.status).toBe(InvoiceStatus.DRAFT); expect(invoice.status).toBe(InvoiceStatus.SENT);
expect(invoice.subscriberId).toBe(subscriberId); expect(invoice.subscriberId).toBe(subscriberId);
}); });
@@ -615,7 +615,7 @@ describe("Credit auto-application on invoice generation", () => {
expect(result!.creditApplied).toBe(false); expect(result!.creditApplied).toBe(false);
const invoice = result!.invoice as Record<string, unknown>; const invoice = result!.invoice as Record<string, unknown>;
expect(invoice.status).toBe(InvoiceStatus.DRAFT); expect(invoice.status).toBe(InvoiceStatus.SENT);
expect(Number(invoice.amountPaid)).toBe(0); expect(Number(invoice.amountPaid)).toBe(0);
}); });
@@ -1000,11 +1000,11 @@ describe("getInvoice and listInvoices", () => {
}); });
it("listInvoices filters by status", async () => { it("listInvoices filters by status", async () => {
const result = await listInvoices(tA(), { status: InvoiceStatus.DRAFT }); const result = await listInvoices(tA(), { status: InvoiceStatus.SENT });
const allDraft = (result.invoices as Array<Record<string, unknown>>).every( const allSent = (result.invoices as Array<Record<string, unknown>>).every(
(inv) => inv.status === InvoiceStatus.DRAFT || inv.status === InvoiceStatus.PARTIAL || inv.status === InvoiceStatus.OVERDUE (inv) => inv.status === InvoiceStatus.SENT || inv.status === InvoiceStatus.PARTIAL || inv.status === InvoiceStatus.OVERDUE
); );
// All returned should be DRAFT (some might have been changed to OVERDUE by other tests) // All returned should be SENT (some might have been changed to OVERDUE or PARTIAL by other tests)
expect(result.invoices).toBeTruthy(); expect(result.invoices).toBeTruthy();
}); });
}); });

View File

@@ -210,6 +210,8 @@ export async function generateInvoiceForSubscriber(
subtotal: monthlyPrice, subtotal: monthlyPrice,
totalAmount: monthlyPrice, totalAmount: monthlyPrice,
amountPaid: new Prisma.Decimal(0), amountPaid: new Prisma.Decimal(0),
status: 'SENT',
issuedAt: new Date(),
lines: { lines: {
create: [ create: [
{ {