Skip to content

Feature/32 receipt numbering - #92

Open
Lightsul wants to merge 6 commits into
developfrom
feature/32-receipt-numbering
Open

Lightsul wants to merge 6 commits into
developfrom
feature/32-receipt-numbering

Conversation

@Lightsul

Copy link
Copy Markdown
Collaborator

Closes #32

Overview

Gives each receipt a unique number when it is issued, with no duplicates and no gaps, even when several receipts are issued at the same time.

Format: DEN_000001 (series DEN_ for food donations + 6 digits, continuous across years). It follows the style of the existing money donation receipts (WEB_056836), but uses its own series so that two receipts of the organization never share a number. To confirm with Nafissa.

Testing

dotnet test: 615/615 passing (Docker required for the integration tests).

Checklist

  • Code is neat, readable, and works
  • Code is commented where appropriate and well-documented
  • Commit messages follow our guidelines
  • Issue number is linked
  • Branch is linked
  • Reviewers are assigned (one of your tech leads)

Notes

  • The DEN_ series is still to be confirmed with Nafissa. Changing it means updating ReceiptNumber.cs and adding a migration, since the database checks the format.

- Add ReceiptStatus, ReceiptAction and ReceiptStateMachine in Core
- Add the status column on receipts and the receipt_status_changes table, with the AddReceiptStatus migration and its SQL script
- Add one endpoint per action; check the state machine, the reason and that the submitter does not approve, then save the status and its history in one transaction
- Return 409 with the allowed actions for an invalid or concurrent change, 400 for a missing reason, 403 for self-approval, 404 for an unknown receipt
- Document the statuses in docs/database/receipt-statuses.md, with a test that keeps the diagram in sync with the code
Renumber the receipt status SQL script to 0008, since 0007 is now the catalog quality class migration from #88.
@Lightsul Lightsul added this to the Sprint - 2 milestone Nov 24, 2026
@Lightsul Lightsul self-assigned this Nov 24, 2026

@anis022 anis022 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, the numbering itself looks solid, the counter lock and the rollback prevent duplicates and gaps. I left one comment on the migration backfill to fix before merging.

FROM (
SELECT id, row_number() OVER (ORDER BY created_at, id) AS position
FROM receipts
WHERE status = 'Issued'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The backfill only numbers receipts with status = 'Issued', ordered by created_at. Since #90, a receipt can be issued and then cancelled, so it gets no number, and the others follow the creation order instead of the issue order. Can we number every receipt that has a receipt_status_changes row with to_status = 'Issued', ordered by its changed_at? Same fix in 0009_add_receipt_numbers.sql.

@anis022
anis022 removed the request for review from lauriechammah November 24, 2026 04:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants