Repository navigation
feat(orders): the Mode B handoff, sent from the order - #630
Open
privatejoel wants to merge 3 commits into
Open
privatejoel wants to merge 3 commits into
privatejoel wants to merge 3 commits into
Conversation
This is C-18 (plan PR 16, R-F3). The engineer sends the order to the order processing team with one click in the SO workspace. The clerk then keys the sales order into Tally. - New endpoint /api/orders/handoff. GET gives the preview. POST sends. The gate is write, then the new action order.handoff (sales_engineer, sales_manager, operator, admin). The action is in SERVER_ACTIONS and in rbac.ts ACTIONS. - The handoff is off unless order_handoff_enabled is on. It is for Mode B only. The flag default does not change. - The send is direct, through sendCommunication. The row starts as a draft, so the reaper cannot send it. With no mail provider, the order shows not_configured and the row becomes failed. - Reply-to is the tenant's Anvil inbound address when one exists. Else it is the engineer. The engineer is in CC. The Graph branch of sendCommunication now passes reply_to. - The send writes handoff_status, handoff_sent_at, handoff_sent_by (ctx.user.id), handoff_comm_id, handoff_payload, dispatch_plan, and dispatch_mode for one origin group. handoff_payload.payload_hash is the order's payload_hash at send (the contract with C-9). - An undecided critical terms flag blocks the send (409 TERMS_UNDECIDED). Blank required fields, a missing mode, a blocking finding, a bad status or no recipient also block it. - The email has no prices. It attaches the SO PDF and the original PO. - The SO PDF builder and loader move to _lib/so-document.js, so the download and the handoff render the same PDF. - The register shows the handoff column and a "not handed off" filter. The workspace and the register show "changed since handoff". No migration. Migration 251 has the columns. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…l origin map name The owner made three changes to the handoff (C-18). - Reply-to is now the engineer who sends the handoff, until C-33 exists. A clerk's reply to the tenant's inbound address would enter the Postmark pipeline as a new PO. The engineer stays in CC. The Graph branch still passes reply_to. The email no longer has the "reply to all" text. - The SO PDF prints "-" (not an em dash) for a blank description and a blank seller name. - part-origin.js exports ORIGIN_COUNTRY. order-handoff.js was the only importer outside that file. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ents The comments in part-origin.js named the tenant and used em dashes. This PR touches the file, so the comments now use neutral words and colons. The code does not change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 is C-18 of docs/SO_EXECUTION_COHESION.md (R-F3), built as plan PR 16 of docs/SO_TERMS_AND_HANDOFF_SCOPE.md (section 8). The engineer sends a Mode B order to the order processing team with one click in the SO workspace. The clerk then keys the sales order into Tally.
The owner accepted all defaults of C-D11, C-D12 and C-D13. This PR applies them.
The endpoint:
/api/orders/handoffGET ?order_id=gives the preview: the prefill with its sources, the origin groups and their modes, the To and CC lines with a reason for each address, the subject, the body, the attachments and the blockers.POST { order_id, fields?, resend? }sends.fieldsis{ required_by, contact_name, contact_phone, modes }. A key that you do not send keeps the prefill.resend: truesends a handoff again.requirePermission(ctx, "write"), thenrequireAction(ctx, "order.handoff"). The new action is inSERVER_ACTIONS(auth.js) and inACTIONS(rbac.ts). Roles:sales_engineer,sales_manager,operator,admin. The route is inSTATIC_ROUTES.tenant_settings.order_handoff_enabledis on. It is for Mode B only. Off gives{ enabled: false }on GET and 409 on POST. The flag default does not change.migration_251_not_applied. The endpoint never reads that as "not handed off".The five R-F3 changes
draft, andsendCommunicationsends it in the same request. The reaper reads onlyqueuedrows, so it cannot send this row. With no mail provider, the order showsnot_configured, and the row becomesfailedwithmetadata.error = "no_provider_at_send". The screen says "Not sent: no mail provider".sendCommunicationnow passesreply_to(buildGraphMessagesetsreplyTo).handoff_status,handoff_sent_at,handoff_sent_by(ctx.user.id),handoff_comm_id,handoff_payload,dispatch_plan, anddispatch_modewhen there is one origin group.handoff_payload.payload_hashis the order'spayload_hashat send. This is the contract with C-9 (feat(orders): one derived execution stage on every order endpoint #626).payload_hashmoves after the send, the workspace chip and the register say "Changed since handoff". The button becomes "Re-send handoff". The rule is the same as inorder-stage.js(C-9).The decisions (C-D11, C-D12)
TERMS_UNDECIDED), a blank material required date, a blank contact name, an origin group with no mode or with a mode that is not in its group, an unresolved blocking finding, a CANCELLED, DUPLICATE, REUSED or BLOCKED order, no lines, and no To recipient (409HANDOFF_BLOCKED).source_country, then the item master. If two strong signals do not agree, the line goes tounknown. The item master is weak: it is read only when no other signal exists.resend: true.Other changes
src/api/_lib/so-document.js: the SO PDF builder and its loader move here fromorders/so_pdf.js. The download and the handoff render the same PDF.so_pdf.jsre-exports the builder. When a dispatch plan has more than one group, the PDF prints "As per dispatch plan".terms/check.jsexportspoDocumentOf, so the handoff finds the original PO the same way.Deploy notes
order_handoff_enabledfor the pilot after this PR and the shadow week.Tests
New:
src/v3-app/api-orders-handoff.test.js: the parity oforder.handoff, the role gate, flag off, Mode A, migration 251 missing, the preview and its sources, the send, no prices, the actor isctx.user.id, the storedpayload_hash, the audit has no contact data, the dispatch plan and the PDF label, the second click and Send again, every blocker, terms (critical blocks, high does not, shadow does not), origin precedence, and tenancy.src/v3-app/api-orders-handoff.send-direct.test.js: the row is inserted as a draft and is never queued;not_configuredwith no provider; a provider refusal isfailed.src/v3-app/api-orders-handoff.reply-to.test.js: replies go to the engineer who sends (an operator's send replies to the operator); with a Postmark inbound address or a watched Outlook mailbox set, replies still go to the engineer; the real Graph message carries the engineer asreplyTo.src/v3-app/api-orders-handoff.changed-since.test.js: the hash moves, then a re-send stores the new hash.src/v3-app/api-order-register.handoff-column.test.js: the column, the filter, no contact data, the export words.src/v3-app/components/OrderHandoffButton.test.tsx: hidden when off or for a role without the action, sends the edited fields, the confirm for Send again, the server's blockers.src/v3-app/test-support/handoff-harness.js: the shared in-memory stand-in for the endpoint tests.Changed:
screens/so-register.test.tsx(the newnot_handed_offparameter).Follow-up commits on this branch:
9ca9aa7f(reply-to is the engineer; the SO PDF prints "-" for a blank description and seller name;part-origin.jsexportsORIGIN_COUNTRY) and40fd3918(the part-origin comments name no tenant and use no em dashes; no code change).Mutation check. I broke each rule, saw a test fail, and restored it. 34 of 34 killed:
requireActionremoved.order.handoffmissing fromSERVER_ACTIONS.ctx.userId.queued.reply_to.buildGraphMessagedropsreplyTo.dispatch_modeis written for a mixed order.Gates:
npm run check: pass.npm run lint: 0 errors (the warnings were there before; three move with the code toso-document.js).npm run build: pass. I deleted the build outputs.npm run verify: pass. It rewrote docs/RBAC_AUDIT.md and docs/WRITE_PATH_AUDIT.md with drift that is on main too. I restored both and kept only the neworders/handoff.js | writerow in RBAC_AUDIT.md.npm run eval:golden: pass, aggregate 1.000.NODE_OPTIONS=--no-experimental-webstorage npx vitest run: 632 files, 7418 tests, all pass (run again on40fd3918).Not covered
order_handoff_senderis not read.sendCommunicationuses Graph when it is connected, else the mailer (decision 4 default).order_handoff_templateis not read. The template is the decision 5 default.communications.to_addrholds one address.shortcut:inorders/handoff.js).fix/honest-send-status(fix(ui): show only what the server confirmed, and say when the worker is down #623) also changescomms-send.js. This PR changes only the Graph call line, which fix(ui): show only what the server confirmed, and say when the worker is down #623 does not touch.🤖 Generated with Claude Code