Skip to content

Store the invoice amount_remaining so local rows can tell what is still owed #1907

Description

@whoAbhishekSah

The local invoice rows store only the Stripe total. "Total" and "still owed" differ when the customer's credit balance covers an invoice: the total is positive, the amount remaining is zero, and nothing needs paying.

Today that mismatch has one visible effect: CheckOrganizationDelete judges local rows by total, so the org delete button can grey out over an invoice with nothing due, telling the user to pay something unpayable. It clears when the provider marks the invoice paid and the sync picks it up — minutes in practice, and in the safe direction (the button under-promises; the real delete judges live provider data by amount_remaining and is correct). See the discussion on #1881 and the partial fix in #1906, which unfroze the synced total.

Closing it fully means storing amount_remaining next to amount:

  • migration adding the column, backfilled from amount for payable states
  • stripeInvoiceToInvoice mapping it, and the sync update writing it
  • the delete check (and anything else asking "does this invoice still want money") judging on it instead of the total

Worth batching with any other billing-schema change rather than shipping alone.

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions