Skip to content

feat(sales): an order links by hand only an Activated framework contract of its account (#2917) - #2928

Merged
objectstack-fleet[bot] merged 4 commits into
mainfrom
claude/issue-2917-order-contract-link-rule
Dec 2, 2026
Merged

objectstack-fleet[bot] merged 4 commits into
mainfrom
claude/issue-2917-order-contract-link-rule

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Irene · project thread
Fixes #2917

Clause-②: no
Metadata-protocol: none
Metadata-impact: maintainer — a save-time rule added: a person's change of an order's Contract is refused unless the contract is an Activated framework contract; plus a warning on the Order Date

维护者速读

  • 销售在订单上手动选合同时,只能看到并保存同一客户、已激活的框架合同;已过期、草稿、订单合同和"其他"合同都选不到,通过接口硬塞也会被拒并说明原因。
  • 属于订单与合同(订单到回款)这条线,解决测试中发现的"过期合同还能接新订单"。
  • 只在有人改订单的关联合同时检查:清空总是允许,合同后来过期的老订单照常编辑保存,起草合同和系统写入不受影响;规则可随代码撤回。
  • 无。

What changes

  • Picker. crm_sales_order.crm_contract keeps dependsOn: ['crm_account'] and gains lookupFilters (form framework, status activated) and allowCreate: false (a contract created from the picker would be a Draft the order may not take).
  • Save. New hook sales_order_contract_link (beforeInsert/beforeUpdate, priority 95): a person's write that sets Contract to a contract that is not framework + activated is refused, VALIDATION_FAILED 400, naming the contract number; localized in zh-CN, ja-JP, es-ES. Judged only when Contract changes to a non-empty value; clearing passes; no person on the write (ctx.user absent or session.isSystem) is not judged, which covers Draft Contract's elevated write, the seed, system imports and flows. The account half stays contract_same_account (Sales order: an order could be saved with another account's contract, so its Order to Cash rows could not be saved against it #2728), which keeps its own message on Contract.
  • Warning. New contract_term_order_date (conditional, warning): the Order Date outside the contract's Start Date to End Date warns and saves, judged when the write links the contract or changes the date.
  • Docs: src/docs/crm_sales_orders.md + .zh.md, content/docs/(product)/sales/orders.mdx + zh-Hans + zh-Hant. Changeset 2917-order-contract-link-rule.md.
  • Wording: the refusal says "framework contract" / 框架合同 / 基本契約 / Contrato Marco, today's form label in each pack, so it reads with the UI; Rename the "Framework Contract" form to "Multi-Order Contract" (display name only; value framework unchanged) #2916's rename sweeps it with the rest.

Read first (by risk): src/sales/objects/sales_order.hook.ts (the person signal and the unchanged-value early return), src/sales/objects/sales_order.object.ts (the warning's previous predicate), test/helpers/verify-stack.ts (activateContract, used by the re-fixtured suites).

Tests

  • New test/sales-order-contract-link.test.ts (18 cases, booted stack, REST door): link to Activated framework on create and update; refuse Expired, Terminated, Draft, In Approval framework, Activated and Draft order contract, Activated Other, each on create and update with code and message; another account's contract refused; refusal in zh-CN/ja-JP/es-ES from the packs; clear allowed; order still saves after its contract expires (Contract unchanged and sent back as it was); system insert with an Expired contract not judged; Draft Contract still links its Draft order contract; Order Date before/after term warns and saves, silent inside and on an unrelated edit; picker metadata pinned.
  • Re-fixtured (stale fixtures that linked orders by hand to Draft or other contracts): framework-contract-quota, o2c-order-contract-later, o2c-parallel-figures, o2c-sales-order, sales-order-draft-contract, sales-order. Each now activates the contract (system write) or makes the ineligible link a system write, as an import would. Business assertions unchanged.
  • Rosters: refusal-envelope count 116 → 117, sales-order hook roster + sales_order_contract_link.
  • Ablation (on disk, restored): rule neutralized → 10 of 18 red (every refusal, picker pin, locale, warning); person exemption removed → Draft Contract and system-insert cases red.

Acceptance notes

  • Picker measured in the booted console (19.0.0-next.3): the edit form's Contract picker sends one query ["and",["contract_form","=","framework"],["status","=","activated"],["crm_account","=",ACCOUNT]], so lookupFilters and dependsOn combine; the "Browse all records" grid sends the same filter; Acme with CTR-0001 (Activated framework), CTR-0005 (Draft framework), CTR-0006 (Draft Other) listed CTR-0001 only. After allowCreate: false the picker shows no "Create new".
  • Existing out-of-filter value: an order linked to CTR-0001, then CTR-0001 expired, opens its edit form showing "Acme Platform Subscription" (read by id, not through the filter); saving a PO change sent only customer_po_number and answered 200.
  • Server enforcement: lookupFilters is picker-only by the platform's own describe ("The picker narrows the choice only: a rule the save must enforce belongs on the server too"), hence the hook. No platform gap to file.
  • Rule 6 list (existing non-conforming links): on the shipped demo data there are none: the one linked order, SO-0001, names CTR-0001, Activated framework. The list for another install is two reads with an admin session: POST /api/v1/data/crm_contract/query (fields id, contract_number, status, contract_form) and POST /api/v1/data/crm_sales_order/query (fields order_number, crm_contract); list orders whose contract is not framework + activated, and order contracts (contract_form: order) named by more than one order. No script ships: scripts/ is outside this card's claimed file surface (open question in the report).

Verification

Two-minute check: pnpm dev, open any order, Edit, open Contract: only that account's Activated framework contracts are listed, and no Create new.

Final head 91c54e54: pnpm validate 0, pnpm typecheck 0, pnpm lint 0, pnpm hygiene 0; full suite vitest run --shard=N/6, six shards all exit 0.

Full suite, per shard (head 91c54e5)
  • 1/6: Test Files 62 passed, Tests 928 passed, 14 skipped
  • 2/6: Test Files 61 passed, Tests 1062 passed, 1 skipped
  • 3/6: Test Files 61 passed, Tests 1175 passed, 11 skipped
  • 4/6: Test Files 61 passed, Tests 1030 passed, 24 skipped
  • 5/6: Test Files 61 passed, Tests 1282 passed, 6 skipped
  • 6/6: Test Files 61 passed, Tests 1394 passed, 2 skipped
Live API on the booted app (zh-CN)
  • PATCH order to CTR-0005 (Draft framework): 400 VALIDATION_FAILED 「合同CTR-0005不能关联到这张订单。只能选择同一客户、已激活的框架合同:请另选一份,或清空关联合同。」
  • PATCH to CTR-0006 (Draft Other): 400, same sentence naming CTR-0006
  • PATCH to CTR-0001 (Activated framework): 200; clear: 200

🤖 Generated with Claude Code

https://claude.ai/code/session_01J8VVAk8tegvAi1ECkgCFfc

…tract of its account (#2917)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J8VVAk8tegvAi1ECkgCFfc
The account half of the rule stays contract_same_account's (#2728).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J8VVAk8tegvAi1ECkgCFfc
…cker filter (#2917)

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

vercel Bot commented Dec 2, 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 Dec 2, 2026 11:07am 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 Dec 2, 2026
@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review December 2, 2026 11:11
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:hotcrm#1 · huangyiirene · session_01J8VVAk8tegvAi1ECkgCFfc

ACCEPT · 2026-12-02T11:11Z

Head-sha: 91c54e54

维护者速读

  • 改了什么:订单的「合同」选择框只列出同一客户、已激活的框架(多订单)合同,也不能在选择框里新建合同。有人手动挂别的合同(草稿、已过期、订单合同、「其他」)保存会被拒绝并说明原因。清空合同、合同没变的保存、系统写入(含「起草合同」)都不拦。下单日期不在合同期内只警告。手册三语已同步。
  • 没做到的:存量挂错的清单没有做成脚本,PR 里写了两步查询的方法;演示数据里没有挂错的。您本地已知的一例是 CTR-0005(订单合同)挂了 SO-0004 和 SO-0005,需要手工把 SO-0005 摘下来或改挂到多订单合同。
  • 要你做什么:无。按您「派吧」与「做完的,没有问题的都自动合并」,席位合并(新增保存规则属于维护者级元数据改动,按您的常设授权合并)。

席位核对

  • Form: Fixes #2917; draft → ready to main. lookupFilters (framework + activated) beside dependsOn: ['crm_account'], allowCreate: false; hook sales_order_contract_link refuses a person's change to an ineligible contract (400, contract number in the message, zh-CN/ja-JP/es-ES); warning rule contract_term_order_date; docs — on the amended claim surface. Six fixtures that linked ineligible contracts by hand now use a system write; assertions unchanged.
  • Picker measured on 19.0.0-next.3: one combined filter, out-of-filter existing value still displays and saves — no platform card needed.
  • Test: 18 new cases; ablation → 10 failed (rule off), 2 failed (exemption off). Full suite as 6 locked shards on 91c54e54, all exit 0; validate/typecheck/lint/hygiene exit 0.
  • Overlap: Rename the "Framework Contract" form to "Multi-Order Contract" (display name only; value framework unchanged) #2916 renames 框架合同 in the same two pack files; whichever lands second merges main.
  • Landing: seat lands on the maintainer's standing word 「做完的,没有问题的都自动合并」 (2026-11-26T10:39Z); auto-merge waits for required checks.

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.

An order may link only an Activated multi-order contract of the same account (checked when a person changes the field; system writes exempt)

1 participant