Repository navigation
feat(psa): Prepare Billing puts a project's approved billable time and expenses on a payment plan (#2621) - #2926
Conversation
…d expenses on a payment plan (#2621) Project Delivery phase 3 step 3a. Project Delivery now depends on Order to Cash (module-split-plan item 21). A plan step names its project (a field Project Delivery contributes to crm_billing_milestone, with the project page's list of steps); a time entry and an expense name the step they were billed on (Billed On, read-only, stamped only by the action). Prepare Billing, a script action on the project for its project manager, the director and PMO positions and administrators, takes the billable hours on approved timesheets and the approved billable expenses up to a date onto one new step under the project's order, or its contract; it refuses with a sentence on a Non-billable project, with no order or contract, with nothing to bill, and while Order to Cash is disabled, before writing anything. A run that fails midway takes its writes back. time_entry_costing lets through an update that changes only Billed On. project_member hides Billed On. 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 席位核对 · independent review · head
|
…e under concurrent runs (#2621) The independent review of #2926 measured three ways a run left a wrong step: a run cut off by the sandbox's wall clock left a full step with part of its rows stamped, and its retry billed the rest again; the hand-written take-back could not cover that; and two runs at once both billed the same rows. The pinned 19.0.0-next.3 gives a script body ctx.api.transaction. - The reads of unbilled rows, the step and every Billed On stamp now run in one platform transaction (capability api.transaction); the take-back is gone. A forced failure and a wall-clock cut-off each leave no step and no stamp, and the retry bills each row once. - Stamps go through the engine's predicate path (multi), so a stamp lands only on a row still unbilled, and the rows on the step are counted before the commit: a short count refuses (CONFLICT) and rolls the run back. - Tests: two runs at once give one 900 step; a row billed by another write inside the run's unit refuses and rolls back; a run cut off at a 1.5 s ceiling with 120 rows leaves nothing; a project director, the PMO and an administrator each run it. - crm_project declares actionLayout.record pinned prepare_billing (#2720, merged from main); stale comments, the plan's phase-3 text, the ADR citation on the member's 404, and the docs' failure sentences in three locales and both manuals are rewritten. Claude-Session: https://claude.ai/code/session_017xRBcUpajguxop2zMyDN9K
|
repo:hotcrm@sunhaolin · sunhaolin · session_017xRBcUpajguxop2zMyDN9K link-check red on
|
|
repo:hotcrm@sunhaolin · sunhaolin · session_017xRBcUpajguxop2zMyDN9K 席位核对 · independent re-review · head
|
…cs name the run limit (#2621) - The transaction already rolls a failed run back, so the body no longer wraps every undeclared error as 409 CONFLICT "try again". A refusal of its own (nothing to bill, the short count) keeps its code; any other error leaves as thrown: a hook's plain throw is the platform's 400 HOOK_ABORTED, a timeout its 500. The forced-failure test pins the new answer and keeps its zero-residue assertions. - The docs site (three locales) and the in-app manual (en, zh) say that a very large backlog can reach the 30-second run limit, leaving nothing behind, and that an earlier Bill Up To date bills it in parts. - psa-module-plan.md: on a driver without transactions the run is not atomic; HotCRM's shipped SQL drivers both support transactions. Claude-Session: https://claude.ai/code/session_017xRBcUpajguxop2zMyDN9K
|
repo:hotcrm@sunhaolin · sunhaolin · session_017xRBcUpajguxop2zMyDN9K Ruling recorded · 2026-12-02T11:26ZThe maintainer, in chat: 「2926 B 选 B1,C 接受」. This settles questions B and C in 7342846946.
The PR stays a draft (maintainer class). After the push and a green CI, the seat posts the head update for the maintainer's merge. Generated by Claude Code |
…p keeps its amount when the order's total changes (#2621) The maintainer's ruling on PR #2926: 「B 选 B1,C 接受」. B1. crm_billing_milestone gains Order to Cash's own Created From (origin: manual, order_confirmation, billing), read-only to people; rows from before it read empty and count as manual. The confirmation flow writes order_confirmation, Prepare Billing writes billing, and sales_order_amount_plan_step no longer moves a lone billing step to the order's new total. Order to Cash reads only its own field; the dependency stays PSA to Order to Cash. Labels in the four O2C packs. Tests: an order written as Confirmed (no generated step), a 300 billing step, the total from 10,000 to 12,000: the step stays 300 and the order shows Payment Plan Differs. Control: a sole step typed by hand still follows the total (12,000), and a generated step reads order_confirmation. C. The docs site (three locales), the Project Delivery manual (en, zh) and the Order to Cash manual (en, zh) say that billing steps sit beside an order's automatic full-amount step, so the order shows Payment Plan Differs, and that the rule is revisited before step 3b. Plan notes, changeset and the field count follow; origin/main merged. Claude-Session: https://claude.ai/code/session_017xRBcUpajguxop2zMyDN9K
|
repo:hotcrm@sunhaolin · sunhaolin · session_017xRBcUpajguxop2zMyDN9K link-check on head |
|
repo:hotcrm@sunhaolin · sunhaolin · session_017xRBcUpajguxop2zMyDN9K Head update —
Stays draft with |
Closes #2621
Clause-②: no
Metadata-protocol: none
Metadata-impact: maintainer — permission set:
project_membergains tworeadable: falsefield rows (Billed On oncrm_time_entryand oncrm_expense); also a hook changed (time_entry_costinglets the billed-on stamp through the timesheet lock); a field on an existing Order to Cash object (crm_billing_milestone.origin) and a flow condition change (sales_order_amount_plan_step), per the ruling 「B 选 B1,C 接受」维护者速读
What changes
app.objectstack.hotcrm.psadeclaresapp.objectstack.hotcrm.o2c(module-split-plan.md, new Decisions recorded (2026-11-17), item 21 — the card asked for item 20, which the 2026-11-16 re-measure already holds, so it is 21). Registration order was already right (o2cStackbeforepsaStack). Pins updated, each with a sentence:test/psa-module-package.test.ts,test/expense-module.test.ts(two),test/package-ownership.test.ts.crm_billing_milestone.crm_project(optional lookup, contributed by PSA, related list on the project page; no column in any view).crm_time_entry.crm_billing_milestone(PSA's own,readonly, indexed) andcrm_expense.crm_billing_milestone(contributed,readonly, merged into PSA's onecrm_expenseextension entry:os validaterefuses a second entry for the same object).src/psa/actions/billing.actions.ts), a script action oncrm_project, one param (Bill Up To). It takes billable entries on the project's approved timesheets and the project's approved billable expenses, dated up to the date and on no step yet; inserts one step under the order, else the contract (name = project number + date range, planned amount = total at bill rates, planned date = run day); stamps each row. Refusals are a declared catalogue in four locales: FORBIDDEN, RECORD_NOT_FOUND, VALIDATION_FAILED (no_date, non_billable, no_source, o2c_off, nothing_to_bill), CONFLICT.crm_project_directorandcrm_pmo(they holdproject_manager+finance_controller), andplatform_admin/org_owner/org_admin. ⛔ Never a project member.current_user.can("crm_billing_milestone", "read")reads false:/auth/me/permissionsleaves the module's objects out, measured), and the body refuses before any write. The body's signal: the platform withholds a disabled module's contributed fields from every read, the body's in-process read included (measured on 19.0.0-next.3: with O2C off the order's and contract'splanned_amountkey is absent; on, present). objectstack#34900 closed as "served", so the body has to check.ctx.api.transaction(capabilityapi.transaction, in the pin). A failure or the sandbox's wall-clock cut rolls all of it back: no step, no stamp. Stamps are a predicate-path compare-and-set (where: { id: {$in}, crm_billing_milestone: null }, multi: true, batches of 200), and the rows on the step are counted before commit. A short count is the action's own 409 CONFLICT. Any other error leaves as thrown (a hook's throw is the platform's 400 HOOK_ABORTED, a timeout its 500), never re-labelled as CONFLICT.time_entry_costing): an update whose only change, besides the engine'supdated_at/updated_by, iscrm_billing_milestoneis let through. A person's own write of the field never reaches the hook as a stamp: the platform withholds a person's value for areadonlyfield frombeforeUpdateand drops it (measured: the lock still answers 409 on an approved timesheet; on a draft the value is dropped).project_memberhides both Billed On fields. No grant on plan steps for any project set. Measured:/meta/actiondoes not serve the action to a member, and the platform answers a run of an action it does not show a caller as an unknown name, so the door answers 404, not 403 (objectstackpackages/runtime/src/action-run-visibility.ts, the rule it cites as ADR-0106 D1). Which reference the member's projection drops is the platform's to decide and is not pinned.ar_accountantreading time entries for a step's labor figure;project_memberhidden from the project's billed figure, as the cost block is.projects/time-and-expenses(en, zh-Hans, zh-Hant), section Billing the time and expenses; in-app manualcrm_psa_projects_cost(en + zh);module-split-plan.mditem 21; dated notes inpsa-module-plan.md,order-to-cash-module-plan.md, REQ-0002, REQ-0007; counts (STATUS, both READMEs: 57 actions; STATUS 643 fields sinceorigin).Tests
Business facts, `test/psa-prepare-billing.test.ts` (through `@objectstack/verify`)
Twenty cases on the shipped app, at
af9824a(19 intest/psa-prepare-billing.test.ts, 1 intest/psa-prepare-billing-timeout.test.ts; the two added in round 4 are the B1 case and its control): one step under the order with the right total (8 h + 4 h at 150 plus one approved billable expense = 2,030.50), unbillable / draft-timesheet / unapproved / later rows left alone, the stamp through the approved timesheet's lock, and a payment recorded against the step by an AR accountant (Received = 2,030.50); a second run takes only what is new and a third refusesnothing_to_billwith no step; contract fallback, andno_sourcerefusal with nothing written; Non-billable refused; a member not shown the action (/meta/action) and answered 404, and not reading Billed On (manager control reads it); a finance controller refused 403 FORBIDDEN before any write; a project manager's direct POST and PATCH on a plan step answer 403; a person's write of Billed On refused by the lock (409) on an approved timesheet and dropped on a draft; a forced failure on the last stamp (an engine hook refuses it) answers the platform's 400 HOOK_ABORTED and leaves no step and no stamp, and the retry bills each row once (700); two runs at once give exactly one 900 step and refuse the other; a row billed by another write inside the run's unit makes the stamps fall short, so the run answers 409 CONFLICT and rolls back, the other write included; a project director, the PMO and an administrator each run it (300); a run cut off at a 1.5 s wall ceiling with 120 rows (an engine hook holds each stamp 50 ms) answers 500, leaves no step and no stamp (re-checked 7 s later), and a run up to an earlier date then bills its 20 rows once; an administrator's delete clears the stamps and the next run bills again; a sales manager's delete of a billing step answers 403 with step and stamp intact; Order to Cash disabled:/auth/me/permissionsdrops the step (the button's gate), the run refuseso2c_off, nothing stamped, the project opens, and on enable the step's Project and the stamps are back.Other local batches at the same tree: script-bodies (new
crm_project:prepare_billinginvocation), authorization-coverage, permission-set-descriptions, o2c-module-package, module-disabled-actions, psa-objects, psa-weekly-time, record-tab-order: 8 files, 151 passed, 1 skipped. Everydocs-*/i18n-*file: 39 files, 796 passed, 9 skipped. psa approvals / budget / tasks / members, project-, o2c-, hooks-runtime-o2c, expense report / request / submit / standard: 25 files, 398 passed, 1 skipped.Ablation
Each guard removed on disk, the suite run, the file restored by an EXIT trap (restore confirmed by grep):
time_entry_costing's billed-on exemption removed → 9 failed | 3 passed (every run hits 409 RECORD_LOCKED).{"success":true,…}expected[400, 'VALIDATION_FAILED'](a step was written into the disabled module).d7ca739) → 3 failed: the wall-clock case, the forced failure, and two-at-once.Acceptance notes
ar_accountantreads plan steps but not projects, so a billing step's Project shows as a restricted record to them.Verification
Local, at
af9824a's tree (exit captured before any pipe):pnpm validate0 (38 Objects, 643 Fields, 57 Actions),pnpm typecheck0,pnpm lint(os lint --strict) 0,pnpm hygiene0;pnpm build0 was last read atcb2e2eb. NOT MEASURED locally: the fullpnpm test(369 files; a 60-file batch outran the container's time limit), so CI's run is the full reading.Two-minute check:
pnpm exec vitest run --maxWorkers=2 test/psa-prepare-billing.test.ts test/psa-prepare-billing-timeout.test.ts— 20 tests pass.🤖 Generated with Claude Code
https://claude.ai/code/session_017xRBcUpajguxop2zMyDN9K