Repository navigation
feat(o2c): Prepare Billing reduces the order's automatic full-amount step (#2934) - #2938
Conversation
…step (#2934) Ruling Q1 = B on #2933, variant B-1. Each Prepare Billing run, in its own transaction, takes what it billed off the order's one clean generated step (origin order_confirmation, nothing received on it, no invoice naming it) and deletes it at zero, so the plan still adds up to the order and Payment Plan Differs reads true only when the plan really differs. The write is a compare-and-set on the amount read; a writer in between refuses the run with CONFLICT and rolls it back. Billing past the order's amount deletes the step and keeps the whole bill, so the order shows Payment Plan Differs for the excess. A step with money or an invoice against it, or an order with several generated steps, is left as it is. A deleted billing step gives its amount back to the generated step while it exists (billing_step_give_back), never past the order's total, so rows billed again are not taken off twice. Manuals (en, zh), the docs site and the plan replace the "tracked in #2934" wording; a changeset. Claude-Session: https://claude.ai/code/session_017xRBcUpajguxop2zMyDN9K
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
repo:hotcrm@sunhaolin · sunhaolin · session_017xRBcUpajguxop2zMyDN9K CI on The independent review is pending: the reviewer is out of quota until 12-06 (UTC). The maintainer is choosing between waiting and a substitute reviewer. |
|
repo:hotcrm@sunhaolin · sunhaolin · session_017xRBcUpajguxop2zMyDN9K Independent read-only review · head
待维护者裁决
Seat: items ③–⑤ go back to the dev now. A push also re-runs ⑥. Risks ①② will be stated in the PR body; with Q4=B, the root fix goes to a follow-up card. Evidence: |
…2934) Independent review of #2938 at 6174e80, items 3 to 5 and 1-2 wording: - Rule 11: the give-back's compare-and-set is typed, not cast. The hook API declares HookCompareAndSetOptions (where names the id, multi: true; the measured answer is the row count) as an update overload, with its reason and its one rostered caller; no guard in test/ reads hook write options, so the two comments are the record. - After three missed compare-and-sets the hook logs a warning through ctx.log (the build grants log to the lowered body, measured: api.read, api.write, log); HookLogContext types it. - Docs, manuals and changeset: the generated step is deleted when a run bills more than it still holds, which on a split plan comes before the order's total. The changeset states that the give-back runs after the delete commits, gives up after three misses, and does not record what each run took, relying on the Total Price cap. - Tests with exact figures: give-back on a split plan (5,700 back to 6,000, the cap not reached); generated step already deleted; generated step with money received; two misses then 9,500 + 300 = 9,800; three misses leave 9,400 and the shipped body logs one warning; total raised after a reduction; cancelled with and without money on the billing step. runShippedHook takes an optional host logger. Claude-Session: https://claude.ai/code/session_017xRBcUpajguxop2zMyDN9K
|
repo:hotcrm@sunhaolin · sunhaolin · session_017xRBcUpajguxop2zMyDN9K Head update:
Stays draft for the maintainer's merge; the 4 rulings above are pending. |
|
repo:hotcrm@sunhaolin · sunhaolin · session_017xRBcUpajguxop2zMyDN9K Maintainer's rulings and merge word in chat, verbatim: 「2938 你帮我合并。4 个问题:1A 2A 3A 4A+开卡」 · recorded 2026-12-04T08:55Z
All 22 checks on |
Closes #2934
Clause-②: no
Metadata-protocol: none
Metadata-impact: maintainer — a hook changed (a new
afterDeletehook,billing_step_give_back, oncrm_billing_milestone) and an existing action (Prepare Billing) now changes and deletes the order's generated plan step. No permission set, sharing rule, field or object is added, removed or renamed. AGENTS.md puts "a hook changed" in the maintainer class until the reviewer says otherwise; the reviewer may downgrade it toreviewer(a flow-like data change that does not change who sees what).维护者速读
What changes
src/psa/actions/billing.actions.ts), in the samectx.api.transactionas the run: after the stamps and their count check, the order's generated step (origin = order_confirmation) is reduced by the amount billed and deleted when it reaches zero. Payment Plan Differs then reads true only when the plan really differs. The action's result gainsorder_step({ id, amount, deleted }, or null when nothing was reduced).multi: true) on{ id, planned_amount: <amount read> }whose answered row count must be 1. Another writer between the read and the write makes it 0, and the run throws CONFLICT and rolls back (step, stamps and all), the existing 409 the person retries. Measured: the engine's predicate update and delete answer the row count through the sandbox facade.crm_invoice.crm_billing_milestonecolumn): left as it is. Someone is working that plan.billing_step_give_back,src/o2c/objects/billing_milestone.hook.ts,afterDelete,runAs: 'system'). Why: deleting a billing step clears its rows (objectstack#34899), so the next run bills them again and reduces the step again. Without the give-back the same rows would be taken off twice. Same conditions as the reduction; the generated step never grows past the order's Total Price, so a billing step written before this change (which took nothing) gives nothing back. When the generated step is gone, nothing is recreated: the plan reads short until the next run bills the rows again, which restores it.ctx.log.warn, naming the order, the step and the amount), and the generated step stays short of the amount until a person corrects it.src/sales/objects/_hook-api.tsdeclaresHookCompareAndSetOptions(wherenames theid,multi: true) as anupdateoverload answering the row count (measured: 1 when the compare held, 0 when another writer moved the row). It carries the reason and the roster of its one caller. No guard intest/reads hook write options, so that comment and the hook's comment are the record.HookLogContexttypesctx.log; the build grants the lowered bodylog(measured:["api.read","api.write","log"]).planned_amount/plan_differson the order (sales-order.extension.ts, a summary and a formula, no code change); the amount-follow flow edges e6/e7 (sales-order-amount-plan-step.flow.ts) still follow only a lone non-billing step: after a reduction the order has several steps and is left alone, and after the generated step is deleted a lone billing step still takes e7. The confirmation flow creates a step only when there is none. The cancel-trim flow is unaffected.open_amountdrives the Overdue view (a reduced step is open less, which is correct). The contract'splannedsummary sees the same steps. No dataset or dashboard reads these fields. The project's Billed / Not Yet Billed (Project Delivery phase 3, step 3b: billed and not yet billed on the project, in the project financials and on the dashboard; manual and docs #2622) is not touched.crm_psa_billing(en, zh),crm_o2c_collection_plan(en, zh), the docs site's Time and Expenses and Collection Plan pages (en, zh-Hans, zh-Hant) andpsa-module-plan.md. The "tracked in Order to Cash: Prepare Billing reduces the order's automatic full-amount payment plan step, so Payment Plan Differs stays truthful #2934" wording is replaced by the new behaviour..changeset/2934-billing-reduces-auto-step.md(minor), including the upgrade note.Tests
test/psa-prepare-billing-order-step.test.ts(19 cases, on the booted app through the action door), with exact figures:plan_differsempty; open across the plan = 10,000.order_stepnull, contract steps unchanged.[hook 'billing_step_give_back'] billing_step_give_back: the generated plan step kept changing; its amount was not given backwith{ order, step, amount: 300 }. (The booted handle runs handlers in-process, whose context has noctx.log, so the warning is read off the shipped body;runShippedHookgained an optional host logger.)completed.test/runtime-coverage.test.ts: the new file joinsRUNTIME_TEST_FILES, so the new hook is named in a runtime test.Ablation (red without the change)
if (false && orderId)): 5 of 10 red (the 9,700/9,550 case, exactly-zero, beyond-the-order, the CONFLICT case, the give-back case); restored, 10/10.expected 9700 to be 10000; restored, 10/10.round2(ceiling)): 2 red, the split plan (expected 10000 to be 6000) and the two-miss retry (expected 10000 to be 9800). The row-count check removed (returnafter the first write whatever it answered): 3 red, the two-miss retry (expected 9600 to be 9800), three misses (expected 9600 to be 9400) and the shipped-body warning case. Restored, 19/19.Acceptance notes
Verification
Booted `objectstack dev` (port 4001), Wayne Operations Module Rollout (seeded T&M) linked to a new 10,000 order confirmed Draft→Confirmed, a consultant's timesheet submitted and approved through the approval, Prepare Billing twice
en:
zh-CN (
accept-language: zh-CN, a second order): the same figures (8,640 then 7,960, Planned 10,000,plan_differsempty, open 10,000); a third run answered 400截至 2026-11-23,没有尚未开票的已批准可计费工时或费用。and changed nothing. The zh-CN label of the flag is 回款计划与订单金额不符.Two-minute check:
npx vitest run test/psa-prepare-billing-order-step.test.ts, which should show 19 passed.Read first:
src/psa/actions/billing.actions.ts(the reduction block after the count check),src/o2c/objects/billing_milestone.hook.ts(the give-back cap and compare-and-set),test/psa-prepare-billing-order-step.test.ts(the CONFLICT case).Gates on head
91aa8d3:pnpm validate/typecheck/lint(os lint --strict) /hygieneexit 0; full suite as 8 shards exit 0 (745 / 848 / 847 / 870 / 832 / 957 / 773 / 1200 passed).🤖 Generated with Claude Code
https://claude.ai/code/session_017xRBcUpajguxop2zMyDN9K