Repository navigation
feat(invoice): allocate numbers atomically via a Sequence collection - #895
Draft
augmentcode[bot] wants to merge 1 commit into
Draft
augmentcode[bot] wants to merge 1 commit into
augmentcode[bot] wants to merge 1 commit into
Conversation
Invoice numbers were client-supplied and the last_invoice_number setting was bumped after save, so concurrent creates could be handed the same number. Add a generic Sequence collection (entity+year, unique index) and an atomic getNextSequence helper (findOneAndUpdate $inc + upsert), and wire invoice create to allocate number/year from it instead of trusting the client. The collection is entity-keyed so quote numbering can use it once a quote create path exists in this fork.
Author
|
👋 I've got this PR. I'll handle review feedback, CI failures, and merge conflicts, and ping you the moment it's ready for review. Drop a comment anytime. Marking it ready and picking reviewers are your call — I'll leave both alone. |
Author
|
This PR appears to be inactive. The agent will stop monitoring until a new comment is posted. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
number/yearwere client-supplied andlast_invoice_number(aSetting) was bumped after save via a non-awaitedincreaseBySettingKey. Concurrent creates can read the same last number and produce duplicate invoice numbers.Solution
Sequencecollection (backend/src/models/coreModels/Sequence.js) keyed byentity+yearwith a unique compound index.getNextSequencehelper (backend/src/middlewares/sequence/) usingfindOneAndUpdatewith$inc+upsert— a single-document op MongoDB guarantees atomic, so concurrent creates can never get the same number.number/yearfrom the sequence and ignore client-supplied values, replacing the post-save setting bump.invoice,quote, ...) so quote numbering can reuse it directly.Misc
Client/Invoice/Payment), so only the invoice create path is wired. The sequence collection + helper are generic and ready for quotes once a quote create path exists.Sequenceper(entity, year)from the current max invoice number so new numbers don't collide with historical ones (counters start at 0).github-apitool was unavailable in this (manual) session, so this PR was opened via the org bot (github-app-api); the visible creator is the bot rather than the requesting user — a session tooling misconfiguration to flag.Pull Request opened by Augment Code | View session