Skip to content

feat(sales): contracts have a Contract Name, their record title (#2746) - #2787

Merged
objectstack-fleet[bot] merged 5 commits into
mainfrom
claude/issue-2746
Nov 25, 2026
Merged

objectstack-fleet[bot] merged 5 commits into
mainfrom
claude/issue-2746

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Irene · project thread

Fixes #2746
Clause-②: no
Metadata-protocol: none
Metadata-impact: maintainer — a new required field on an existing object (crm_contract.name, the new record title; rows saved before it hold no name until the backfill script runs) and changed seed data (the four demo contracts, en and zh-CN, gain names)

维护者速读

  • 用户能看到什么变化:所有人在合同列表、合同详情页头、客户的合同页签、回款节点和发票上的合同选择器、审批和通知里,看到的都从「CTR-0006」变成「合同名称」,编号仍并列显示(选择器里写在名称下方);新建合同时必须填合同名称,从订单起草的合同自动带订单(即报价)的名称。
  • 为什么做:产品负责人确认的问题——同一客户有多份合同时只看到编号,要逐个点开才分得清;合同是销售到回款链路上唯一没有名称的单据。
  • 出错会怎样:已安装的客户升级后,旧合同在跑补名脚本之前没有名称,页头和选择器会显示记录 ID;旧合同照常可编辑。改动可整体撤回,撤回后新加的名称列留在数据库里、不再被读取。
  • 要你做什么:合并前确认升级说明里「升级后由管理员运行补名脚本」这一步可以接受(托管环境由环境负责人决定何时运行)。

What changes

  • crm_contract.name, "Contract Name" — Field.text, required: true, searchable, 255 chars, group basic; it is the nameField. searchableFields: ['name', 'contract_number']. contract_number stays first in highlightFields, so the record header's strip and the platform lookup picker show the number beside the name (the picker draws the strip's first field under each candidate and as its second column — read in the 18.6.0 console bundle, then seen in the browser, screenshots below). No formula title: the platform's own picker columns carry the number.
  • No storage.notNull, on purpose (AGENTS.md rule 11: comment at the field, pinned in test/contract-name.test.ts). Measured on 18.6.0: booting the new field with storage: { notNull: true } against a database created before it fails the contract's whole schema sync — alter table crm_contract add column name text not null - Cannot add a NOT NULL column with default value NULL — and leaves contracts unwritable. required alone is the spec's sanctioned posture for this ("required alone is the criteria_json posture (legacy null rows rest)", FieldSchema.storage): every new write needs a name, and old rows still save edits that leave the name alone (measured, and pinned).
  • Where the name shows: All Contracts first column (link, pinned), number second; calendar, gantt and timeline titles; the new-contract form asks for it first; the account, opportunity and contact Contracts tabs (relatedListColumns); the printed contract's parties block.
  • Drafted contracts carry the source's name (_contract-draft.ts gains ContractDraftSource.name): Draft Contract on an order takes the order's name (an order created from a quote already carries the quote's name); the switched-off quote_accepted_contract_draft flow takes the quote's name, else its opportunity's (new get_opportunity node), else the quote number — the ruling's "报价名称(没有则带商机名称)".
  • Notices name the contract by number and name: crm.contract_drafted, crm.contract_expired, crm.contract_renewal read one composed {{contract}} (CTR-0006 · Annual Service 2027, the number alone for an unnamed row) built by _contract-label.ts, in all four template packs — one value because a notice missing a value is not sent (notification templates: declare required variables or write literal defaults, so a flow that omits a new variable no longer mails a blank (platform ruling on objectstack#32678) #2451).
  • Upgrade backfill: scripts/backfill-contract-names.ts (report-only without --apply, rerunnable, writes only name on unnamed rows): the source quote's name (the quote of an order naming the contract, else the single accepted quote of its opportunity), otherwise "account name + start date". docs/MAINTENANCE.md §3.6 and the changeset tell admins to run it.
  • Labels in en / zh-CN / es-ES / ja-JP; demo contracts named in both stories (seed identity stays description, so an upgraded demo database is not seeded twice).
  • Docs: contracts, orders, quotes pages in en / zh-Hans / zh-Hant; in-app crm_sales_contracts and crm_sales_orders (en + zh); invoice import mapping comment; docs/feature-inventory.md CON-001; docs/STATUS.md field count.

Tests

  • New test/contract-name.test.ts: title, required, no column constraint, number first in the strip, list/form/print order, four pack labels, every demo contract named; on the booted stack: a nameless insert refused (VALIDATION_FAILED on name at the engine, 400 over REST), clearing a name refused, an unnamed legacy row still saves an unrelated edit, search by name and by number, the invoice import resolves the Contract column by number and by name, the switched-on quote flow names the contract by the quote, and by the opportunity when the quote has none.
  • New test/backfill-contract-names.test.ts: the script run with --apply against a stubbed door: the PATCH bodies for each rule, named rows untouched.
  • sales-order-draft-contract.test.ts: Draft Contract's contract is named as the order (= the quote). contract-drafted-notice / flow-scheduled: notices carry CTR-… · name. o2c-order-contract-later: an invoice's history names the contract by its title. 25 suites' contract fixtures gain a name.
  • Ablation (one-time, restored): the quote flow's opportunity fallback mutated to a literal → with the opportunity's name when the quote has none red (Expected: "Named deal 7" / Received: "ABLATED", 1 failed / 15 passed); restore proven by git diff HEAD empty and the file's hash equal to the HEAD blob.
pnpm verify, and the rerun after merging main

pnpm verify on 26714976 (validate, typecheck, lint, source hygiene, build, full test run) under the shared lock:

 Test Files  337 passed (337)
      Tests  6485 passed | 58 skipped (6543)
os-verify-lock: VERDICT command-exit 0 · held the lock 1503s (25m03s) · waited 0s

Then origin/main (d9875549, #2785, which reads the quote flow this PR edits) was merged; on the merge head e99d0135: tsc --noEmit clean, and test/quote-accept-copy.test.ts, test/contract-name.test.ts, test/sales-order-draft-contract.test.ts 3 files / 44 tests passed, VERDICT command-exit 0.

Acceptance notes

  • Upgrade: until scripts/backfill-contract-names.ts --apply runs, an old contract's header, lookup chips and approvals fall back to the record id, and its notices name it by number. Measured on a dev database created on main and booted on this branch: 4 of 4 contracts unnamed, schema sync clean, no duplicate demo rows; report then --apply named 4/4 (CTR-0001 from its order's quote, the other three by account + start date, an activated and an expired contract among them); a second run reported 0.
  • Out of scope, noted: the renewal task's subject and the renewal opportunity's name still say contract CTR-… (their text is matched by the renewal sweep's legacy-title check, _legacy-task-titles.ts); the invoice/payment refusals that name a contract still name it by number. Neither was in the card's list.
  • Platform note (carrier: objectstack, not filed here): on 18.6.0 SQL schema sync adds a storage.notNull field to an existing table as NOT NULL with no default, so on SQLite the whole object's sync fails even with zero rows, instead of adding the column nullable and reporting tighten_not_null drift as the spec's describe ("a destructive migration gated by the schema-drift ceremony (backfill first)") promises. Once the platform does that, a later PR can declare storage.notNull after the backfill.

Read first

  1. src/sales/objects/contract.object.ts — the field, the title, why no storage.notNull.
  2. src/revenue/flows/quote-accepted-contract-draft.flow.ts — the name fallback chain and the new get_opportunity node.
  3. scripts/backfill-contract-names.ts — the naming rule for existing rows.

Two-minute check

pnpm dev, open Contracts: the first column is Contract Name, the second Contract Number; New asks for Contract Name first; on a new Billing Milestone, the Contract picker shows each name with Contract Number: CTR-… under it.

Verification

Browser, dev boot on this branch (en-US and zh-CN, desktop 1440×900; not on a phone): All Contracts list, contract record header, account Contracts tab, the new-contract form, the billing-milestone contract picker, and Draft Contract on an order (the drafted CTR-0005 is named Globex Seat Expansion Order; its inbox notice's templateData.contract is CTR-0005 · Globex Seat Expansion Order). Before/after-backfill screenshots are in the project folder contract-name-2746/ (not committed). The chain walked: order → Draft Contract → contract → billing milestone picker.

🤖 Generated with Claude Code

https://claude.ai/code/session_01J8VVAmQQaqVXpJepCqm4Xa

The contract's title was its autonumber, so approvals, notices, lookup
chips and the account's Contracts tab showed only CTR- numbers. A
required name field is now the nameField; drafted contracts take the
source's name, and a report-first script names existing contracts.

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
@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 7:58am 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 e99d0135525ea72df1ba5938cffb15450e78655f · 2026-11-25T08:06Z

  • 改了什么:合同新增必填的「合同名称」并作为记录标题;列表、表单、客户的合同页签、选择器、审批和通知里名称与 CTR- 编号并列显示;从订单起草合同、自动起草合同时自动带名称;附一个给老合同补名称的脚本。
  • 为什么改:合同没有「合同名称」:列表、选择器、审批和通知里只显示 CTR- 编号,分不清是哪份合同 #2746(p1),同一客户的多份合同分不清。
  • 风险与回滚:升级后老合同在运行补名称脚本前没有名称,页头和选择器暂时显示记录 id、通知仍显示编号;脚本默认只报告,加 --apply 才写,可重复运行。整 PR 回退即可(新列留空无害)。
  • 要你做什么:升级到含此改动的版本后,管理员运行一次 scripts/backfill-contract-names.ts --apply(docs/MAINTENANCE.md 3.6);云端每个组织同理。
  • 席位意见:L1 读过合同对象、两个起草路径的取名规则、补名称脚本和测试;CI 全绿。

席位核对

  1. Shape: 65 files, +857 / -124 (most are ledgers, docs in three languages, seeds); check-governed-merges: 0 of 65 paths governed, under the 3000-line threshold.
  2. Ruling fidelity: 1 required name as nameField, first in list/form/header ✓; 2 drafted contracts take the quote name, else the opportunity name (switched-on quote flow) / the order's name, which carries the quote's (order Draft Contract) ✓; 3 number kept and shown beside the name via the strip's first field in header and picker, no formula title ✓; 4 existing rows named by the backfill (source quote name, else account + start date) ✓, run by an admin — the same pattern as the Overpayment drives an invoice's open amount and the receivable negative: an invoice of 6,000 paid 6,100 shows Open -100 #2513 backfill.
  3. Accepted deviation: no storage.notNull — on 18.6.0 adding a NOT NULL column to an existing table fails the object's whole schema sync (measured), filed as driver-sql: schema sync adds a new storage.notNull field to an existing table as NOT NULL with no default — on SQLite the whole object's sync fails and the object becomes unwritable objectstack#37258; required refuses every new nameless write and unnamed legacy rows still save unrelated edits (pinned).
  4. Gate check-runs on head e99d0135525ea72df1ba5938cffb15450e78655f: all 20 success. Local pnpm verify 337/337 files before the main merge; post-merge targeted suites green. Ablation reported red.
  5. Out of scope (noted in the PR): renewal task subject / renewal opportunity name and invoice/payment refusals still name contracts by number. A later storage.notNull follows #37258 and the backfill; no card now.
  6. Landing: ready + auto-merge through the merge queue.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 25, 2026 08:07
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit b44cd1d 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.

合同没有「合同名称」:列表、选择器、审批和通知里只显示 CTR- 编号,分不清是哪份合同

2 participants