Repository navigation
fix(o2c): an invoice recorded from a billing milestone keeps it (#2755) - #2767
Conversation
New on a billing milestone's Invoices tab opened an invoice whose Billing Milestone was prefilled but hidden behind "Select Account first", and choosing the Account emptied it. The invoice was saved with no milestone, so the milestone's Invoiced never moved. This is the invoice half of #2755; the payment half is #2760. - crm_invoice.crm_billing_milestone drops dependsOn and gains lookupAutofill: the account (overwrite), and the order and the contract while the invoice has none. - A new hook, invoice_plan_step_guard, refuses an invoice whose billing milestone belongs to another account, by the milestone's name, in the refusal envelope. The picker no longer filters by account, so this rule replaces the filter, for the form as for an import or an API write. - The row stamp takes no order or contract from another account's milestone when the invoice names its account, so the refusal names the milestone. - Message translated in zh-CN, es-ES and ja-JP; tests, the module manual, the site page and a changeset ride along. A prefilled parent still does not fire lookupAutofill (objectstack-ai/objectstack#35050, tracked on #2598); that is not worked around here, so the Account is still chosen by hand from a milestone's page.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
Seat record · HOLD · head 独立评审已完成。PR 自述为 maintainer 类;评审认为可按 reviewer 类处理,但它同样收紧了一条保存时的规则,并且必须排在 #2760 之后,所以和 #2760 一起交维护者决定;本席位不转 ready、不挂 auto-merge。
Findings
与 #2760 的关系:行为上不矛盾,文本上冲突( Landing:等待维护者决定;建议 #2760 先合,本 PR rebase 后再合。 |
|
Seat record · 浏览器实测 · head 在本分支的本地服务(独立开发库,zh-CN)上实测,四项全部通过。PR 保持 draft,未改动合并状态。此前 HOLD 记录里"没有在浏览器实测表单""编辑表单是否能保存"两条就此消除。
Nits(不阻塞):
仍未验证:批量更新时 hook 能否拿到原记录;hook 读节点是否受读权限限制(只用管理员测过);en 语言环境。与 #2760 在 |
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.
Description
An invoice created from a billing milestone's Invoices tab → New lost the milestone: the prefilled Billing Milestone was hidden behind "Select Account first", picking the Account emptied it, and the save succeeded with no milestone and no order or contract. The milestone's Invoiced never moved, and nothing said so. This is the invoice half of #2755; the payment half is #2760.
Cause: on
crm_invoice, thecrm_billing_milestonelookup declareddependsOn: ['crm_account']and nolookupAutofill. The order and contract lookups on the same object droppeddependsOnfor the same reason on #2560. And no rule refused an invoice naming another account's milestone.Metadata-impact: maintainer — a hook is added and a validation tightened (an invoice naming another account's billing milestone is now refused on save; before, it was saved). No permission set, sharing rule, object or field is added, removed or renamed; no stored data changes.
Type of Change
Related Issues
Related to #2755 (the payment half is #2760; this is the follow-up that PR names)
Related to #2598 (objectstack-ai/objectstack#35050: a prefilled parent does not fire
lookupAutofill)Changes Made
src/o2c/objects/invoice.object.ts:crm_billing_milestonedropsdependsOnand gainslookupAutofill. The milestone fills the account (overwrite: true), and the order and the contract while the invoice has none (default mode), which is what the server stamps on save.src/o2c/objects/invoice.hook.ts: a new hookinvoice_plan_step_guard(priority 90, afterinvoice_row_stampat 50, beforeinvoice_figuresat 100) refuses an invoice whose billing milestone belongs to another account, in the refusal envelope (VALIDATION_FAILED, reasonmilestone_named, parammilestone). It judges a write that sets the milestone, or that moves the account under a milestone the invoice keeps; an edit of the amount and the paid-amount recompute are not judged.src/o2c/objects/_row-stamp.ts(three lines): an invoice that names its account takes no order or contract from a milestone of another account, so the refusal names the milestone the user chose rather than an order or contract they never saw.test/refusal-envelope.test.tscount 98 → 99.test/o2c-collection-plan.test.ts(invoice_plan_step_guard: an invoice's plan step belongs to its account (hotcrm#2755), 7 cases): the lookup carries nodependsOnand the autofill above; an invoice entered from a plan step keeps it and the step counts it; another account's step is refused by name on insert and on update; moving the account under a kept step is refused; a control edit is not judged.src/o2c/docs/crm_o2c_invoices_payments.md+.zh.md, andcontent/docs/(product)/order-to-cash/invoices-and-payments.mdx+.zh-Hans+.zh-Hant..changeset/2755-invoice-keeps-billing-milestone.md(patch).The trade-off
Without
dependsOnthe Billing Milestone picker no longer filters by the account: it lists every account's milestones the user may read. The server refusal replaces the filter, so a wrong pick is caught at save, not in the picker. Picking a milestone also overwrites an Account already chosen on the form with the milestone's account, as picking an order or a contract does.When the form still carries the order or contract the milestone filled in,
invoice_row_stamp(priority 50) refuses first and names that order or contract; the milestone is named once it is out of the way (measured below). The docs and the changeset say so.Why the order and contract autofill do not overwrite
lookupAutofillwithoverwrite: trueempties its target when the picked record's source field is empty, and a milestone carries an order or a contract, not always both. In the default mode a value already on the form stays, which is also what the server does.Not worked around
A prefilled parent does not fire
lookupAutofill(objectstack-ai/objectstack#35050, tracked on #2598), so on an invoice opened from a milestone's page the Account is still picked by hand. This PR does not work around that. What holds now: the prefilled milestone is visible, survives picking the account, and is saved.Edges, as they stand
invoice_row_stampunder the order's or the contract's name, before the guard runs.Testing
pnpm verifygreen locally (validate, typecheck, lint, hygiene, build, test)Before (main,
48082b7d)After (this branch)
Conflicts to expect with #2760
Both PRs are cut from
mainand neither has merged. This branch was kept apart from #2760's rather than stacked on it, so whichever lands second needs a small manual merge:A trial merge of this tree with #2760's head (
b1097378) gives three conflict hunks, one per file:src/o2c/objects/_row-stamp.ts: both change the line that pushes the plan step as a source. fix(o2c): a payment recorded from an invoice or a billing milestone keeps it (#2755) #2760 addsofPayer(step)for payments; this PR adds the same test for an invoice. The merged line needs both conditions. fix(o2c): a payment recorded from an invoice or a billing milestone keeps it (#2755) #2760's comment there, "Payments only: nothing after this hook judges an invoice's step", stops being true once both are in.test/refusal-envelope.test.ts: the history comment above the pinned count of refusal call sites. The count line itself does not conflict: both PRs change 98 to 99, so git keeps 99, and the test then fails. With both in, it must read 100, by hand.test/o2c-collection-plan.test.ts: the import line (Invoicehere,Paymentthere); keep both.The five doc pages and the three translation packs are changed by both PRs and merge without a conflict.
Checklist
src/declare their class (see theMetadata-impact:line above)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. Auto-merge is not armed.