Skip to content

feat(sales): lock an order's amount once Confirmed; Subtotal is the lines' sum on an order with lines (#2826) - #2834

Merged
objectstack-fleet[bot] merged 4 commits into
mainfrom
claude/issue-2826-order-amount-lock
Nov 27, 2026
Merged

objectstack-fleet[bot] merged 4 commits into
mainfrom
claude/issue-2826-order-amount-lock

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Requested by Irene · project thread

Fixes #2826

Clause-②: no
Metadata-protocol: none
Metadata-impact: maintainer — a hook changed: a person's edit of a confirmed, completed or cancelled order's amount, and a typed Subtotal on an order with lines, are now refused

维护者速读

  • 销售和财务在订单上:确认、完成或取消后,再改小计、折扣、税额、运费会被拒绝并提示“先退回草稿”;有订单行的订单不能再手填小计,只能等于各行之和。
  • 属于“订单金额只在草稿时可改”这张总卡,让订单合同、收款计划和框架合同额度读到的总金额不再被悄悄改掉。
  • 万一规则误拦,销售改不了已确认订单的金额,可先退回草稿再改;导入、种子数据和系统自身的更新不受影响;撤回此改动即恢复旧行为。
  • 无

What changes

  • sales_order_workflow (src/sales/objects/sales_order.hook.ts), on beforeUpdate by a person (ctx.user present, the line lock's exemption):
    • Amount lock. If the order WAS Confirmed, Completed or Cancelled and the write changes subtotal, discount, tax or shipping_handling against the stored row, it is refused 409 RECORD_LOCKED with reason amount_confirmed / amount_completed / amount_cancelled: "Order X is Confirmed, so its amount can no longer be changed. Send it back to Draft first." (Completed / Cancelled: "… can no longer be changed."). Unchanged figures sent back by a form pass. A write that moves a Confirmed order to Draft and changes the amount in the same request is refused; the amount changes in the next write.
    • Subtotal on an order with lines. If a person's write changes subtotal and the order has lines, a value other than the lines' sum (the roll-up's own formula, rounded to cents) is refused with 400 VALIDATION_FAILED: "Order X has lines, so its Subtotal is the sum of its lines and cannot be typed. Change the lines instead." I chose refuse over override: an override would drop the typed number without telling anyone why. sales_order_total_rollup's write carries the sum and passes. An order with no lines takes a typed Subtotal, as before.
    • Why not a form condition. 18.6.0 has readonlyWhen, but objectql strips a TRUE readonlyWhen for every caller, isSystem included, and does it without an error. On the status lock that would also strip the seed's and an import's roll-up writes to confirmed orders. On "has lines" there is no field of the order to test, and adding a line count would strip the roll-up's own Subtotal write. So the form still shows the four fields as editable, and saving refuses. The Subtotal help text says so.
  • Refusal catalogue: three new reasons under RECORD_LOCKED, and a new VALIDATION_FAILED entry. Each is translated in zh-CN, ja-JP and es-ES hooks.ts; English is the declared message.
  • subtotal gets a description (help text), en/zh-CN/ja-JP/es-ES.
  • Docs: in-app src/docs/crm_sales_orders.md (+ .zh.md), and the site page content/docs/(product)/sales/orders.mdx (+ zh-Hans and zh-Hant). The zh headings carry an explicit English anchor.
  • Changeset .changeset/2826-order-amount-lock.md (minor).
  • Unchanged, as ruled (Invoices and payments run in parallel: unlink them, show Unpaid and Uninvoiced instead of Receivable Balance, measure overdue on the payment plan, and generate a plan step when an order is confirmed #2806 / Framework contracts: roll up the orders under them (ordered amount, remaining quota) and warn on over-limit, with an admin switch to block #2807): Order Amount counts Confirmed and Completed orders only, and an order back in Draft drops out of the framework quota.

Tests

  • test/sales-order.test.ts, new block "the header amount locks once the order leaves Draft (Sales orders: lock Subtotal, Discount %, Tax and Shipping once Confirmed; Subtotal read-only when the order has lines #2826)", 7 cases on the booted stack:
    • each of the four fields refused on Confirmed, with the code and the sentence, and the stored figures unchanged;
    • Draft plus an amount change in one write refused;
    • unchanged figures and other fields save;
    • Completed and Cancelled each refused with their own sentences;
    • a system write (hooks.run … { system: true }) changes a confirmed order's amount, and a seeded line on a confirmed order still rolls up;
    • back in Draft all four fields are editable, the total recomputes, and re-confirming keeps it and locks it again;
    • an order with lines refuses a typed Subtotal (and null) but accepts the sum, a line edit still moves Subtotal, and an order with no lines takes a typed Subtotal.
  • Fixture triage. These existing tests changed a confirmed order's amount as a person, which is now refused by design:
    • test/framework-contract-quota.test.ts: the raise and lower now go through Draft, and the test asserts the 409 on Confirmed first. The quota warning is still asserted on the raise and absent on the lower.
    • test/o2c-parallel-figures.test.ts: the amount change goes Draft, then edit, then Confirm. Expectations are unchanged.
    • test/refusal-envelope.test.ts: the swept call-site count goes from 108 to 110 (two new refuse calls).
  • Ablation (on disk, then restored): the new block disabled (if (false && …)), and the Sales orders: lock Subtotal, Discount %, Tax and Shipping once Confirmed; Subtotal read-only when the order has lines #2826 tests re-run:
    • 5 failed, 2 passed (the system-write and no-lines cases are positive controls that pass either way);
    • restored with git checkout.

Acceptance notes

Verification

Final head and readings are in the comment below. Two-minute check: in the console, confirm an order, edit its Tax, and save. Expected: the save is refused with "Order … is Confirmed, so its amount can no longer be changed. Send it back to Draft first."

Read first, by risk:

  1. src/sales/objects/sales_order.hook.ts: the new block before "The header totals follow their inputs" (the ctx.user exemption and the previous.status judgement).
  2. test/framework-contract-quota.test.ts: the reworked raise and lower path.
  3. src/sales/translations/*/hooks.ts: the new sentences.

🤖 Generated with Claude Code

https://claude.ai/code/session_01J8VVAk8tegvAi1ECkgCFfc

…s the lines' sum on an order with lines (#2826)

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J8VVAk8tegvAi1ECkgCFfc
…ft; swept refusal count 110 (#2826)

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 9:08am 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 27, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:hotcrm#1 · huangyiirene · session_01J8VVAk8tegvAi1ECkgCFfc

ACCEPT · 2026-11-27T09:17Z

Head-sha: 90544ef6

维护者速读

  • 改了什么:订单确认(或已完成、已取消)后,小计、折扣、税额、运费不能再手改,保存时提示「请先退回草稿」;系统写入照常。有订单行时,小计必须等于行合计,手填不一致会被拒。确认弹窗的提示也改成「订单行和金额将被锁定」。
  • 没做到的:表单上这四个字段看起来仍可编辑,保存时才拦。平台目前的只读条件会连系统写入一起挡住,所以没用。
  • 要你做什么:无。按您「做完的,没有问题的都自动合并」,席位合并。

席位核对

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 27, 2026 09:18
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 27, 2026
Merged via the queue into main with commit 3459c68 Nov 27, 2026
22 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.

Sales orders: lock Subtotal, Discount %, Tax and Shipping once Confirmed; Subtotal read-only when the order has lines

2 participants