Skip to content

feat(revenue): a quote discounted above 30% goes to a sales manager for approval (#2751) - #2848

Merged
os-zhuang merged 9 commits into
mainfrom
claude/vigilant-tesla-nnr4ts
Nov 29, 2026
Merged

os-zhuang merged 9 commits into
mainfrom
claude/vigilant-tesla-nnr4ts

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2751

Metadata-impact: maintainer — any other change to who can see or change what: a quote discounted above 30% can be presented only after a sales manager's approval, and the quote and its lines are locked while it waits; a hook changed (the settled-quote freeze lets the platform's line roll-up through)
Clause-②: no
Metadata-protocol: none
Ruling-ref: hotcrm#2751 comment 7157473292 — the maintainer, verbatim: 「2751 同意,开始认领并处理这个任务」 (/pm-dispatch hotcrm session, 2026-11-25T08:47Z), on option A narrowed (30% on the quote's or any line's discount, no amount threshold, sales-manager position with excludeSubmitter, quote and lines locked, reject to Draft, the gate on every path to Presented including print, the platform approval process); held by his 「A,允许按卡开分支,四张卡二号席认领」 (comment 7158163459, 2026-11-25T09:18Z) until the platform line lock shipped, resumed on 19.0.0-next.2 (comment 7247295054)

维护者速读

  • 销售代表在报价单上点「提交审核」后,折扣超过 30% 的报价会进入销售经理的待审批,审批期间报价和明细都改不了,批准后才能标记为已提交。
  • 解决产品负责人在线上 6.6.0 测到的报价「提交审核却没人审、自己就能放行、审核中还能改价」这个高优先级问题,按您 11 月 25 日选的方案 A 落地。
  • 出错时最坏是某些报价无法标记为已提交或被锁住;可以整体撤回本次改动,已有报价的数据不受影响。
  • 请您审阅并合并这个草稿。

What changes

  • quote_discount_approval (src/revenue/flows/quote-discount-approval.flow.ts, record-after-write, one flow per protocol 19's flow-create-update-pair): a quote moved into, or created in, In Review whose Discount % or any line's is above QUOTE_DISCOUNT_APPROVAL_PERCENT (30, src/sales/objects/_thresholds.ts) opens an approval for the crm_sales_manager position: excludeSubmitter, lockRecord, first_response, onEmptyApprovers: 'admin_rescue', mirrored into discount_approval_status. Approve stamps approved_discount; reject or recall returns the quote to Draft.
  • The line lock is the platform's. @objectstack/plugin-approvals@19.0.0-next.2 binds bindDetailRowLockHook beside the record lock, so a held quote's master-detail lines refuse insert, update, delete and a move on or off, the last line included (the 18.6.0 gap that put this card on hold). No hotcrm-side line freeze is written.
  • crm_quote gains three read-only fields in the pricing group: max_line_discount (a max summary of the lines), discount_approval_status (Not Required, Pending, Approved, Rejected) and approved_discount; and the transition gate discount_approval_before_presented on the move into Presented (Mark Presented, Edit, REST, and the print flow, which runs as the rep).
  • Actions: unchanged. While Discount Approval is Pending, Mark Presented, Reject and Revise stay on the screen and the approval's record lock refuses them RECORD_LOCKED. Hiding them while Pending was split out of this PR at L1 and is Quote: hide Mark Presented, Reject and Revise while the discount approval is Pending (the courtesy half split out of PR #2848) #2850, blocked on this PR.
  • The settled-quote freeze (quote_workflow, src/revenue/objects/quote.hook.ts) lists max_line_discount among the platform fields: the platform recomputes the roll-up as the caller when a settled quote's lines cascade on its delete, and the freeze refused that write (measured: four test/quote-line-freeze.test.ts delete cases went 500 / cascade stopped before this line, green after).
  • 19 conventions: no form sections (fields carry group), no permission-set change (no set hides the new fields, so View All / Modify All no longer opening fields does not reach them), the flow labels and steps in every locale (i18n/missing-flow 0).
  • Translations in en, zh-CN, ja-JP, es-ES (fields, options, the gate's message, the flow and its steps). Docs: content/docs/(product)/sales/quotes*.mdx (en, zh-Hans, zh-Hant), the automation table (three locales, 51 flows), the in-app Revenue manual (src/revenue/docs/crm_revenue_quotes*.md), docs/requirements/0013-quote-discount-approval.md (REQ-0013), docs/feature-inventory.md QUO-014, the flow/field counts in README, introduction and STATUS. Changeset .changeset/2751-quote-discount-approval.md (minor).

Tests

test/quote-discount-approval.test.ts pins the three p1 symptoms of the hold comment against the real approval (action door, approvals door, data door, REST):

  • no approver: a request for the sales managers, in both managers' approvals Inbox and not the rep's; any line over the line sends it; a quote created In Review is sent; a quote at exactly 30% opens nothing and is presented as before;
  • self-release: the submitter's Mark Presented, Reject and Revise refused RECORD_LOCKED while pending, through the action door the console posts to; a manager's own quote cannot be approved by them (403) and another manager approves it; an over-the-line Draft refused straight to Presented (Edit and REST); approved then presented; a discount deepened after the approval refused; a rejection back to Draft and still not presentable;
  • price edits during review: the header discount, a new line, a line's discount, price and quantity, the last line's delete, the only line's move off and a line's move on, and the REST door all refused RECORD_LOCKED with nothing stored; a manager may still delete the held quote (quote, lines and request go); after the decision the quote and lines take edits again.

test/flow-quote-print-presented.test.ts adds the print path: an unapproved over-the-line Draft keeps Draft, a pending quote keeps In Review, an approved quote is presented by printing.

Red before, green after. The same file on origin/main 142e7a1 with only the constant added (an origin/main worktree, QUOTE_DISCOUNT_APPROVAL_PERCENT = 30 in _thresholds.ts, nothing else). At 72326be the file held 23 cases and the reviewer measured 23 failed of 23 (this body first said 22 of 22, a miscount). At 8128731 it holds 22 (the button case went with the hiding) and reads 22 failed of 22. Not every one is red on behaviour: 9 fail on it (no pending approval request on the quote 7, expected [] to have a length of 1 1, an over-the-line quote no manager approved was presented 1), and 13 fail first on a fixture field the change adds, waiting for the max_line_discount roll-up to read a value (expected undefined to be 40, ... to be 30, ... to be +0), before reaching the behaviour they pin. On this branch: green.

Full suite at 72326be

pnpm build then pnpm exec vitest run --maxWorkers=2 under the shared verify lock: VERDICT command-exit 0, Test Files 346 passed (346), Tests 6625 passed | 58 skipped (6683). The run before the last commit (at aa40142) read 10 failed in six files, each fixed in 72326be: the four settled-quote delete cases (the freeze line above), the two ceiling cases whose quote now needs the approval verdict, the flow-elevation rationale, the runtime-coverage roster, and the STATUS / README / introduction counts.

L1 fix round at 8128731

Under the shared verify lock: pnpm validate exit 0 (Validation passed) · pnpm typecheck exit 0 · pnpm lint exit 0, 0 warnings, 54 suggestions · pnpm hygiene exit 0 (source hygiene clean), all VERDICT command-exit 0. The test files that read the touched files (test/docs-*, test/quote-*, test/automation-docs-coverage, test/action-references, test/flow-quote-print-presented, test/changeset-version-wrapper): Test Files 57 passed (57), Tests 1073 passed | 9 skipped (1082). The full suite is CI's on this head.

Acceptance notes

  • Two items go past the ruling's literal words, both necessary consequences of it: the approved_discount rule ("approved for this deep a discount": discount_approval_before_presented lets an over-the-line quote into Presented only when approved_discount is at least both its Discount % and its deepest line's, without which a discount deepened after the approval would be presented on the old approval), and the freeze listing max_line_discount (without it a settled quote with lines could not be deleted). Hiding Mark Presented, Reject and Revise while pending is no longer in this PR: it moved to Quote: hide Mark Presented, Reject and Revise while the discount approval is Pending (the courtesy half split out of PR #2848) #2850.
  • A quote sitting In Review when this ships has no request; one above 30% is refused at Mark Presented and is sent by Revise then Submit for Review (docs say so). Seed data holds one In Review quote, at 15%.
  • After an approval the quote is unlocked; a discount raised then is caught at Presented, not by a new request (only the move into In Review opens one). The gate's message names the way out.
  • Boot log, not new in kind: the seeder's line items reference their quote by name, and the platform's summary recompute reads that name as an id (Roll-up summary recompute failed … Record … not found in crm_quote), the same warning crm_project.approved_budget already logs on main. Not filed from here; the seat may route it.
  • Serial Clean up 9 custom pages: 7 record detail pages return to the platform default, Sales Home and Account Workbench go; the quote and contract print pages stay #2740: this diff does not touch src/revenue/pages/quote_detail.page.ts or src/sales/pages/contract_detail.page.ts.

Verification

Two-minute check: pnpm exec vitest run test/quote-discount-approval.test.ts — expect 22 passed. In the console: as a sales rep, give a quote a 40% discount and click Submit for Review: the quote reads In Review, Discount Approval Pending, and clicking Mark Presented is refused with "This Quote is locked while an approval is in progress"; signed in as a sales manager, the request is in the approvals Inbox.

Read first, by risk: src/revenue/objects/quote.object.ts (the discount_approval_before_presented condition), src/revenue/flows/quote-discount-approval.flow.ts (the start condition and the closing writes), src/revenue/objects/quote.hook.ts (the one freeze line).

Local gates at 72326be

pnpm validate exit 0 (38 Objects 641 Fields, 51 Flows) · pnpm typecheck exit 0 · pnpm lint (os lint --strict) exit 0, 0 warnings, 54 suggestions · pnpm hygiene exit 0 (source hygiene clean) · pnpm build exit 0 · pnpm test as above. CI reads on the PR's own check-runs.


Generated by Claude Code

…ine lock (#2751)

Work in progress, not for review: the ruling's line-item lock is not fully
available on the pinned @objectstack 18.6.0 (plugin-approvals has no
master-detail row lock there; it is merged upstream, unreleased). Parked on
this branch so the card resumes from it once the maintainer decides.

- QUOTE_DISCOUNT_APPROVAL_PERCENT = 30 beside the 60 ceiling
- crm_quote: max_line_discount (summary, max), discount_approval_status
  (approval mirror), approved_discount, and the transition gate
  discount_approval_before_presented
- quote_discount_approval (+ insert twin): Sales Manager position,
  excludeSubmitter, lockRecord; reject or recall -> Draft

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017xRBcV3h25dAMNWki8e1ns
… platform's line lock (#2751)

The WIP's two flows become one record-after-write flow (protocol 19,
flow-create-update-pair). The quote's lines are held by the platform's
detail-row lock (bindDetailRowLockHook, @objectstack/plugin-approvals
19.0.0-next.2), so the 18.6.0 last-line gap is gone. Mark Presented,
Reject and Revise are not offered while the approval is pending. The new
fields, the gate's message and the flow's steps are in all four packs.
The test pins the three symptoms: no approver, self-release, price edits
during review.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017xRBcV3h25dAMNWki8e1ns
…l, the automation table, REQ-0013 and QUO-014; print-path pins; changeset (#2751)

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017xRBcV3h25dAMNWki8e1ns
…the line roll-up; counts and coverage follow the new flow (#2751)

The settled-quote freeze refused the platform's recompute of
max_line_discount, which the cascade of a quote delete triggers as the
caller: the freeze now treats that roll-up as a platform field. The
docs' flow and field counts read 51 and 641, the new flow's runAs
carries its rationale, the print suite names the flow it drives, and
the ceiling suite records the approval its presented quote needs.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017xRBcV3h25dAMNWki8e1ns
@vercel

vercel Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
hotcrm Ignored Ignored Nov 29, 2026 10:17am UTC

Request Review

…a discount approval is pending; the lock refuses them (#2751)

The hiding goes past the ruling's words and moves to its own card. The
record lock remains the control, pinned through the action door. Docs,
the in-app manual, REQ-0013 and the changeset say "refused" instead of
"not offered"; the changeset also names the settled-quote freeze change.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017xRBcV3h25dAMNWki8e1ns
Brings in the shard-2 timeout fix from #2854.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017xRBcV3h25dAMNWki8e1ns
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:hotcrm#2 · sunhaolin · session_017xRBcV3h25dAMNWki8e1ns

维护者速读

席位核对 — ACCEPT · repo:hotcrm#2 · head f6fad95

  1. Shape.
    • Quote discount approval: one record-after-write flow, plus a quote transition gate.
    • The quote's line items are locked by the platform's bindDetailRowLockHook (@objectstack/plugin-approvals@19.0.0-next.2). hotcrm writes no lock of its own.
    • A freeze exemption in quote.hook.ts lets the max_line_discount roll-up through.
    • Docs in 3 locales and the in-app manual are updated, along with REQ-0013 and the changeset.
    • No governed path is touched. Maintainer class.
  2. Premise measured.
    • The ruling is met line by line (L1): over 30 % on the header or on any line; approver crm_sales_manager with excludeSubmitter; lockRecord; reject and recall return to Draft.
    • Three 18.6.0 gaps are now refused with RECORD_LOCKED: deleting the last line, moving a line off, and moving a line on.
    • Self-release is closed. A rep's forged status is dropped, and a manager's own approval answers 403.
    • Red before the change: 22/22 on main. 9 of those fail on behaviour and 13 on the roll-up fixture field.
  3. Gate check-runs on f6fad950. 20 of 20 succeed, read by the seat. This includes shard 2, after main brought test(psa): give the bulk-submit cases of hotcrm#2764 a measured budget (#2849) #2854.
  4. Accepted deviations.
  5. Out of scope.
  6. Landing. Maintainer merge. Fixes #2751. After the merge, Quote: hide Mark Presented, Reject and Revise while the discount approval is Pending (the courtesy half split out of PR #2848) #2850 unblocks.

@objectstack-fleet objectstack-fleet Bot added the pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue label Nov 29, 2026
Resolves the one conflict, docs/STATUS.md: the branch added 3 fields
and 1 flow (the quote discount approval), main removed 2 pages (the
quote and contract detail shells, #2740). The counters combine to
641 Fields, 2 Pages, 51 Flows, matching what `pnpm validate` prints
on the merged tree.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017xRBcV3h25dAMNWki8e1ns
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:hotcrm#2 · sunhaolin · session_017xRBcV3h25dAMNWki8e1ns

席位核对 — ACCEPT · repo:hotcrm#2 · head 1a85f31

This is a base update only. The ACCEPT of seat record 7250855170 (head f6fad950) carries over.

@os-zhuang
os-zhuang marked this pull request as ready for review November 29, 2026 13:08
@os-zhuang
os-zhuang added this pull request to the merge queue Nov 29, 2026
Merged via the queue into main with commit 5ebc44e Nov 29, 2026
21 of 22 checks passed
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:hotcrm#2 · sunhaolin · session_017xRBcV3h25dAMNWki8e1ns

Merged as 5ebc44e5a8, so pm:awaiting-merge comes off. #2850 is unblocked.

@objectstack-fleet objectstack-fleet Bot removed the pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue label Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Server-side behaviour — hooks, flows, actions ci/cd CI plumbing and the verification pipeline documentation Improvements or additions to documentation metadata Declarative metadata — schema, security posture, UI surfaces

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[decision] 报价「提交审核」没有审核人:状态变成审核中,但没人审批、自己就能放行、审核期间还能改价

3 participants