Skip to content

feat(psa): a project shows Billed and Not Yet Billed beside Approved to Bill (#2622) - #2933

Merged
objectstack-fleet[bot] merged 5 commits into
mainfrom
claude/issue-2622-project-billed
Dec 3, 2026
Merged

objectstack-fleet[bot] merged 5 commits into
mainfrom
claude/issue-2622-project-billed

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2622

Clause-②: no
Metadata-protocol: none
Metadata-impact: maintainer — permission sets: project_member gains seven readable: false field rows on crm_project (Billable Labor, Billable Expenses and Approved to Bill, readable to a team member until now, plus the four new billing fields); finance_controller, system_admin and project_manager gain the seven matching readable: true rows (PSA_BILLING_FIELDS, the #2820 two-role rule); new fields, dataset measures and dashboard tiles otherwise.
Ruling-ref: the maintainer in chat on this PR, relayed by the seat 2026-12-03: 「Q1 选 B,Q2 选 A,Q3 选 E,旁证补上」

维护者速读

  • 项目经理、项目总监、PMO 和财务在项目「财务」区看到新的「已出账」和「未出账」,两者相加等于「已批准待开票」;项目概览仪表盘多一行开票数字,「各项目出账情况」表就是开票清单。
  • 项目交付第三阶段第二步:在第一步「准备开票」之后,回答项目已经开出去多少、还剩多少没开,替项目经理和财务解决开票对账。
  • 数字算错只影响显示和列表,可以随时撤回;项目成员从此看不到「已批准待开票」等开票数字(以前看得到),这是权限变化。
  • 无(三项裁决已按原话落实:订单与回款不改、另立卡 Order to Cash: Prepare Billing reduces the order's automatic full-amount payment plan step, so Payment Plan Differs stays truthful #2934 跟踪;项目成员看不到开票数字;不做列表视图,用仪表盘表格)。

What changes

  • crm_project Financials (src/psa/objects/project.object.ts): billed_labor_amount (summary of crm_time_entry.bill_amount through the entry's own crm_project, filter is_billable and Billed On $null: false), billed_expense_amount (summary of approved billable crm_expense.amount, Billed On $null: false), billed_amount (Billed, formula of the two), unbilled_amount (Not Yet Billed = Approved to Bill minus Billed, a stored computed column, expression, so a list can filter on it). One hop each; no summary of a summary. No stored flag was needed: the summary filter reads the Billed On lookup itself.
  • Why Billed reads the stamped rows, not the plan steps: the steps are Order to Cash's, a person may change a step's amount, and they leave with Order to Cash; the rows are Project Delivery's, so Billed is always a part of Approved to Bill and keeps counting with Order to Cash off. The probe's two grants (ar_accountant reading time entries, project_member kept from a step summary) were for a summary over the step and are not needed.
  • Invoiced and received: no project total. An invoice and a payment name the step, and the step's Received is itself a summary over payments, so a project total would be two hops (a summary of a summary). They are read per step in the project's list of payment plans (Received, Open). Where the card says invoiced is "read on each plan step": the merged code's step has no Invoiced figure; its invoices list on its own page.
  • The list for the people who bill is the Projects Overview's Billing by Project table, filtered to unbilled_amount > 0, sorted by Not Yet Billed, 100 rows (widened from 20: it is the worklist). No list view (ruling Q3 E): a view that filters or sorts on Not Yet Billed breaks for project_member, which masks it (test/authorization-coverage.test.ts, unchanged and green); the console measured 403 "You don't have access" for a member who picks such a view in the switcher.
  • project_financials: billed_labor_sum, billed_expense_sum, billed_sum (derived sum), unbilled_sum (derived Approved to Bill minus Billed). Projects Overview: a billing row (Approved to Bill, Billed, Not Yet Billed metrics, Billing by Project table), every project whatever its status.
  • project_member hides the whole billing block (the card: "A project member sees none of the three figures"; ruling Q2 A). The member's own entries keep their bill rate. Two roles: PSA_BILLING_FIELDS (src/sales/profiles/_psa-grants.ts) gives finance_controller, system_admin and project_manager a read row on each of the seven, so a holder of one of them beside project_member reads the block (the feat!: move to ObjectStack 19.0.0-next.2 and protocol 19 #2820 rule the cost fields follow); project_manager is included because it is the set that bills.
  • Labels in four packs. zh-CN / ja-JP / es-ES: the O2C packs already spell Invoiced/Uninvoiced 已开票/未开票, 請求済/未請求, Facturado/Pendiente de facturar, so Billed / Not Yet Billed take distinct words (已出账/未出账, 請求計上済み/請求未計上, Pasado a cobro/Pendiente de pasar a cobro) and the manual says Billed is not invoiced.
  • Docs. In-app manual: a new page crm_psa_billing (en + .zh.md), Billing Time and Expenses — From Approval to Payment; the cost page's billing section moves there; the overview page gains a billing section. Docs site: Projects (index, Time and Expenses) and Order to Cash (Collection Plan, a new Steps from a project's billing section), three locales. docs/feature-inventory.md (new PSA domain, PSA-001 and PSA-002), docs/STATUS.md (647 fields), psa-module-plan.md (phase 3b built), REQ-0002 traceability. Changeset .changeset/2622-project-billed.md.

Acceptance notes

  • Ruling Q1 B: Order to Cash is unchanged; Payment Plan Differs beside an automatic full-amount step stays, and the docs and the plan point at hotcrm#2934, where Prepare Billing reducing that step is tracked.
  • The upgrade commands in the changeset (os migrate summary-nulls, os migrate stored-expressions) are named from --help; they were NOT run against an upgraded database.

Tests

test/psa-billed.test.ts (new, 5 cases) and the narrowed sets, at e35cd45 / 050cce1
  • test/psa-billed.test.ts: after a run Billed + Not Yet Billed = Approved to Bill (1430.5 = 1430.5 + 0); new approved time and expense move Not Yet Billed only (1770.5 / 1430.5 / 340); a submitted expense moves nothing; deleting a billing step returns its rows to Not Yet Billed (600 / 0 / 600); a member reads none of the seven billing fields, the PM and finance read all three; the stored filter unbilled_amount > 0 lists a project with something left and not one billed in full; with Order to Cash disabled the project reads 300 / 300 / 0 and new approved time moves it to 450 / 300 / 150. Tests 5 passed (5).
  • Discriminating run: before the project_member rows, the member case failed member reads no billable_labor_amount: expected 150 to be undefined.
  • Narrowed set (23 files: PSA, Prepare Billing, docs counts/drift/rosters/locale/zh names/dashboard tiles, datasets, money roll-ups, sharing): Tests 2 failed | 667 passed; the two were pins of decisions this card changes (psa-objects "the amount to bill stays readable", psa-module-package nav roster), updated; rerun with 10 more files: Tests 236 passed (236); docs set after the last edit Tests 69 passed (69).
  • pnpm validate 0, pnpm typecheck 0, pnpm lint (strict) 0, pnpm hygiene 0, pnpm build 0 at 050cce1. The full pnpm test farm is left to CI (a 560 s local attempt ran out of time behind the shared lock queue).

Verification

Browser pass on a booted `objectstack dev` (19.0.0-next.3), as project manager, finance controller and project member, en and zh-CN, with Order to Cash on and off

Data: seed project PRJ-00002 linked to a seed order, a PM and a consultant staffed, a timesheet approved through the PM's Inbox (1.5 h, 300), Prepare Billing as the PM (one 300 step), then a second timesheet approved (2.5 h, 500). REST and screen agree: Approved to Bill 800, Billed 300, Not Yet Billed 500.

  • Project manager, en / zh-CN: every Project Delivery navigation entry (20, at 050cce1, when the since-removed Projects to Bill entry still existed) opened with no API answer at or above 400; Financials reads Approved to Bill 800.00 · Billed Labor 300.00 · Billed Expenses 0.00 · Billed 300.00 · Not Yet Billed 500.00 (zh: 已批准待开票 800.00 · 已出账工时金额 300.00 · 已出账费用 · 已出账 · 未出账 500.00); the dashboard's billing row reads 800 / 300 / 500 and Billing by Project; the since-removed list view showed the project under the filter chip "Not Yet Billed: Greater than 0".
  • Finance controller, en / zh-CN: the same figures, list and tiles.
  • Project member, en / zh-CN: 15 entries, no Projects Overview; every entry opens with no API error; the project's Financials shows Planned Revenue only (no billing field); the dashboard opened from its URL shows no billing tile and no cost tile; the since-removed list view, picked in the All Projects switcher or opened from its URL, answered 403 and "You don't have access" (the reason it was removed).
  • Order to Cash disabled (PATCH /packages/app.objectstack.hotcrm.o2c/disable), as administrator and project manager: every navigation entry, the project page, a billed time entry, its timesheet and an expense opened; Prepare Billing is not shown; the figures keep their values (800 / 300 / 500 on the record and the dashboard); enabled again, the same.
  • Seen with Order to Cash on and off alike, not from this change: a non-administrator's record page asks GET /api/v1/meta/object/sys_audit_log and gets 404; the page renders.

Class: maintainer. It changes a permission set (project_member loses read of Approved to Bill, Billable Labor and Billable Expenses, which it had), which AGENTS.md Who decides a change puts in the maintainer row; the PR stays a draft for his merge.

First files to read: src/sales/profiles/project-member.profile.ts (the permission change), src/psa/objects/project.object.ts (the four fields, the summary filters), src/psa/views/project.view.ts.

Two-role rows, measured at 38475ee on a booted dev server over REST: project_manager+project_member and finance_controller+project_member read 7/7 billing fields; project_member alone 0/7. The Billing by Project table renders ("No data yet" on the fresh seed, no API error).

Two-minute check: npx vitest run test/psa-billed.test.ts test/two-role-field-rows.test.ts — expect all passed.

🤖 Generated with Claude Code

https://claude.ai/code/session_017xRBcUpajguxop2zMyDN9K

…to Bill (#2622)

Project Delivery phase 3 step 3b. The project's Financials gain Billed
Labor and Billed Expenses (one-hop summaries over the time entries and
expenses whose Billed On is filled), Billed (their sum) and Not Yet
Billed (Approved to Bill minus Billed, a stored computed column so a
list can filter on it). Projects to Bill lists the projects with
something left to bill, for the people who bill. project_financials
gains the four measures and Projects Overview a billing row.
project_member hides the whole billing block, Approved to Bill and its
halves included. A manual page follows billing from the approved hour
to the payment; the docs site, feature inventory, STATUS, the plan and
REQ-0002 are updated.

Claude-Session: https://claude.ai/code/session_017xRBcUpajguxop2zMyDN9K
… sees no billing tile (#2622)

Measured in the browser: opened from a link, Projects Overview shows a
team member neither the cost tiles nor the new billing row.

Claude-Session: https://claude.ai/code/session_017xRBcUpajguxop2zMyDN9K
@vercel

vercel Bot commented Dec 3, 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 Dec 3, 2026 4:05am UTC

Request Review

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:hotcrm@sunhaolin · sunhaolin · session_017xRBcUpajguxop2zMyDN9K

Independent read-only review (Fable) · head 050cce1 · 2026-12-03T02:30Z · maintainer-class, stays draft

  1. 结论:有条件通过——代码和权限实现成立;合并前需维护者就 Q1、Q2 裁决,并等 CI 测试分片跑完。
  2. 依据:已出账只统计「开票于」不为空的行,费用侧与已批准待开票同条件,工时侧只有已批准(终态)工时单的行会被打标,故 已出账 ≤ 已批准待开票;钉住的 objectql 在汇总回写时同一次写入重算存值列 unbilled_amount,常规路径无陈旧值。
  3. 风险(均不阻断):① 裁决 C 承诺「3b 之前重定规则」,本 PR 未重定就删了文档里的「将会重新审视」;② 成员失去原本可见的 3 个数字;③ 升级后老项目「未出账」为空直到回填,回填命令未在升级库上跑过;④ 同一项目并发「审批工时」和「准备开票」时存值列可能短暂陈旧,下次写入自愈;⑤ 已批准工时单若被改到别的项目,已出账工时留在旧项目(低概率,未实测);⑥ 数据集同义词写了「已开票人工/费用」,与本 PR 定的「已出账≠已开票」相反;⑦ 成员访问列表 403、数据集被拒只做了浏览器走查,无自动化测试;⑧ 成员在视图切换器里可能仍能选到「待出账项目」并得到 403(未实测)。
  4. 类别:维护者类(确认)——改了权限集 project_member。

待维护者裁决

Q1 · 订单上的「回款计划与订单金额不符」(裁决 C 说 3b 前重看)
按工时计费的订单确认时自动生成一条全额回款计划,之后每次「准备开票」再加一条,于是订单常年亮「不符」,那条全额计划一直挂「未回款」,预期回款多算一份订单额。订单的未回款/未开票按订单总额算,不受影响。

  • A 保持现状,只在文档写明。利:不动订单与回款;弊:提示长期失真,预期回款多算,等于默认取消 12-02 的承诺。
  • B 另立订单与回款卡。B-1 每次准备开票冲减那条自动全额计划(减到零即删),计划合计始终等于订单额;B-2 只让「不符」提示忽略开票生成的计划(改动小,但多算仍在)。
  • 建议:B(倾向 B-1),不阻塞本 PR 合并。

Q2 · 项目成员能看到哪些开票数字
合并前成员能看「已批准待开票、可计费人工、可计费费用」;之后仍能看自己工时的计费金额、费率卡和项目「计划收入」。

  • A(卡片原文 / PR 现状)整块 7 个字段对成员隐藏。利:规则简单,与「开票于」已隐藏一致,不会被两数之差推算;弊:收回已有可见性,且「计划收入」仍可见,保密有限。
  • B 成员继续看已批准待开票及两半,只藏已出账/未出账。利:不改现有体验;弊:与卡片验收条件不符,界面半块数字。
  • 建议:A(可逆:删 3 行即恢复);若意图是「成员不看项目的钱」,「计划收入」另立卡。

Evidence: project.object.ts:238-333, billing.actions.ts:91-97, pin objectql index.mjs:32587-32592, 26169-26179, 18220-18230, project-member.profile.ts:97-103, project.dataset.ts:188,197, project.view.ts:74-84, sales-order.extension.ts:128-150, ruling C on #2926 (2026-12-02T11:27Z).

Seat: items ⑥–⑧ go back to the dev as small fixes now; ③ is stated in the changeset. The PR stays a draft until the maintainer rules Q1/Q2 and merges.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:hotcrm@sunhaolin · sunhaolin · session_017xRBcUpajguxop2zMyDN9K

CI on 050cce1: two real failures, both this PR's; fix in progress (2026-12-03T02:32Z)

  • Test shard 1, test/authorization-coverage.test.ts:335: the Projects to Bill view filters and sorts on crm_project.unbilled_amount, which is masked from project_member. This has the same root as review item ⑧. The dev fixes the view; the assertion stays as it is.
  • Test shard 2, test/docs-anchor-links.test.ts:81: projects/index{,.zh-Hans,.zh-Hant}.mdx:74 link ./time-and-expenses#billing, which is not site-absolute.

…hors are site-absolute (#2622)

- project_financials: the Billed Labor and Billed Expenses synonyms read
  已出账人工 / 已出账费用; 已开票 is Order to Cash's Invoiced.
- test/psa-billed.test.ts: the Projects to Bill filter runs as the project
  manager and finance through REST; a project member is refused it (403)
  and lists projects with no billing field; a member aggregating the
  billing measures of project_financials is refused, the PM is answered.
- projects_to_bill declares editInline, as its sibling project lists do
  (view-inline-edit).
- content/docs projects index (three locales): the link to Prepare Billing
  is site-absolute, as docs-anchor-links requires.

Claude-Session: https://claude.ai/code/session_017xRBcUpajguxop2zMyDN9K
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:hotcrm@sunhaolin · sunhaolin · session_017xRBcUpajguxop2zMyDN9K

Q3 · Fable analysis · head e8a9806 · 2026-12-03T03:17Z — the one red check left: test/authorization-coverage.test.ts:335

背景:「待出账项目」列表按「未出账金额」筛选和排序,而该字段对项目成员隐藏;平台对隐藏字段的筛选排序一律 403,仓库测试规定任何视图都不得筛选/排序被隐藏字段。导航入口已对成员隐藏,但视图切换器里成员仍能选到并撞上 403。无论 Q2 选 A 或 B,「未出账」都对成员隐藏,所以这条与 Q2 无关。本 PR 已在「项目总览」仪表盘加了「按项目的开票情况」表(已批准待开票 / 已出账 / 未出账,按未出账从高到低,前 20 条),该仪表盘本就不给成员。

  • A 加成员可读的「有未出账」是/否字段,视图按它筛选。利:列表保留;弊:成员逐个项目知道有没有钱没出账,与「成员看不到」相悖,排序仍要去掉,多一个存值字段。
  • B 去掉筛选排序,成为普通开票列表。利:改动最小;弊:名不副实,成员打开三列为空。
  • C 删视图和导航入口,报告「隐藏期间做不到」。利:最干净,符合卡片「否则说明为什么不行」;弊:若不指明替代,开票人看上去少一个清单。
  • D 改测试承认视图有受众限制。弊:放宽全仓安全护栏,且现有导航 visible 只是界面隐藏,成员照样 403。
  • E(新) 删视图,由仪表盘上已有的「按项目的开票情况」表充当开票人的清单。利:C 的全部好处且功能不丢,成员进不了该仪表盘、聚合被拒已有测试;弊:是前 20 条汇总表,不可行内编辑,项目多时看不全(上限可调)。
  • F(新) 视图加平台 requiredPermissions,新设「可看项目开票」能力发给经理/财务/管理员。利:唯一能在服务端把视图从切换器拿掉的机制;弊:又一次授权变更,仍需改测试,crm.app.ts 已有先例拒绝自设能力。

建议:E——卡片允许「做不到就说明」,清单用途已由同一 PR 的仪表盘表满足,不动护栏、不加授权;若坚持要可操作列表,另立卡走 F。

旁证(未实测):新隐藏的 7 个开票字段没有加入 PSA_COST_FIELDS(src/sales/profiles/_psa-grants.ts:66-81)。按 #2820 的两角色规则,同时持有 project_member 和 finance_controller/system_admin 的人会读不到整个开票块;#2820 为 14 个成本字段补过行和测试(test/two-role-field-rows.test.ts),这 7 个建议同样处理。

Evidence: authorization-coverage.test.ts:295-336 (rule since #488, no exemption); precedent sales-rep.profile.ts:159-171; project.view.ts:74-85; psa.app.ts:60-63; pin liveness/app.json:129 (nav visible is client-side only); projects-overview.dashboard.ts:202-215; psa-billed.test.ts:165-189; pin view.zod.ts:3797-3809 (requiredPermissions); crm.app.ts:36-41.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:hotcrm@sunhaolin · sunhaolin · session_017xRBcUpajguxop2zMyDN9K

Maintainer's rulings in chat, verbatim: 「Q1 选 B,Q2 选 A,Q3 选 E,旁证补上」 · recorded 2026-12-03T03:24Z

Sent back to the dev; the PR stays a draft for the maintainer's merge.

…ill view, billing rows for two roles (#2622)

The maintainer's ruling in chat: 「Q1 选 B,Q2 选 A,Q3 选 E,旁证补上」.

- Q3 E: the projects_to_bill list view, its navigation entry and its
  labels in the four packs are removed. A list view cannot filter or sort
  on Not Yet Billed while project_member masks it (a view that queries a
  masked field breaks for that set's holders, authorization-coverage). The
  list for the people who bill is Projects Overview's Billing by Project
  table, now filtered to unbilled_amount > 0 and widened from 20 to 100
  rows. Manuals, docs site, feature inventory, plan, REQ-0002 and the
  changeset say so.
- Q2 A: the billing block stays hidden from project_member.
- Q1 B: Order to Cash is unchanged; where the docs describe Payment Plan
  Differs after billing they point at hotcrm#2934.
- Two-role rows: PSA_BILLING_FIELDS (_psa-grants.ts), seven read rows,
  carried by finance_controller, system_admin and project_manager, so a
  holder of one of them beside project_member still reads the billing
  block (the #2820 rule the cost fields follow).
- Tests: two-role-field-rows pins the three pairs; psa-billed proves the
  REST filter for the PM and finance without a view, the member refusal,
  and the dashboard table's binding.

Claude-Session: https://claude.ai/code/session_017xRBcUpajguxop2zMyDN9K
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:hotcrm@sunhaolin · sunhaolin · session_017xRBcUpajguxop2zMyDN9K

CI on 38475ee: Test shard 8 is red, and the failure is this PR's (2026-12-03T04:04Z)

test/psa-billed.test.ts › "with Order to Cash disabled the project still reads…" fails with Test timed out in 5000ms. It passes locally. The case disables a module and writes several rows, which takes longer than the default 5 s budget on the CI runner. The fix follows the #2923 precedent (d66957a): a per-test budget on the slow cases, with no global change. The dev is on it.

CI shard 8 on 38475ee timed the Order to Cash disable case out at the
default 5 s (1.5 s locally: a run, then a package disable and enable). As
d66957a did for the flow-quote case, each psa-billed case above 0.5 s
locally gets its own 15_000 budget, with the reason beside it; the
default for the file is unchanged.

Claude-Session: https://claude.ai/code/session_017xRBcUpajguxop2zMyDN9K
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:hotcrm@sunhaolin · sunhaolin · session_017xRBcUpajguxop2zMyDN9K

Head update: 9152b8e, rulings implemented, CI all green (2026-12-03T04:18Z)

  • Q1 → B: Order to Cash is untouched. The docs and the plan now point at Order to Cash: Prepare Billing reduces the order's automatic full-amount payment plan step, so Payment Plan Differs stays truthful #2934.
  • Q2 → A: the 7 billing fields stay hidden from project_member.
  • Q3 → E: the projects_to_bill view and its nav entry are removed. The billers' list is the Projects Overview "Billing by Project" table: filtered to Not Yet Billed > 0, sorted by it, 100 rows. authorization-coverage is unchanged and green.
  • Side finding: PSA_BILLING_FIELDS gives finance_controller, system_admin and project_manager read rows on the 7 fields (feat!: move to ObjectStack 19.0.0-next.2 and protocol 19 #2820 rule). Pinned in two-role-field-rows: red without, green with. Measured over REST: PM+member 7/7, finance+member 7/7, member alone 0/7.
  • Review items ⑥–⑧: zh synonyms are now 已出账; member-denial tests are automated; the switcher 403 is gone with the view.
  • CI timeout: the slow psa-billed cases carry a per-test budget of 15 s, as in d66957a.
  • All 19 checks on 9152b8e finished green, and the PR is mergeable. The full suite also passed locally in 8 shards.

Open for the maintainer (non-blocking):

  1. project_manager was included in the two-role billing rows because the PM bills. The feat!: move to ObjectStack 19.0.0-next.2 and protocol 19 #2820 cost rows named only finance and admin.
  2. Follow-up proposed: the two Billed On fields from step 3a (crm_time_entry / crm_expense.crm_billing_milestone) have no two-role rows yet.

Stays draft with pm:awaiting-merge: the maintainer's merge.

@objectstack-fleet objectstack-fleet Bot added the pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue label Dec 3, 2026
@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review December 3, 2026 07:22
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Dec 3, 2026
Merged via the queue into main with commit b2567dc Dec 3, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pm:awaiting-merge PR only: landing waits on the maintainer's own review and merge (SKILL.md 复核 ②); never on an issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants