Skip to content

feat(contract): framework contract shows Order Amount and Remaining Quota; an order over the quota warns (#2807) - #2818

Merged
objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/issue-2807-framework-quota
Nov 26, 2026
Merged

objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/issue-2807-framework-quota

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Irene · project thread

Part of #2807: this PR lands the roll-up and the warning. The admin switch to block waits on a decision (see Acceptance notes).

Clause-②: no
Metadata-protocol: none
Metadata-impact: reviewer — a new formula field (Remaining Quota), a new field group (Order Totals) that the three roll-up fields move into, and a warning-only validation on the order that refuses no write

维护者速读

  • 销售和合同管理员会看到:框架合同页面新增「订单汇总」区块,显示订单金额(已下单金额)和剩余额度;订单使框架合同超额时,保存照常完成,并弹出黄色警告。
  • 属于合同、订单、发票、回款关系整改跟踪卡的第四项,按 11 月 26 日您「超额默认警告,管理员可以改成拦截」的裁决落地前一半。
  • 只加了显示和警告,不拦任何保存,订单金额字段从「合同金额」区块挪到新区块(打印的合同不再带这几个数字);可整体撤回。
  • 「管理员改成拦截」需要您选方案:平台目前没有让管理员开关打包规则的入口,选项已写在卡片上。

What changes

Order Totals on the contract. A new field group orders ("Order Totals") on crm_contract holds:

The three moved out of value because contract_print_page prints the value group whole ("every member is something the customer signs"). Running totals do not belong on the signed document.

The warning. crm_sales_order.framework_quota_exceeded is a conditional rule (when the order names a contract) with severity: 'warning'. It fires when:

  • the contract is a framework contract;
  • this write adds to the order's share (a newly linked order, or a higher total_price);
  • and stored order_amount − previous share + new total > contract_value.

The previous share is previous.total_price when the order was already linked to the same contract (read as record.crm_contract.id, because a predicate that reads through a reference may not also read it as a value). An edit that leaves the share as it was, or lowers it, is not judged, so an order already over is not flagged on every save and lowering is always free. The answer carries it in warnings and the console shows "Saved — with warnings" (browser-verified below).

Not here: the admin switch to block. See Acceptance notes.

Text. Labels, help, section and warning in en / zh-CN / es-ES / ja-JP. The Contracts manual (three locales) and the in-app Contracts and Orders help (two) gain the quota. docs/STATUS.md field count is 636→637, as pnpm validate prints.

Tests

Run on head ffe1c5a9. The logs are in the folded blocks below.

  • test/framework-contract-quota.test.ts (new, 10 tests, REST data door as a sales rep) covers:
    • a fresh framework contract reads 0 / full value, and counts a linked order tax-included;
    • visibility per form;
    • empty Remaining Quota while the roll-up is NULL;
    • the three fields are off the print page;
    • a warning on a new over-limit order, on linking an existing order and on raising a linked order's total, with the order saved;
    • no warning on an unrelated edit or a lowered total;
    • a line that takes the order over shows on Remaining Quota;
    • no warning on an Other contract or with no contract.
  • Ablation (on disk, then restored): removing the "adds to the order's share" clause turns 2 tests red (raised-then-unrelated edit, lowered total).
Local runs
Head ffe1c5a9 (final):
  framework-contract-quota + contract-form-change + object-validation-predicates
    Test Files  3 passed (3) | Tests  165 passed (165)
    os-verify-lock: VERDICT command-exit 0
  pnpm validate / typecheck / lint (--strict) / hygiene: each OK (validate: 38 Objects 637 Fields)

Head 2c1348bc (all translation and docs changes in; the head after it changes contract.object.ts and the new test only):
  68 files (docs-*, i18n-*, contract*, sales-order*, o2c-sales*, object-validation*, refusal*, zh-cn*, runtime-coverage, seed*, package-ownership, backfill*, framework*)
    Test Files  68 passed (68) | Tests  1372 passed | 11 skipped (1383)
    os-verify-lock: VERDICT command-exit 0
  18 more files reading orders, groups or packs (field-groups-coverage, detail-section-dedup, metadata-references, record-pages-2720, o2c-collection-plan, ...)
    Test Files  18 passed (18) | Tests  414 passed (414)
    os-verify-lock: VERDICT command-exit 0

Ablation (on disk, restored, re-run green): the "adds to the order's share" clause removed
    Tests  2 failed | 8 passed (10) -- raised-then-unrelated edit; lowered total

Acceptance notes

  • The admin switch to block is not in this PR. Measured on 18.6.0:

    • Validation-rule active is one of the two settings an installation may set on a packaged rule (ADR-0029 D9.2a, tenantRuleSettingsOf). But PUT /api/v1/meta/object/crm_sales_order as the admin answers 403 NOT_OVERRIDABLE: "'object/crm_sales_order' is provided by a managed package and is sealed" (ADR-0131 D6).
    • The packaged-item switches that exist (Regime C) cover flows, actions and sharing rules, not validation rules.
    • A record-triggered flow cannot refuse its write: the trigger catches and logs the run's error.
    • A hook cannot read a setting: HookContext has no settings accessor, defineStack takes no settings manifest, and manifest.configuration was removed in spec 17.

    So an admin-switchable block needs either a platform capability or an app-made setting. The options are in the report on Framework contracts: roll up the orders under them (ordered amount, remaining quota) and warn on over-limit, with an admin switch to block #2807, for the maintainer. A block rule shipped switched off with no switch would be declared-and-not-enforced, so none is shipped.

  • A line's save does not show the warning. A line raises the order's total through sales_order_total_rollup's own write to the order. The platform hands that nested write's advisories to no listener: "A nested write a hook or a flow makes inside this one carries its own options". The contract's Remaining Quota below zero is the sign that stays. Documented in the help.

  • Cancelled orders still count toward the Order Amount, as they already did on an order contract since Contracts: a contract form (order / framework / other), the order contract's amount follows its order, and an active contract changes only through Change #2804. This follows the ruling's "sum of the linked orders". Excluding them would change Contracts: a contract form (order / framework / other), the order contract's amount follows its order, and an active contract changes only through Change #2804's order-contract value too, so it is left as ruled.

  • The record page shows the three fields on every form. Measured: the console's synthesized record page does not apply a field's visibleWhen in its detail sections. An Other contract shows Order Amount, Differs and Remaining Quota, empty or computed. This was already the case for Contracts: a contract form (order / framework / other), the order contract's amount follows its order, and an active contract changes only through Change #2804's two fields. The metadata states the condition, and the renderer gap is reported for upstream filing, not worked around.

  • One seeded order already sits over its framework contract. The seed load reports it once as an advisory hit, and nothing fails.

  • src/sales/pages/**, docs/STATUS.md, the in-app help and the changeset are outside the claim's file list or under "user manual". No page file was changed. The print page is only read, by the test.

  • src/sales/objects/_thresholds.ts says a severity: 'warning' rule has "no observable surface at all". On 18.6.0 that is no longer true (warnings on the REST answer, a console toast). It is noted here and not changed.

Verification

On a dev server from this branch (port 4017, fresh database, headless Chrome as the dev admin):

  1. A framework contract at 1 000 with an order of 900 shows Order Totals: Order Amount 900.00, Remaining Quota 100.00.
  2. On that order's Edit dialog, setting Tax to 300 and clicking Update shows two toasts: "Order … updated" and "Saved — with warnings" with "With this order, the orders under the framework contract total more than its Contract Value. The order is saved; …". The contract then reads Order Amount 1,200.00, Remaining Quota -200.00.

Two-minute check: pnpm exec vitest run test/framework-contract-quota.test.ts should show 10 passed. Or, in the app, link an order to a framework contract so that the orders exceed its value. The save goes through with a yellow warning, and the contract's Remaining Quota goes negative.

Read first, by risk:

  1. src/sales/objects/sales_order.object.ts: QUOTA_* and framework_quota_exceeded, especially the previous-share term (previous.crm_contract == record.crm_contract.id).
  2. src/sales/objects/contract.object.ts: remaining_quota and the orders group move.
  3. content/docs/(product)/sales/contracts.mdx: the quota section, the business wording users read.

🤖 Generated with Claude Code

https://claude.ai/code/session_01J8VVAk8tegvAi1ECkgCFfc

…uota; an order over the quota warns (#2807)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J8VVAk8tegvAi1ECkgCFfc
…help; changeset (#2807)

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

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

vercel Bot commented Nov 26, 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 26, 2026 12:06pm 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 labels Nov 26, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:hotcrm#1 · huangyiirene · session_01J8VVAk8tegvAi1ECkgCFfc

ACCEPT · 2026-11-26T12:13Z

Head-sha: ffe1c5a9

维护者速读

席位核对

  • Form: Part of #2807 (not Fixes) — correct, the block half is undelivered; attribution lines present; ready to main.
  • Ruling half delivered: Ordered amount = the Contracts: a contract form (order / framework / other), the order contract's amount follows its order, and an active contract changes only through Change #2804 order_amount summary (tax-inclusive total_price), now visible on framework contracts; remaining_quota = contract value − ordered, framework only; warning-severity rule framework_quota_exceeded judges only writes that add to the order's share (an order already over is not frozen; lowering always allowed). Read the CEL in the diff.
  • Not delivered, maintainer decision posted in the project thread: how the admin switch to block is made (platform switch / per-contract field / app settings object) — 18.6.0 seals packaged validation rules (admin PUT → 403 NOT_OVERRIDABLE).
  • Gates: every check-run on ffe1c5a completed success; local validate/typecheck/lint/hygiene exit 0; new test file 10 tests via the REST door, with an ablation that fails 2 when the share clause is removed. Browser pass recorded (warning toast on save).
  • Out of scope (dev findings, platform): record page detail ignores visibleWhen on an Other contract; nested hook writes deliver no validation advisories (line save over quota shows no warning) — noted in the PR's Acceptance notes.
  • Landing: seat lands on the maintainer's standing word 「做完的,没有问题的都自动合并」 (2026-11-26T10:39Z).

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 26, 2026 12:14
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 26, 2026
Merged via the queue into main with commit fb8edeb Nov 26, 2026
21 checks passed
huangyiirene pushed a commit that referenced this pull request Nov 26, 2026
…-parallel (#2806)

docs/STATUS.md keeps both sides: 636 fields and 55 flows, as pnpm
validate prints on the merged tree.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J8VVAk8tegvAi1ECkgCFfc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants