Skip to content

feat(o2c): invoices and payments run in parallel; Unpaid and Uninvoiced replace the Receivable Balance; overdue on the payment plan (#2806) - #2819

Merged
objectstack-fleet[bot] merged 14 commits into
mainfrom
claude/issue-2806-invoice-payment-parallel
Nov 27, 2026
Merged

objectstack-fleet[bot] merged 14 commits into
mainfrom
claude/issue-2806-invoice-payment-parallel

Conversation

@objectstack-fleet

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

Copy link
Copy Markdown
Contributor

Requested by Irene · project thread
Fixes #2806
Clause-②: no
Metadata-protocol: none
Metadata-impact: maintainer — permission sets (crm_user, project_member and the shared Order to Cash figure rows carried from the Receivable Balance to Unpaid and Uninvoiced), fields hidden (payment Invoice; invoice Payment Plan, Paid, Open, Overpaid) and removed (Receivable Balance on contract and account; the plan step's Invoiced), two record-change flows added, seed data changed, hooks unchanged

维护者速读

  • 用户能看到什么变化:财务录回款时不再选发票,回款只挂回款计划、订单或合同;订单、合同、客户上的「应收余额」换成「未回款」「未开票」两个数;「逾期发票」换成「逾期回款计划」;订单确认时自动生成一条回款计划。
  • 为什么做:按 11 月 26 日的拍板,让发票和回款各走各的,销售看欠款不再依赖财务逐张核销发票(订单与回款模块)。
  • 出错会怎样:客户上的未回款、未开票算错会误导催款;旧数据升级后要跑两条迁移命令才有数,正文附了新旧对比和升级步骤,代码可直接撤回,隐藏的发票字段数据都还在。
  • 要你做什么:请确认客户汇总的口径(按已确认和已完成的订单,加没有订单的已签合同各算一次),见 Acceptance notes 第一条。

What changes

The 2026-11-26 ruling, item by item:

  • Unlinked. A payment names no invoice: the payment's Invoice field is hidden, and its link no longer draws a Payments list on the invoice's page (relatedList: false). A payment names its Payment Plan, Order or Contract, or the account alone.
  • Hidden, not deleted. On the invoice: Payment Plan, Paid, Open, Overpaid (hidden, kept, still kept in step by invoice_figures and still guarded by the row stamps for API and import writes). The plan step's Invoices list is gone too (relatedList: false). The plan step's own Invoiced summary is removed (it summed the hidden link; os lint flagged it as declared but not displayed).
  • Unpaid and Uninvoiced (labels avoid "Receivable"). Order: Total Price minus Received / minus Invoiced; contract: Contract Value minus the same; both floored at 0 with max(). Account: the sum of each deal's own figure, once per deal: Confirmed or Completed orders, plus Activated or Expired contracts that have no order. Stored computed fields, no hook.
  • Plan step Open is a stored, filterable field; Overdue Payment Plans (planned date before today, Open above 0) replaces Overdue Invoices in the Order to Cash navigation.
  • Confirmed order gets a step (sales_order_confirmed_plan_step): on the status becoming Confirmed and no step yet, one step for the order total, planned today plus the payment-terms days (same day for Due on Receipt or no terms). Amount change (sales_order_amount_plan_step): the lone step follows the total while nothing is received; otherwise the order shows Payment Plan Differs. Instalments stay manual. No bank reference field.
  • Import mappings and templates drop the payment's Invoice and the invoice's Billing Milestone columns; the mapping header states the erp_ref rule for a receipt split across orders.
  • Seed: payments name plan steps, invoices name no step, Acme's step and invoice name its order.
  • scripts/compare-unpaid-receivable.ts: the old-vs-new account figures, read-only.
  • Docs: both in-app Order to Cash manuals (en and zh), the Order to Cash pages, FAQ, quick tour, subscription scenario, modules page, automation page, project notes, admin setup (en, zh-Hans, zh-Hant).

PM assumptions, measured. (1) A formula takes a maximum: true, max(0.0, …) evaluates. (2) The account rolls up a formula on orders: false at runtime. os validate exits 0, but every child write logs that aggregate will not sum a declared formula field and the query is not run, so the summary goes stale. The stored-computed-field route was taken instead: what the user sees is what the ruling describes, so no decision was needed.

Old vs new account figures

pnpm exec tsx scripts/compare-unpaid-receivable.ts --url http://localhost:4112 on the dev seed as main left it, after the upgrade, os migrate summary-nulls --apply (25 values) and os migrate stored-expressions --object crm_sales_order --object crm_contract --object crm_billing_milestone --object crm_account --apply (17 rows):

Account Receivable Balance (old) Unpaid (new) Change Uninvoiced (new) Invoiced Received
Acme Corporation 220,000 238,700 18,700 238,700 220,000 0
Globex Industries 0 11,232 11,232 11,232 11,232 11,232
Initech Solutions 21,000 21,000 0 0 60,000 39,000
Total 241,000 270,932 29,932 249,932 291,232 50,232

9 accounts read, 3 with a figure on either side. The old figure is recomputed from the invoices' stored Open (equal to the stored Receivable Balance on main).

  • Acme +18,700: the order total includes 18,700 tax the invoice never billed; the old figure counted only issued invoices.
  • Globex +11,232: the second half of the order is not invoiced yet; the old figure never saw it.
  • Acme Uninvoiced 238,700 on upgraded data vs 18,700 on a fresh seed: main's invoice names only the contract, and under the orders-first rule a contract with an order counts through the order. On a fresh seed of this branch the invoice names the order and the account reads 18,700.

Tests

  • New test/o2c-parallel-figures.test.ts (12 tests, booted app): order and account Unpaid and Uninvoiced, the 0 floor, draft and cancelled orders out, payment and amount moves, the seeded contract counted once (then through its order), overdue via the stored Open filter, the confirm flow (Net 30 is day 30, Due on Receipt today, an existing step means none, re-confirm adds none), the amount flow and Payment Plan Differs.
  • Updated: o2c receivables, collection plan, invoice list totals, module package, sales order, seed twins, default permission set, PSA totals, contract activation no-op (the account roll-up over contracts is now an expected account write; the assertion is now that the account is not promoted), automation ledger, runtime roster, counts.
Readings
  • pnpm verify on b088a54: validate, typecheck, lint --strict, hygiene, build exit 0; vitest 330/338 files, 14 failed tests in 8 files (new flows missing from ledgers and counts, two unguarded flow conditions, an anchor prefix, the activation no-op test).
  • After the fixes, on d762604: the 8 files plus the new one, 445/445 passed; test/docs-*, test/automation*, test/flow-*, test/actions-flows*, 60 files, 1603 passed, 15 skipped; typecheck, lint --strict, hygiene exit 0. The full suite was not rerun on d762604 (CI runs it).
  • Browser (headless Chrome, fresh seed): the Order to Cash navigation shows Overdue Payment Plans; that list shows the two Initech steps (6,000 and 15,000 open); the new-payment form has Account, Order, Contract, Payment Plan, no Invoice; the invoice page has no Paid, Open, Overpaid, Payment Plan, and no Payments list; the plan step page lists Payments only; the account, order and contract pages show Unpaid and Uninvoiced (Acme 238,700 / 18,700; Initech contract 21,000 / 0), and the Acme order shows Payment Plan Differs: Yes.

Acceptance notes

  • The account rule is a choice inside the ruling. Implemented: orders first (Confirmed or Completed orders, plus Activated or Expired contracts with no order). The alternative, contracts first, would overstate a framework contract's ceiling as owed. Also chosen: which statuses count, and that a row naming only the contract of a deal with an order is not seen by the account (upgrade note in the changeset).
  • Unpaid counts money not yet invoiced. It is amount minus Received, as ruled, so it can exceed what was billed (Globex, Acme tax).
  • Outside the claimed file surface: src/sales/profiles/ (the crm_user and project_member rows and the shared Order to Cash figure rows had to move from the removed Receivable Balance to the new fields, or validate fails), src/docs/crm_admin_setup*, src/psa/docs/crm_psa_projects_cost*, docs/STATUS.md, README.md and the introduction pages (flow and field counts).
  • 从发票 / 回款节点的「回款」页签新建回款:父记录被「请先选择客户」盖住、选客户后被清空,保存的回款没有挂到发票上 #2755 re-checked: its invoice entry is gone (no Payments list on an invoice). Its payment-plan entry still holds: the payment's Payment Plan keeps dependsOn: crm_account, and the browser shows "Select Account first" on it.
  • 订单 → 回款节点「添加」列出其他客户、其他合同的回款节点(未按客户过滤;发票页签同类) #2753 re-checked: its invoice half still holds: the order's Invoices list is unchanged by this PR.
  • Upgrading needs two migrate commands (changeset); until then the new stored fields read empty on old rows.

Verification

Risky hunks, in order: src/o2c/extensions/contract-account.extension.ts (the account legs and their filters), src/o2c/flows/sales-order-amount-plan-step.flow.ts (when the plan is rewritten), src/sales/profiles/_o2c-figures.ts (who reads the new figures).

Two minutes: pnpm dev, open Acme Corporation, then its order: the account reads Unpaid 238,700 and Uninvoiced 18,700, and the order shows Payment Plan Differs: Yes.

🤖 Generated with Claude Code

https://claude.ai/code/session_01J8VVAk8tegvAi1ECkgCFfc

Seat note — DELIBERATE CORRECTION of an existing changeset

Commit 110d036 (by the seat) edits the unreleased .changeset/2807-framework-contract-quota.md so it does not contradict this PR's note in the same release:

  • before: "Order Amount — the total of every order linked to the contract, tax included —"
  • after: "Order Amount — the total of the contract's Confirmed and Completed orders, tax included (a draft or cancelled order counts toward neither it nor the quota) —"
  • before: "Linking an order to a framework contract, or raising a linked order's total, so that …"
  • after: "Linking an order to a framework contract, raising a linked order's total, or confirming one, so that …"

Why: maintainer ruling 2026-11-27T02:03Z (project thread decision card) — Order Amount and Remaining Quota count only Confirmed and Completed orders. Release text only; no code changed in that commit.

…ed replace the Receivable Balance; overdue on the payment plan (#2806)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J8VVAk8tegvAi1ECkgCFfc
…step on the booted app (#2806)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J8VVAk8tegvAi1ECkgCFfc
…nvoices and payments (#2806)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J8VVAk8tegvAi1ECkgCFfc
…er count is unfilled counts as having none (#2806)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J8VVAk8tegvAi1ECkgCFfc
… overdue plans and the confirmed order's step in the manuals and the docs site; hidden links list nothing (#2806)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J8VVAk8tegvAi1ECkgCFfc
…ined; the two flows on the automation page, in the counts and in the runtime roster (#2806)

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 27, 2026 3:24am 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 26, 2026
)

README.md and docs/STATUS.md keep both sides: main's 56 actions and its
fields, this branch's 55 flows and its field change (635 fields, 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
…-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
…ninvoiced read its Order Amount (#2806)

The maintainer's ruling of 2026-11-27: a contract that has orders computes
Unpaid and Uninvoiced from its Order Amount, not its Contract Value; a
contract with no order keeps the Contract Value. Invoiced and Received are
unchanged: invoices and payments entered on an order already carry the
order's contract (row stamp; contract fill flow for a contract set later).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J8VVAk8tegvAi1ECkgCFfc
…n order contract keeps its order's amount (#2806)

The maintainer's option B ruling. crm_contract.order_amount sums only
Confirmed and Completed orders: it feeds a framework contract's Order
Amount, Remaining Quota and the o2c Unpaid/Uninvoiced base, and
order_count counts the same set. A new hidden linked_order_amount
(every order but Cancelled) keeps #2804's draft follow, Differs from
the Order Amount and Update from Order. The record page does not apply
visibleWhen in detail sections, so both roll-ups are hidden and one
form-dependent formula, order_amount_shown, is the visible Order
Amount. The quota warning still checks a Draft as if confirmed, and
warns again when confirming takes the contract over.

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

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

Copy link
Copy Markdown
Contributor Author

repo:hotcrm#1 · huangyiirene · session_01J8VVAk8tegvAi1ECkgCFfc

ACCEPT · 2026-11-27T03:14Z

Head-sha: 110d0362

维护者速读

  • 改了什么:发票和回款平行(不再互相挂钩);订单、合同、客户上显示未回款、未开票;订单确认时自动生成一个回款计划节点;逾期回款计划视图。
  • 按您的决定:客户层按订单为主算(A);合同有订单时按已下单金额算未开票/未回款;「已下单金额」「剩余额度」只算已确认、已完成的订单,超额照样警告(草稿也警告)。
  • 要你做什么:无。按您「做完的,没有问题的都自动合并」,席位合并。

席位核对

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 27, 2026 03:15
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 27, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 27, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:hotcrm#1 · huangyiirene · session_01J8VVAk8tegvAi1ECkgCFfc

Re-queue · 2026-11-27T03:33Z

Head-sha: 95415ee6

  • Dequeued 2026-11-27T03:22Z on a queue CI failure: feat(demo): pnpm demo:staff adds a Finance Controller and an Accounts Receivable user #2823 (merged just ahead) added a test reading the account's receivable_balance, which this PR retires (FROM Receivable Balance TO Unpaid / Uninvoiced).
  • Fix (seat): merged origin/main into the branch (c467644) and pointed test/demo-staffing.test.ts's finance-persona account check at invoiced_amount, received_amount, unpaid_amount, uninvoiced_amount (95415ee). Test-only; behaviour unchanged.
  • Evidence: vitest run test/demo-staffing.test.ts under the verify lock → 38/38 passed, VERDICT command-exit 0; all 20 check-runs on 95415ee6 completed success.
  • The earlier ACCEPT stands for the code; landing again on the maintainer's standing word.

@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 27, 2026
Merged via the queue into main with commit 08a7451 Nov 27, 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

2 participants