Skip to content

feat(procurement): make received_amount a live summary roll-up (#84)#88

Merged
os-zhuang merged 1 commit into
mainfrom
claude/live-rollups-procurement
Jul 19, 2026
Merged

feat(procurement): make received_amount a live summary roll-up (#84)#88
os-zhuang merged 1 commit into
mainfrom
claude/live-rollups-procurement

Conversation

@os-zhuang

Copy link
Copy Markdown
Contributor

背景

延续 #87(expense 的 total_amount 已改为原生 summary),本 PR 把 procurement 模板里最后一个"手工维护的跨对象汇总字段" procurement_order.received_amount 也改造成实时汇总。

在此之前 received_amount 是一个手工维护的 Field.currency:seed 和 PR→PO 转换 flow 里都硬写它的值,而收货(goods receipt)到货时没有任何自动重算——本该做这件事的 receipt→PO 汇总 hook 会因嵌套跨对象写入把 QuickJS 沙箱写崩(framework#1867)。该 bug 已修复,这个变通做法不再需要。

改动

received_amount 改为原生 Field.summary,对 purchase_order lookup 关系上的 procurement_receipt.received_value 求和:

received_amount: Field.summary({
  label: 'Received Amount',
  group: 'commercial',
  summaryOperations: {
    object: 'procurement_receipt',
    field: 'received_value',
    function: 'sum',
    relationshipField: 'purchase_order',
  },
});

引擎会在每次收货记录 insert/update/delete 时重算。被拒收的收货记录 received_value 恒为 0(由 rejected_has_zero_value 校验保证),所以直接求和即等于已验收总额,无需额外过滤。

  • procurement_order.object.tsreceived_amountField.summary
  • src/data/index.ts:删掉 4 处手写的 received_amount seed 值(现由 seed 的收货记录派生)
  • pr_to_po_convert.flow.ts:删掉草稿 PO 上的 received_amount: 0
  • hooks/index.tsprocurement_receipt.object.tsCHARTER.md:更新已过时的"stored field / after-create hook"注释,改为描述实时汇总

验证

  • tsc --noEmit ✓、pnpm build ✓(4 objects / 50 fields)
  • 全新 dev server 启动 boot 验证:seed 0 错误;汇总值与收货记录精确吻合——例如一个带单张 $18k 验收收货的 PO 报告 received_amount = 18000;一个部分收货的 PO 报告 3750 / 7500。

影响

纯模板改动,不改 framework。行为等价但去掉了手工维护——收货变化现在会实时反映到 PO 的 received_amount / match_status / is_fully_received


Generated by Claude Code

`procurement_order.received_amount` was a hand-maintained stored currency
field: the seed and the PR→PO conversion flow set it explicitly, and there
was no automatic recompute when goods receipts arrived (the receipt→PO
rollup hook that would have done so crashed the QuickJS sandbox on the
nested cross-object write — framework#1867). That workaround is no longer
needed now the sandbox bug is fixed.

Convert `received_amount` to a native `Field.summary` that sums
`procurement_receipt.received_value` over the `purchase_order` lookup. The
engine recomputes it on every receipt insert/update/delete. Rejected
receipts already carry `received_value` 0 (enforced by the
`rejected_has_zero_value` validation), so a plain sum equals the accepted
total — no filtering needed.

- procurement_order.object.ts: received_amount → Field.summary
- src/data/index.ts: drop the 4 hand-set received_amount seed values
  (now derived from the seeded receipts)
- pr_to_po_convert.flow.ts: drop received_amount: 0 from the drafted PO
- hooks/index.ts, procurement_receipt.object.ts, CHARTER.md: refresh the
  now-stale "stored field / after-create hook" notes to describe the
  live summary

Boot-verified against a fresh dev server: seeds load with 0 errors and the
rolled-up totals match the receipts exactly (e.g. a PO with one $18k
accepted receipt reports received_amount 18000; a partial PO reports 3750
of 7500).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BZguyAaQbyUpwMZ2gMLaAP
@os-zhuang
os-zhuang merged commit cb1112e into main Jul 19, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants