Repository navigation
fix(so): close five sales order audit defects - #631
Open
privatejoel wants to merge 1 commit into
Open
privatejoel wants to merge 1 commit into
privatejoel wants to merge 1 commit into
Conversation
- A writer cannot set an approval. The PATCH no longer copies "approval" from the body; only the approve branch writes it, with the approver's id. POST /api/orders makes a DRAFT with no approval and no hash, and needs so.write. - Lines are editable only in DRAFT, PENDING_REVIEW and BLOCKED. The unused so.edit_after_approval action is deleted. - The Tally retry drain pushes a queued row only while its order is not cancelled, is approved, and has the hash the row was queued with. Otherwise the row leaves the queue with the reason and keeps its XML. The order update is scoped to the row's tenant. - The Tally voucher XML and the voucher PDF read rate and quantity through soLineRate/soLineQty. The PDF gives the whole line to computeLineTax, so the item master GST rate is used. - SO intake clears all extraction state at the start of each extraction and on remove. - The Excel export no longer selects orders.payment_terms, which no migration creates. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
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
This PR fixes five defects that the 2026-10-19 audit of the sales order path found. The plan in
docs/SO_EXECUTION_COHESION.md(C-1 to C-38) does not cover them. This PR does not touch the branches of #622 to #630.PATCH /api/orders/[id]copiedapprovalfrom the body. A PATCH with{approval:{payloadHash:<current>}}and no status wrote an approval with no approver. Nowapprovalis not inAPPROVE_INPUTS. Only the approve branch writes it, withapprovedByset to the approver.POST /api/orderstookstatus,approvalandpayload_hashfrom the body and checked only the coarse write verb. Now it always makes a DRAFT with no approval and no hash, and it needsso.write.so-intake.tsxsends DRAFT. The legacy local-storage mirror inanvil-client.jssendsstatus,approvalandpayload_hash. The server now ignores these fields, so a mirrored order arrives as DRAFT.so-workspace.tsx: lines are editable only in DRAFT, PENDING_REVIEW and BLOCKED. Before, APPROVED, FAILED_TALLY_IMPORT and DUPLICATE were also editable. The unusedso.edit_after_approvalaction is deleted fromrbac.ts(nothing read it, and the server did not have it).tally/retry.js: before it pushes a queued row, the drain reads the order in the row's tenant. It skips the row if the order is not found, is cancelled, has no approval, or has a hash that is not the hash on the row. A skipped row getsstatus = gave_upandlast_error = "skipped::<reason>". Itspayload_xmlstays. If the order read fails, the row stays pending and goes through the usual backoff. Theordersupdate after a push now filters ontenant_id.computeLineTaxandinventoryEntryXmlreadline.rate || line.unitPrice, so a rate that the reconciler filled indiscounted_unit_pricewas lost. Both now usesoLineRateandsoLineQty(_lib/so-line-money.js).voucher_pdf.jsgavecomputeLineTaxan object that it built field by field and that did not include_mapped_item, so a GST rate that only the item master had printed as 0%. Also, the PDF readdiscounted_unit_pricefirst, so it could print a rate that was not on the voucher. It now gives the whole line tocomputeLineTaxand printssoLineQtyandsoLineRate.resetExtraction()clears lines, evidence, extraction meta, the large-PO flag and the extracted customer. It runs at the start of each extraction and on remove.orders/export.jsselectedorders.payment_terms, but no migration makes this column. It is removed from the select and from the Payment Terms fallback. The row still readssalesOrder.payment_terms, then the customer block.Deploy notes
POST /api/ordersnow returns 403ACTION_FORBIDDENfor finance, procurement and operator. These roles are read-only on sales orders, and no screen shows them a create button.gave_upwithskipped::<reason>.tally/healthcounts these rows as give-ups.requireActionname.so.writeis already inSERVER_ACTIONSand inrbac.ts.Tests
New or changed tests (all behavioural, no source grep):
api-so-write-gate.test.js: a writer PATCH with an approval and no status leavesapprovalnull (PENDING_REVIEW and APPROVED). An approve storesapprovedBy. POST with a forged status, approval and hash stores DRAFT with null approval and null hash. POST by finance, procurement or operator returns 403 and inserts no row.so-workspace-manual-lines.test.tsx: the add and remove controls show on DRAFT, PENDING_REVIEW and BLOCKED. They do not show on APPROVED, FAILED_TALLY_IMPORT, DUPLICATE or EXPORTED_TO_TALLY, and the read-only notice gives the status.api-tally-mode-b.test.js: the fixtures now queue rows for approved orders with a matching hash. New "order guard" tests: no push for a cancelled order, an order returned for a fix, an order edited after it was queued, or an order of another tenant. The skipped row keeps its XML. A failed order read keeps the row pending. The exported status goes only to the row's tenant.api-tally-build-voucher.test.js: a line with no PO rate and a reconciler rate prints<RATE>120/Nos</RATE>and the correct tax.api-orders-voucher-pdf.test.js: the item master GST rate is used. The PDF prints the PO rate, as the voucher does.so-intake-extraction-reset.test.tsx(new): a second PO with 0 lines, and a removed PO, give an order with no lines from the first PO.api-orders-export.test.js: the fake database now refuses a select that namesorders.payment_terms, as the live database does.Mutation check. I reverted each fix one at a time and ran its test file. All 21 mutations failed their tests:
rate || unitPricerate || unitPriceGates on this branch:
npm ciin the worktree.npm run check: pass.npm run lint: 0 errors. The changed lines add no warnings.npm run build: pass.npm run verify: pass. It rewrotedocs/RBAC_AUDIT.mdanddocs/WRITE_PATH_AUDIT.mdwith old drift that this PR did not cause. I restored both files.npm run eval:golden: pass, no regressions.NODE_OPTIONS=--no-experimental-webstorage npx vitest run: 627 files, 7390 tests, all pass.Not covered
resultedit on an APPROVED order. The edit clears the approval, but the status stays APPROVED. The lock in this PR is in the workspace only.ALLOWED_TRANSITIONS. To fix its lines, a user must move it to APPROVED and then return it for correction.approval_expires_at.tally/push.jsdoes not check it either.tally_voucher_recordsrow._lib/tally-reconciler.js(themissing_in_tallyauto-fix) inserts intotally_retry_queuewith columns that do not exist (tally_voucher_record_id,attempt,reason) and without the NOT NULLvoucher_type,payload_xmlandpayload_hash. That insert fails today. This PR does not change it.anvil-client.jsstill sendsstatus,approvalandpayload_hash. The server ignores them. I did not remove them from the client.🤖 Generated with Claude Code