A grace period keeps a periodic invoice as a draft so late events of the
closed period still count, but RefreshInvoice, PUT /invoices/:id/refresh and
the RefreshDraftInvoices clock only re-summed the fees already on the draft:
late events were never billed.
- Usage fees now record their window (charges_from_datetime,
charges_to_datetime, charges_duration), as Lago's fee properties do.
- rago-jobs refresh_draft (Invoices::RefreshDraftService): for a draft, the
usage lines are priced again from the window's events with the plan's
current charges, filters and groups (charge_lines, shared with invoice
generation), the other lines are re-taxed, totals recomputed (prepaid credit
already drawn still counts), all in one transaction that only writes while
the invoice is still a draft. Finalized invoices are never changed. Drafts
with progressive credits or coupons, or with lines older than the recorded
window, keep the old re-sum.
- The REST, GraphQL and clock paths use it; the clock emits invoice.drafted
only for drafts whose totals moved.
Tests: live Postgres draft refresh (late May event billed, June event not,
second sweep no-op, finalized untouched); GraphQL admin test now refreshes
while the invoice is a draft. Full workspace with pg-tests: 573 passed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>