Skip to content

feat(billing): invoice jobs see deleted invoices - #1982

Merged
rohilsurana merged 4 commits into
mainfrom
feat/invoice-jobs-count-deleted-invoices
Oct 16, 2026
Merged

rohilsurana merged 4 commits into
mainfrom
feat/invoice-jobs-count-deleted-invoices

Conversation

@rohilsurana

Copy link
Copy Markdown
Member

What changes

  • The invoice list can now include soft deleted rows (IncludeDeleted on the filter, and a DeletedAt field on the invoice).
  • The monthly overdraft invoice job finds the last overdraft invoice in one place, and that lookup now counts deleted invoices too.
  • The invoice sync with the billing provider leaves a locally deleted invoice alone. Before, a deleted local row looked like a missing one and the sync would create it again.

Why

This is the second step of making billing rows soft deleted when an organization is deleted. Once invoices carry deleted_at, two jobs could do damage if they could not see them:

  • The overdraft job works out its billing window from the last overdraft invoice. If that invoice is soft deleted and the job cannot see it, the window falls back to an older invoice and the customer is billed again for a period that was already paid.
  • The sync would insert an invoice that still exists on the provider as a new live row.

Nothing writes deleted_at on invoices yet, so there is no behavior change in this PR.

Depends on

This branch is stacked on the migration PR for live-only provider ids.

Release note

Deploy this before the PR that makes the billing deletes soft. If the deletes run first and one fails half way, an overdraft customer can be billed twice.

Tests

  • Repository: the list returns deleted invoices only when asked.
  • Overdraft window: a deleted overdraft invoice still moves the window start, and a live one does as before.
  • Sync: a deleted local invoice is skipped and no new row appears. A live one is updated as before.

@vercel

vercel Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
frontier Ready Ready Preview Oct 16, 2026 8:40am UTC

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: raystack/frontier/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 551be3b9-3acf-49ed-9d67-5097d74a5d97
📥 Commits

Reviewing files that changed from the base of the PR and between 3425558 and 8d97dcd.

📒 Files selected for processing: 5
  • billing/invoice/invoice.go
  • billing/invoice/service.go
  • billing/invoice/service_test.go
  • internal/store/postgres/billing_invoice_repository.go
  • internal/store/postgres/billing_invoice_repository_pg_test.go

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Deleted invoices are no longer recreated or updated during provider sync.
    • Deleted overdraft invoices remain available as credit-window anchors, and invoices without credit items are skipped.
    • Invoice listings can include deleted records while preserving filtering, sorting, and pagination.

Invoice queries can now include soft-deleted records and expose their deletion timestamps. Provider synchronization skips matching deleted invoices, and overdraft generation can use deleted invoices as anchors.

Changes: Soft-deleted billing records

Layer / File(s) Summary
Deleted invoice query support
billing/invoice/invoice.go, internal/store/postgres/billing_invoice_repository.go, internal/store/postgres/billing_invoice_repository_pg_test.go
Invoice exposes DeletedAt, and Filter adds IncludeDeleted. The PostgreSQL repository returns deletion timestamps and includes deleted records when requested. Tests cover returned records and pagination counts.
Invoice processing with deleted records
billing/invoice/service.go, billing/invoice/service_test.go
Provider sync skips matching deleted invoices. Overdraft generation selects an invoice with a credit item from all customer invoices and continues to the next customer after lookup errors. Tests cover deleted and live invoice cases.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Suggested reviewers: amangit07, whoabhisheksah

Merge Risk: ⚪ Minimal · up to 8d97d

The deleted-invoice handling is ready to merge after normal checks; no material issue was identified.

Pre-merge checks: Passed 2
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coveralls

coveralls commented Oct 12, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 38875144870

Coverage increased (+0.2%) to 55.262%

Details

  • Coverage increased (+0.2%) from the base build.
  • Patch coverage: 3 uncovered changes across 1 file (25 of 28 lines covered, 89.29%).
  • 1 coverage regression across 1 file.

Uncovered Changes

File Changed Covered %
billing/invoice/service.go 20 17 85.0%
Total (2 files) 28 25 89.29%

Coverage Regressions

1 previously-covered line in 1 file lost coverage.

File Lines Losing Coverage Coverage
billing/invoice/service.go 1 20.56%

Coverage Stats

Coverage Status
Relevant Lines: 41645
Covered Lines: 23014
Line Coverage: 55.26%
Coverage Strength: 19.13 hits per line

💛 - Coveralls

@rohilsurana
rohilsurana force-pushed the feat/billing-provider-ids-live-unique branch from b0489db to 3711d88 Compare October 13, 2026 09:16
@rohilsurana
rohilsurana force-pushed the feat/invoice-jobs-count-deleted-invoices branch from 569b820 to a7af83d Compare October 13, 2026 09:16
@rohilsurana
rohilsurana force-pushed the feat/billing-provider-ids-live-unique branch from 3711d88 to 8d9f641 Compare October 13, 2026 11:42
@rohilsurana
rohilsurana force-pushed the feat/invoice-jobs-count-deleted-invoices branch from a7af83d to ebe1dc5 Compare October 13, 2026 11:42
@rohilsurana
rohilsurana marked this pull request as ready for review October 13, 2026 11:53
@rohilsurana
rohilsurana force-pushed the feat/billing-provider-ids-live-unique branch from 8d9f641 to 89bfb1c Compare October 14, 2026 09:03
@rohilsurana
rohilsurana force-pushed the feat/invoice-jobs-count-deleted-invoices branch from ebe1dc5 to 0031cdd Compare October 14, 2026 09:03
Base automatically changed from feat/billing-provider-ids-live-unique to main October 16, 2026 08:39
@rohilsurana
rohilsurana force-pushed the feat/invoice-jobs-count-deleted-invoices branch from 0031cdd to 8d97dcd Compare October 16, 2026 08:39
@rohilsurana
rohilsurana merged commit 2c6d9a2 into main Oct 16, 2026
8 checks passed
@rohilsurana
rohilsurana deleted the feat/invoice-jobs-count-deleted-invoices branch October 16, 2026 08:44

This branch was successfully deployed

1 active deployment
Preview — 8d97dcd4 Deployed Oct 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants