feat(procurement): make received_amount a live summary roll-up (#84)#88
Merged
Conversation
`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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
延续 #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_orderlookup 关系上的procurement_receipt.received_value求和:引擎会在每次收货记录 insert/update/delete 时重算。被拒收的收货记录
received_value恒为 0(由rejected_has_zero_value校验保证),所以直接求和即等于已验收总额,无需额外过滤。procurement_order.object.ts:received_amount→Field.summarysrc/data/index.ts:删掉 4 处手写的received_amountseed 值(现由 seed 的收货记录派生)pr_to_po_convert.flow.ts:删掉草稿 PO 上的received_amount: 0hooks/index.ts、procurement_receipt.object.ts、CHARTER.md:更新已过时的"stored field / after-create hook"注释,改为描述实时汇总验证
tsc --noEmit✓、pnpm build✓(4 objects / 50 fields)received_amount = 18000;一个部分收货的 PO 报告 3750 / 7500。影响
纯模板改动,不改 framework。行为等价但去掉了手工维护——收货变化现在会实时反映到 PO 的
received_amount/match_status/is_fully_received。Generated by Claude Code