Skip to content

fix(revenue): Generate Quote copies the opportunity's product lines onto the quote (#2750) - #2782

Merged
objectstack-fleet[bot] merged 8 commits into
mainfrom
claude/project-thread-ldylr9
Nov 25, 2026
Merged

objectstack-fleet[bot] merged 8 commits into
mainfrom
claude/project-thread-ldylr9

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Irene · project thread

Fixes #2750
Clause-②: no
Metadata-protocol: none
Metadata-impact: reviewer — a flow change (quote_generation) plus translations and docs; no permission set, sharing rule, object or field is touched, and nobody gains or loses access

维护者速读

  • 改了什么:销售在商机上点「生成报价单」后,商机上的每行产品明细会自动复制成报价单明细(产品、数量、销售单价、行折扣、描述),报价小计由这些明细汇总,生成时填的整单折扣在此基础上生效;商机没有明细时和以前一样只建报价单头。
  • 为什么改:产品负责人确认的缺陷——以前生成的报价单明细为 0 行,销售要把同样的产品、数量和单价再录一遍。
  • 风险与回滚:最坏情况是某行因价格表缺该产品或行折扣超过 60% 而复制不上,此时其余行照常复制,结果窗口会写明缺了几行、请到报价单上补;已生成的报价单不受影响,撤回这个合并即可恢复旧行为。
  • 先看:报价生成流程里新增的「读取商机明细并逐行复制」这一段,以及新增的「部分明细未复制」结果窗口。
  • 两分钟验证:在一个有两行产品明细的商机上点「生成报价单」并提交,打开新报价单,应看到两行一样的明细,小计等于商机金额。
  • 需要你做的:无。

What changes

  • src/revenue/flows/quote-generation.flow.ts: after create_quote, a get_record of the deal's crm_opportunity_line_item rows (limit: 1000, so a deal with no lines binds []) and a loop that creates one crm_quote_line_item per row through the ordinary insert, as the rep (the flow's default runAs: 'user'). Each iteration is a guarded() try/catch (the repo's helper, src/sales/flows/_guarded-iteration.ts), counting copiedCount / skippedCount.
    • Copied: crm_product, quantity, unit_price, discount, description. list_price is NOT sent: it is readonly on the quote line (the engine drops a caller's value) and quote_line_item_price_fill writes it from the quote's price book on every insert that names a product, the rule a hand-typed line meets. product_title and line_number come from their hooks the same way.
    • Totals: quote_total_rollup recomputes the quote Subtotal from its lines on each insert and quote_workflow derives Discount Amount / Total from it and the screen's discount. The header's subtotal: oppRecord.amount stays as the price of a line-less deal.
    • A refused line (no active price in the quote's book, or a line discount above the 60% ceiling the deal's lines do not carry) is contained to its iteration; the run ends on a new result_partial screen naming both counts. Clean copies end on the unchanged result screen (edges e6 / e16, complementary conditionals on vars.skippedCount). Edge e4 retired and left vacant; new edges e13–e17.
  • src/revenue/translations/{zh-CN,es-ES,ja-JP}.ts: screens.result_partial (title, description, link label).
  • Docs: content/docs/(product)/sales/quotes{,.zh-Hans,.zh-Hant}.mdx (Generating a quote steps 1–5, the sales-rep tip; the zh Discount-ceiling heading gets the explicit discount-ceiling anchor the new link needs, and the two existing in-page links move to it), the in-app page src/revenue/docs/crm_revenue_quotes{,.zh}.md, docs/feature-inventory.md row QUO-004.
  • .changeset/2750-quote-copies-opportunity-lines.md (patch).

Tests

  • New test/flow-quote-lines.test.ts (booted stack via @objectstack/verify, every write as a sales rep):
    • 2 deal lines → 2 quote lines with the same product, quantity, list price, sales price, discount, description; titles filled; numbered 1..2; Subtotal = Total = 3,835 = the deal amount; ends on result.
    • same deal with a 10% header discount → 3,835 / 383.50 / 3,451.50.
    • 0 deal lines → header-only quote priced from the amount (42,000 / 4,200 / 37,800).
    • editing a copied quote line leaves the deal line and the deal amount unchanged (and the quote re-rolls to 6,685); editing a deal line leaves the quote line unchanged.
    • a 70% deal line is refused by the quote's line ceiling: the other line is copied, Subtotal 700, the run ends on result_partial with "1 … (1 copied)".
    • structure + locale render of result_partial in en / zh-CN / es-ES / ja-JP.
  • Ablation (one-off, not kept): edge e13 re-pointed from get_opp_lines to check_stage (on-disk check: injected=1, removed=0) → the 2-line case goes red with expected [] to deeply equal [ { …(6) }, { …(6) } ]; restored with git checkout HEAD --, git diff HEAD empty.
Readings
  • pnpm verify at b7cbd9f: validate, typecheck, lint (--strict), hygiene, build all green; pnpm test Test Files 334 passed / 1 failed (335), Tests 6465 passed / 1 failed / 58 skipped. The one failure was test/docs-anchor-links.test.ts: the new #discount-ceiling link on the zh pages had no matching heading id.
  • Fixed in fe0e5c3 (docs-only: explicit anchor on the two zh headings, the two existing #折扣上限 links moved to it). At fe0e5c3: vitest run test/docs- → Test Files 36 passed, Tests 773 passed / 9 skipped. The full suite was not re-run after that docs-only commit; CI runs it.
  • vitest run test/flow-quote-lines.test.ts → 11/11; with test/flow-quote.test.ts and test/quote-generation-result-screen.test.ts → 42/42 (before the doc fix; no src/ or test/ change since b7cbd9f).

Acceptance notes

  • Line order: get_record takes no sort in 18.6.0 (GetRecordConfigSchema has no sort key), so quote lines are numbered in the order the read returns them. On the objectstack dev boot this was the deal's order; under @objectstack/verify it came back reversed, so the test matches lines by product. The docs say the order can differ. A sort on get_record is a platform capability, raised in the report rather than worked around here. quote_accepted_order already numbers order lines the same way.
  • List price: copied lines take their List Price from the quote's price book (Standard by default), so a deal line's list price shows up unchanged when the Standard book prices the product at its list price, which is the default. The sales price, which the totals read, is the deal's.
  • Observation, not filed: on the en run the quote's line-items table drew line 2 above line 1 (the stored line_numbers were 1 and 2, read back over REST); on the zh run it drew them in order. That is the related list's display order, unchanged by this PR.

Verification

Dev boot (objectstack dev, this branch), admin, en and zh-CN browser locales. Screenshots in the project files folder quote-from-opportunity-lines-2750/ (not committed):

  • en-two-lines-*: a deal with 2 lines (amount 38,300), discount 10% → quote QTE-0007 with 2 lines, Subtotal 38,300, Discount Amount 3,830, Total 34,470; result screen "Quote Created".
  • en-partial-*: a deal with a 70% line and a 2 × 6,000 line → quote with 1 line, Subtotal 12,000; result screen "Quote Created, Lines Missing … 1 of the opportunity's product lines could not be copied onto it (1 copied)".
  • zh-two-lines-* / zh-partial-*: the same in zh-CN ("报价单已创建" / "报价单已创建,部分明细未复制"); the quote page lists 报价单明细 2 with 小计 38,300.00.
  • Phone layout not checked.

Read first: src/revenue/flows/quote-generation.flow.ts (the get_opp_lines / copy_lines nodes and edges e6, e13–e17), then test/flow-quote-lines.test.ts.
Two-minute check: on a dev boot, Generate Quote on an opportunity with two product lines; the new quote shows the same two lines and a Subtotal equal to the opportunity's Amount.

🤖 Generated with Claude Code

…point)

Declarative updates of crm_sales_order.status, each offered only on the
statuses its move leaves from in sales_order_status_progression. Work in
progress: translations, tests and docs are not written yet, and the
read-only Status half waits on a decision.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J8VVAmQQaqVXpJepCqm4Xa
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J8VVAmQQaqVXpJepCqm4Xa
…ons, tests and docs

The three lifecycle actions from the resume point gain their confirm
text, labels and success messages in all four locale packs; a disallowed
move through an action answers the state machine's own refusal. Docs on
the order pages, the product-sale walk-through and the FAQ say to click
the buttons; Status stays editable on the form until objectstack#36806.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J8VVAmQQaqVXpJepCqm4Xa
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J8VVAmQQaqVXpJepCqm4Xa
…2750)

quote_generation now reads the deal's crm_opportunity_line_item rows after
create_quote and creates one crm_quote_line_item per row, as the rep, inside
a guarded loop: the quote-line hooks price, title, number and roll up each
copied line as they do a typed one, and the header discount applies to the
rolled-up subtotal. A line the quote refuses is counted and named on a new
result_partial screen (four locales). A deal with no lines keeps the
header-only quote. Docs (three locales), the in-app quote page and the
feature inventory row follow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J8VVAmQQaqVXpJepCqm4Xa
…new link resolves

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

vercel Bot commented Nov 25, 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 25, 2026 6:40am UTC

Request Review

@github-actions github-actions Bot added documentation Improvements or additions to documentation ci/cd CI plumbing and the verification pipeline metadata Declarative metadata — schema, security posture, UI surfaces backend Server-side behaviour — hooks, flows, actions labels Nov 25, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:hotcrm#1 · huangyiirene · session_01J8VVAmQQaqVXpJepCqm4Xa

Seat record · ACCEPT · head fe0e5c361eae96566ef0711428d4cead69d0e569 · 2026-11-25T06:47Z

  • 改了什么:从商机生成报价单时,把商机的产品明细逐行复制成报价明细;报价小计、总价由明细汇总,整单折扣在此基础上生效。
  • 为什么改:从商机生成报价单不带商机的产品明细:报价明细为 0 行,要重新录一遍 #2750(p1),用户不用再在报价上重录一遍产品。
  • 风险与回滚:复制走普通新建、以销售本人身份,报价明细的规则(价格表、行折扣上限)照常把关;被拒的行不会静默丢掉,结果页会说明几行没复制;整 PR 回退即可。
  • 要你做什么:无,席位挂自动合并。
  • 席位意见:L1 读过流程改动、四语结果页、测试;CI 全绿。

席位核对

  1. Shape: 12 files, +418 / -29; check-governed-merges: 0 of 12 paths governed, under the 3000-line threshold.
  2. Ruling fidelity: lines copied (product, quantity, sales price, line discount, description); totals roll up from the lines with the header discount on top; one-way copy; no lines → header-only quote as before.
  3. Accepted deviation from the card's wording: List Price (目录价) is not copied — it is readonly on the quote line and the engine would drop it; quote_line_item_price_fill stamps it from the quote's price book, the same rule a typed line meets. Sales price is copied.
  4. A line the quote refuses (price book has no active price, or discount above the per-line ceiling) is counted per guarded iteration and reported on the translated result_partial screen; the other lines are still copied (tests 5–6).
  5. Gate check-runs on head fe0e5c361eae96566ef0711428d4cead69d0e569: all 20 success (Test shards 1–8, Build and Test, Validate, Playwright, Docs Locale Parity, Check Changeset, link-check, CodeQL). New test/flow-quote-lines.test.ts 11/11 locally, ablation reported red.
  6. Out of scope: get_record takes no sort on 18.6.0, so copied line numbers follow read order (also true of quote_accepted_order); documented as "order can differ". Not filed.
  7. Landing: ready + auto-merge through the merge queue.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 25, 2026 06:49
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit 9b73510 Nov 25, 2026
21 checks passed
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.

从商机生成报价单不带商机的产品明细:报价明细为 0 行,要重新录一遍

2 participants