Fix sales journal edit committing a void when repost fails - #35
Draft
cursor[bot] wants to merge 1 commit into
Draft
Fix sales journal edit committing a void when repost fails#35cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
After voided status was allowed, replace_sales_journal could persist the void (stock restored, original sale off the posted list) when post_sales_journal returned success:false. Raise on inner failure so the transaction rolls back. Co-authored-by: ezzademir <ezzademir@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This was referenced Aug 29, 2026
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.
Bug and impact
After PR #31 allowed
sales_journals.status = 'voided', editing a posted sale that cannot be reposted still voids the original journal and restores outlet stock, while the UI reports failure.Concrete trigger:
replace_sales_journalvoids first (stock restored to 7 available), thenpost_sales_journalreturnsinsufficient_stock.Impact: silent loss of a posted sale and unexpected stock restore. A follow-up stock take or re-entry can double-count.
This is distinct from open PR #30 (a successful qty-only replace consuming leftover BATCH lots).
Root cause
replace_sales_journal(migration 043) callsvoid_sales_journalthenpost_sales_journal. Both report failure withRETURN success:falserather thanRAISE. PostgREST treats that as a successful RPC and commits.Before #31, voiding hit
sales_journals_status_checkand the exception rolled back the whole replace. After #31 the void succeeds, so a failed edit persists.Fix
Migration
20260820110000_replace_sales_journal_atomic.sql:RAISE EXCEPTIONif void or post returnssuccess:false, so the transaction rolls back and the original posted journal stays intact.is_profiles_admin()on replace, matchingvoid_sales_journal.Validation
npm test— 27 passednpm run lint— no errors (3 pre-existing warnings)npm run typecheck— cleannpm run build— cleanApply this migration on the hosted project after merge.