Skip to content

fix(o2c): a payment recorded from an invoice or a billing milestone keeps it (#2755) - #2760

Draft
sunhaolin wants to merge 8 commits into
mainfrom
claude/fix-2755-payment-parent-link-8ccdb3
Draft

sunhaolin wants to merge 8 commits into
mainfrom
claude/fix-2755-payment-parent-link-8ccdb3

Conversation

@sunhaolin

@sunhaolin sunhaolin commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Description

A payment created from a payment plan's Payments tab → New lost its parent: the prefilled Payment Plan was hidden behind "Select Account first", picking the Account emptied it, and the save succeeded with no payment plan. The plan's Received never moved, and nothing said so.

Cause: on crm_payment, the crm_billing_milestone lookup declared dependsOn: ['crm_account'] and no lookupAutofill. The order and contract lookups on the same object dropped dependsOn for the same reason on #2560.

The issue also reported the same loss from an invoice's Payments tab. Since main's #2806/#2819 (invoices and payments run in parallel), the payment's Invoice is hidden and the invoice page has no Payments tab, so that door no longer exists; this PR keeps main's ruling and does not bring the invoice lookup back. An API write or an import can still name an invoice, and the server rules below cover it.

Metadata-impact: maintainer — two hooks changed and a validation tightened (a payment naming another account's payment plan is now refused on save, by the payment plan when the write names it and by the invoice when an API write's invoice brought it; before, only another account's invoice was). No permission set, sharing rule, object or field is added, removed or renamed; no stored data changes.

Merged main's #2805/#2811 rename (crm_billing_milestone shows as Payment Plan / 回款计划 / Plan de cobro / 入金計画) and #2806/#2819. The browser checks in the table below ran before both, so they show the old Billing Milestone label and an invoice door that is now gone.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Related Issues

Fixes #2755
Related to #2598 (objectstack-ai/objectstack#35050: a prefilled parent does not fire lookupAutofill), #2806

Changes Made

The trade-off

Without dependsOn the payment plan picker no longer filters by the account: it lists every account's payment plans the user may read. The server refusal replaces the filter, so a wrong pick is caught at save, not in the picker. When the form still carries a contract of the other account, payment_row_stamp (priority 50) refuses first and names the contract; the payment plan is named once the contract is out of the way.

Not worked around

A prefilled parent does not fire lookupAutofill (objectstack-ai/objectstack#35050, tracked on #2598), so from the payment plan's door the Account is still picked by hand. This PR does not work around that. What holds now: the prefilled payment plan is visible, survives picking the account, and is saved.

Testing

Door What was done Read back
Milestone "Globex seats on delivery" → Payments → New Opens with Billing Milestone shown. Picked Account Globex Industries: the milestone stayed. Saved 2,500 Payment carries the milestone (and its order, filled by the server). Milestone Received 0 → 2,500
Payments list → New Picking a milestone alone fills the Account —
Cross-account Contract and step of Initech on the form, Account changed to Acme Corporation (nothing is cleared) Save refused, nothing saved. In turn, as each offending value was removed: the contract is named, then "Initech Q3 service fee belongs to another account…" (shown in zh-Hans)

(The invoice-door rows of the earlier run are dropped: #2806 hid that door.)

Checklist

  • I have added a changeset
  • Metadata changes under src/ declare their class (see the Metadata-impact: line above)
  • English docs changed with their Chinese twins
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Review fixes (Seat record)

  1. An invoice of the payment's account whose payment plan is another account's is refused by the invoice the write named, not by the payment plan it brought.
  2. With no account on the write, the refusal of another account's invoice or step names it, not the order it carries.
  3. Manual and docs site say a save that sets the invoice gives the payment the invoice's payment plan whenever it has one.
  4. The collection-plan tests pin stored values and the exact refusal text.

Additional Notes

Draft on purpose: a maintainer-class metadata change stays a draft for the maintainer's merge (AGENTS.md, How a green PR lands). The independent review of Who decides a change has not been run on this PR yet.

Open for the maintainer, not decided here: under #2806 the hook still copies an API-named invoice's payment plan onto the payment (main left it so); whether that copy should stay is a product call.

Follow-ups, not in this PR:

  • lookupAutofill with overwrite: true empties the target when the picked record's source is empty (platform behaviour, worth raising upstream).

…eeps it (#2755)

New on the Payments tab of an invoice or of a billing milestone opened a
payment whose prefilled parent was hidden behind "Select Account first";
choosing the account emptied it, and the payment was saved under the account
alone, so the invoice's Paid / Open and the milestone's Received never moved.

- crm_payment: the invoice and billing milestone lookups drop `dependsOn` and
  gain `lookupAutofill`. The invoice fills the account, and the contract and
  the milestone while the payment has none; the milestone fills the account.
  The invoice -> milestone fill does not overwrite: measured in the browser,
  an overwriting autofill empties a chosen milestone when the invoice has
  none, which the server keeps.
- payment_plan_step_stamp: refuse a billing milestone of another account,
  naming it, as another account's invoice already was; judge both when a
  write moves the payment to another account.
- payment_row_stamp: a payment naming its account takes no order or contract
  from an invoice or step of another account, so the refusal names what the
  user chose.
- Translations (zh-CN, es-ES, ja-JP), tests, the Invoices and Payments manual
  and site page in every locale, changeset.

The pickers now list every account's invoices and milestones; the refusal on
save replaces the filter. A prefilled parent still does not fire
`lookupAutofill` (objectstack-ai/objectstack#35050, hotcrm#2598), so the
account is picked by hand from those two pages; not worked around here.

Fixes #2755
@vercel

vercel Bot commented Nov 24, 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:50am 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 24, 2026
@sunhaolin

Copy link
Copy Markdown
Collaborator Author

Seat record · HOLD · head b1097378 · 2026-11-24T09:06Z

独立评审已完成。评审判定本 PR 为 maintainer 类(改了 hook,并收紧了一条保存时的规则),按 2026-11-19 的裁定保持 draft,由维护者本人决定是否合并;本席位不转 ready、不挂 auto-merge。

  • 改了什么:回款的「发票」「回款节点」去掉按客户过滤,改为选中后带出客户、合同、节点;保存时拒绝别的客户的发票或节点,并点名该记录。
  • 为什么改、谁提的:从发票 / 回款节点的「回款」页签新建回款:父记录被「请先选择客户」盖住、选客户后被清空,保存的回款没有挂到发票上 #2755(p1,本地 UI 测试发现):从发票或回款节点新建的回款没有挂到父记录上,界面却提示已创建。
  • 最坏情况与能否回退:个别经导入产生的错配数据(发票挂着别的客户的节点)再收款时会被拒,提示指向节点而非发票;已存数据不被改写,回退只需撤销代码,无迁移。
  • 评审没有验证的:未在浏览器实测两个入口;未跑测试;编辑表单是否提交全部字段(决定已有错配回款改金额时是否被拒)未确认;未读 PR 正文。

Findings

  1. payment.hook.ts:97-115(低到中):客户 A 的发票,其已存节点属于客户 B 时,只填了发票的回款会被拒,提示说的是节点,用户并没有选节点。
  2. _row-stamp.ts:113-134(低):写入没有带客户时 payer 为空,拒绝提示会点名一个用户没选过的订单。
  3. crm_o2c_invoices_payments.md:32-33 写的是「回款没有节点时」由发票带出,但 payment.hook.ts:98 总是替换。文档和代码要说同一件事。
  4. test/o2c-collection-plan.test.ts:198-212 的断言偏弱。

与 #2767 的关系:行为上不矛盾,文本上冲突(src/o2c/objects/_row-stamp.ts、test/o2c-collection-plan.test.ts、test/refusal-envelope.test.ts)。两个 PR 都把手工维护的拒绝条数从 98 改成 99,都合入后应为 100。#2767 合入后,_row-stamp.ts:112 的注释「Payments only: nothing after this hook judges an invoice's step」不再成立。建议本 PR 先合,#2767 随后 rebase。

Landing:等待维护者决定。

@sunhaolin

Copy link
Copy Markdown
Collaborator Author

Seat record · 浏览器实测 · head b1097378 · 2026-11-24T12:51Z

在本分支的本地服务(独立开发库,zh-CN)上实测,五项全部通过。PR 保持 draft,未改动合并状态。

  • 发票 → 回款 → 新建:发票已预填并可见;选客户后保存成功,回款保留 crm_invoice,服务器补上回款节点与合同;节点已回款 0 → 20000,发票已收 20000。✅
  • 回款节点 → 回款 → 新建:节点已预填,选客户后仍在;保存后回款保留 crm_billing_milestone,服务器补上订单;节点已回款 2500 → 3500。✅
  • 空白表单:选回款节点带出客户;选发票带出客户(覆盖原值)、合同、回款节点。✅
  • 跨客户:另一个客户的发票、另一个客户的回款节点都被拒绝,表单级提示点名记录,未保存。✅
  • 只改金额的编辑:保存成功,三个关联都保留,节点已回款随之更新。✅

Nits(不阻塞):

未实测:批量更新、非管理员角色、en 语言环境。

sunhaolin and others added 3 commits November 25, 2026 02:30
Resolves the conflicts with #2767 (an invoice keeps its billing milestone):
- _row-stamp.ts: one account check for both forms. A payment or an invoice
  that names its account takes nothing from an invoice or a step of another
  account, so payment_plan_step_stamp and invoice_plan_step_guard refuse it
  by its own name.
- refusal-envelope.test.ts: 100 call sites (both new refusals).
- o2c-collection-plan.test.ts: both imports kept.
…claude/fix-2755-payment-parent-link-8ccdb3
…nvoice's milestone wins (#2755)

Review fixes on #2760:

- payment_plan_step_stamp: a billing milestone of another account that the
  payment took from its invoice (the write did not name it) is refused by
  the invoice: "INV-… counts toward …, a billing milestone of another
  account. Correct the invoice's billing milestone, or choose another
  invoice." (reason invoice_milestone, translated in zh-CN, es-ES, ja-JP).
- payment_row_stamp: the account an invoice or step is judged against is
  the one the write names, else the one its contract or order gives, else
  the row's own; a write naming only a contract no longer takes the order
  of another account's invoice and get refused under that order.
- Manual and docs site: a save that sets the invoice gives the payment the
  invoice's milestone whenever the invoice has one (Received is a one-hop
  summary over the payments pointing at the step); the payment keeps its
  own only when the invoice has none or there is no invoice.
- Collection-plan tests pin the exact refusal text and the stored values.

Co-Authored-By: Claude <noreply@anthropic.com>
…claude/fix-2755-payment-parent-link-8ccdb3

# Conflicts:
#	test/refusal-envelope.test.ts
…claude/fix-2755-payment-parent-link-8ccdb3

# Conflicts:
#	content/docs/(product)/order-to-cash/invoices-and-payments.mdx
#	content/docs/(product)/order-to-cash/invoices-and-payments.zh-Hans.mdx
#	content/docs/(product)/order-to-cash/invoices-and-payments.zh-Hant.mdx
#	src/o2c/docs/crm_o2c_invoices_payments.zh.md
…claude/fix-2755-payment-parent-link-8ccdb3

# Conflicts:
#	test/refusal-envelope.test.ts
…claude/fix-2755-payment-parent-link-8ccdb3

# Conflicts:
#	content/docs/(product)/order-to-cash/invoices-and-payments.mdx
#	content/docs/(product)/order-to-cash/invoices-and-payments.zh-Hans.mdx
#	content/docs/(product)/order-to-cash/invoices-and-payments.zh-Hant.mdx
#	src/o2c/docs/crm_o2c_invoices_payments.md
#	src/o2c/docs/crm_o2c_invoices_payments.zh.md
#	src/o2c/objects/payment.object.ts

This branch has not been deployed

No deployments
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

1 participant