Skip to content

feat(o2c): confirming again refuses a Total Price below what the order invoiced or received (#2827) - #2836

Merged
objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/issue-2827-reconfirm-total-floor
Nov 27, 2026
Merged

objectstack-fleet[bot] merged 3 commits into
mainfrom
claude/issue-2827-reconfirm-total-floor

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Irene · project thread

Fixes #2827

Clause-②: no
Metadata-protocol: none
Metadata-impact: maintainer — a validation rule tightened: an order moving from Draft to Confirmed is now refused when its Total Price is below its Invoiced or Received

维护者速读

  • 财务和销售在订单上:订单退回草稿改低金额后,若总金额低于已回款或已开票,再点确认会被拒绝,提示是哪一项高于总金额、先处理什么;首次确认和已确认订单的其他修改不受影响。
  • 属于"订单金额只在草稿时可改"这张总卡的第二张子卡,避免未回款、未开票被压成零而回款计划对不上。
  • 万一误拦,销售暂时确认不了这张订单,可先调高总金额或处理发票、回款再确认;撤回此改动即恢复旧行为,不动任何数据。
  • 提示文字只写字段名、不写具体金额(平台暂不支持把数值放进提示),请确认可以接受。

What changes

  • Placement (option A, decided). Two validations[] entries the Order to Cash module adds to crm_sales_order through its existing objectExtensions entry, src/o2c/extensions/sales-order.extension.ts (ObjectExtensionSchema.validations, merged into the target). The sales package does not import o2c, and an o2c hook on the order is refused by ADR-0130 R4, so no hook. A tenant without the module has neither the figures nor the rules.
  • Measured first: invoiced_amount / received_amount are stored summary fields and are readable in the rule's {...previous, ...data} record on update. The refusal tests below fire on the booted stack, and the ablation shows they go green only through these rules.
  • The rules (reconfirm_total_below_received, reconfirm_total_below_invoiced): cross_field on total_price, events: ['update'], a transition gate (AGENTS.md rule 7). Each fires only when previous.status == "draft" and record.status == "confirmed" and the figure is strictly above the total. Every read carries has() (the TOTAL predicate rule). Total equal to the figure passes. A write that lowers the total and confirms in one request is judged on the recomputed total, because the total hook runs before validation (tested).
  • Messages: fixed text naming the fields, not the amounts. 18.6.0 authoredRuleMessage returns the authored or translated text verbatim and interpolates no record values; the same limit is recorded on contract_same_account. The order's page shows Total Price, Invoiced and Received side by side. Translated in the o2c packs (en/zh-CN/ja-JP/es-ES) under objects.crm_sales_order._validations.
  • test/i18n-package-ownership.test.ts: a module's row on another package's object may now also carry _validations for the rules that module contributes there, and nothing else. The positive control now covers crm_sales_order fields and rule messages in all four locales.
  • Docs: in-app src/o2c/docs/crm_o2c_invoices_payments.md (+ .zh.md), site content/docs/(product)/order-to-cash/invoices-and-payments.mdx (+ zh-Hans, zh-Hant). The sales manual is unchanged because an app-book page may not link to a module's book.
  • Changeset .changeset/2827-reconfirm-total-floor.md (minor).

Tests

test/sales-order-reconfirm-floor.test.ts, 5 cases on the booted stack:

  • 10,000 received, back in Draft at 8,000: confirming is refused (400 VALIDATION_FAILED, fields[0] = total_price / rule_violation / the sentence; zh-CN sentence via accept-language) and the order stays Draft. At 12,000 it confirms and Unpaid reads 2,000 (the card's acceptance).
  • 9,000 invoiced, back in Draft at 5,000: refused with the invoiced sentence. At 9,000 (equal) it confirms.
  • Lowering the total and confirming in one write is refused; the stored total is unchanged.
  • A first confirm with nothing invoiced or received is not judged.
  • An order already Confirmed below its figures (moved there by a system write) is not judged on its next edit or on Confirmed → Completed.
Ablation (on disk, then restored)

The validations array was emptied in sales-order.extension.ts (grep count of reconfirm_total = 0) and the file re-run: Tests 3 failed | 2 passed (5). The three refuse cases fail with expected 200 to be 400. The failing record shows received_amount: 10000, total_price: 8000, unpaid_amount: 0 (the defect). The two non-gating cases pass either way, by design. Restored from a copy; git diff showed only the intended change.

Acceptance notes

  • Acceptance gap: amounts in the message. The card asks for "with the amounts". On 18.6.0 a validation message cannot carry record values, and the decided placement is a validation. The message names Total Price and Received / Invoiced instead, and the page shows the numbers beside each other. Interpolating record values into a rule message is a platform capability (objectstack). It is named in the dev report for the seat to file, not filed from here.
  • Already-confirmed orders that sit below their figures today keep their status; they meet the rule only if sent back to Draft.

Verification

  • Final head b2caf7d2, through os-verify-lock.sh: pnpm validate && pnpm typecheck && pnpm lint && pnpm test. Result VERDICT command-exit 0, Test Files 342 passed (342), Tests 6568 passed | 58 skipped (6626).
  • Two-minute check: pnpm exec vitest run test/sales-order-reconfirm-floor.test.ts should give 5 passed. In the console, put an order with a payment back in Draft, lower Total Price below Received and set Status to Confirmed; the save is refused on Total Price.
  • Read first: src/o2c/extensions/sales-order.extension.ts (the predicate: transition and guards), test/i18n-package-ownership.test.ts (the widened allowance), src/o2c/translations/zh-CN.ts.

🤖 Generated with Claude Code

https://claude.ai/code/session_01J8VVAk8tegvAi1ECkgCFfc

…r invoiced or received (#2827)

Two cross_field validations the Order to Cash module adds to crm_sales_order
through its objectExtensions entry, judged on the Draft -> Confirmed move only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J8VVAk8tegvAi1ECkgCFfc
…n the manual, the docs site and a changeset (#2827)

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

vercel Bot commented Nov 27, 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 27, 2026 10:05am 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 27, 2026
@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 27, 2026 10:36
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:hotcrm#1 · huangyiirene · session_01J8VVAk8tegvAi1ECkgCFfc

ACCEPT · 2026-11-27T10:36Z

Head-sha: b2caf7d2

维护者速读

  • 改了什么:订单从草稿再确认时,总价低于已回款或已开票就拒绝确认,提示先处理多收款或发票;等于这个金额可以确认。第一次确认、已确认订单的编辑和后续状态变化都不检查。规则属于 Order to Cash 模块,没装这个模块就没有这条规则。
  • 没做到的:提示里没有具体金额,只写字段名(平台目前的校验提示不能带记录值)。已提平台卡 objectstack#37909,平台支持后再补金额。
  • 要你做什么:无。您在决策卡上选了「先合并,提示写字段名」,并按「做完的,没有问题的都自动合并」由席位合并。

席位核对

  • Form: Fixes #2827 after the attribution lines (tracking Sales orders: the amount can change only while Draft; once Confirmed it locks with the lines #2825 not closed by it); draft → ready to main. Files: the o2c order extension, 4-locale o2c translations, o2c manual (+zh), site page (+zh-Hans/zh-Hant), changeset, tests — on the claimed surface. test/i18n-package-ownership.test.ts widened by design: a module's row on another package's object may carry _validations, only for rules that module contributes (positive control asserts the exact set).
  • Placement: o2c objectExtensions[].validations[] (two cross_field rules on Total Price), sales does not import o2c, no cross-package hook (ADR-0130 R4). Transition gate on previous.status == draft && record.status == confirmed (AGENTS rule 7). Measured: stored summary fields are readable in the merged record on update; a same-write lower-and-confirm is judged on the recomputed total.
  • Refusals: tests assert 400 VALIDATION_FAILED with fields[0] = total_price / rule_violation and the zh-CN sentence; order stays Draft. Pass case 12,000 → Unpaid 2,000; equal total passes; first confirm and already-Confirmed edits / Confirmed→Completed not gated. Ablation (rules emptied) → 3 failed / 2 passed (the non-gating controls).
  • Acceptance gap: amounts not in the message — maintainer accepted on the decision card (2026-11-27T10:33Z); upstream capability filed as objectstack#37909.
  • Gates: all 20 check-runs on b2caf7d2 completed success; validate/typecheck/lint/full suite via os-verify-lock on b2caf7d2: 342 files, 6568 passed / 58 skipped.
  • Changeset minor, FROM → TO; sentences checked against the diff.
  • Landing: seat lands on the maintainer's standing word 「做完的,没有问题的都自动合并」 (2026-11-26T10:39Z).

@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 27, 2026
Merged via the queue into main with commit c9d500f Nov 27, 2026
21 checks passed
sunhaolin added a commit that referenced this pull request Nov 27, 2026
#2836 landed on main after the release PR opened, with a 30th
changeset (minor). The branch merged main; this commit removes
.changeset/2827-reconfirm-total-floor.md and writes its line into the
6.7.0 notes: one bullet under Order to Cash and one sentence in the
Integrations check of CHANGELOG.md, and one sentence in the Orders item
of the whats-new page in three locales.

`changeset version` on a copy of c9d500f computes 6.7.0 from all 30
changesets (7 minor, 21 patch, 2 empty), so the version stands. The
marketplace listing reads 7,738 of 8,000 characters, nothing omitted.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.

Sales orders: confirming again refuses a new Total Price below what was already invoiced or received

1 participant