Repository navigation
feat: SCO-137 enforce brand order minimums - #399
Merged
Merged
Conversation
Brands could set an order minimum, see it saved, and still receive orders far below it, because nothing compared it to an order total. An order under its brand's minimum can now be saved as a draft but not submitted, except by the org that owns the brand, which can accept it and submit anyway. One rule (findMinimumViolations) guards every path that submits an order: the rep wizard, buyer checkout and offline sync (submitOrderPayload), the status endpoint, note conversion, email-intake approval, and the AI create-order tool. An offline-captured order under the minimum lands as a draft with a notification instead of being rejected, and an email intake under it goes to review. Buyers never inherit the override, even though a legacy buyer's org is the brand's own. Account overrides replace the brand minimum only on accounts the brand's org owns, so a rep cannot lower a connected brand's minimum through their own account. The wizard, checkout, and draft order page warn before submit and disable the submit control; the brand sees a note that it can still submit. SCO-137 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
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.
Summary
An order under its brand's minimum can be saved as a draft but not submitted, except by the org that owns the brand, which can accept it and submit anyway.
findMinimumViolations(src/lib/server/orders/order-minimum.ts) on top of a pureeffectiveOrderMinimum/minimumShortfall(src/lib/utils/order-minimum.ts) guards:submitOrderPayload)PATCH /api/orders/[id]/status(draft to submitted)/orders/[id]?/convert)locals.organizationis the brand's own org, so every call site passesnullas the actor for buyers.Why
SCO-137: brands could configure a minimum, see it saved, and still receive orders below it. Decision (29 Oct): warn and allow draft only; the brand can override and submit.
Not in this PR
Verification
bun run lintpassesbun run checkpasses (0 errors)bun run test:run: 2083 pass, including new tests for the pure rule, the server helper (override, buyer, account override, indexes), submit (online block, captured to draft, brand override, buyer copy, notes/drafts skipped), and note conversion. The 10 localrecent-searchesfailures are pre-existing (Node v26 localStorage) and pass in CI.tests/rls/admin-bypass.test.tsupdated: the status endpoint now uses the service role for the settings lookup, after RLS has authorized the order read.Test plan
Closes SCO-137
🤖 Generated with Claude Code