feat(accounting): intercompany netting workbench — data model (#1058)#1239
feat(accounting): intercompany netting workbench — data model (#1058)#1239carbon-agent wants to merge 1 commit into
Conversation
Workstream 4 (netting) data-model foundation, stacked on the tolerance/FX matching phase (#1224). Schema only, deliberately ahead of the consuming RPCs/service/UI: those reference the new tables in TypeScript and require regenerated @carbon/database types (a running local stack the build env lacks). - accountDefault.intercompanyNettingAccount (by id) + per-group "1135 Intercompany Netting Clearing" current-asset account seeded (sibling of 1130, parent resolved by isGroup+name+class) and backfilled; left NULLABLE so the settlement path raises rather than posting to the wrong clearing account. - intercompanyNettingStatement + intercompanyNettingStatementLine — group-level, single-column PK + companyGroupId/company columns per the intercompanyTransaction precedent (currencyCode a bare TEXT with no FK, same reason). - payment.nettingStatementId back-reference + partial index. - ICNS-%{yyyy}- readable sequence backfilled for existing companies + seeded for new. - RLS mirrors the intercompanyTransaction source-OR-target shape (accounting_create/update/delete); line policies gate on the parent statement's two companies via EXISTS, fully-qualifying the line's statementId to disambiguate from the statement's readable-number column of the same name. Follow-up (needs the stack for type regen + posting verification): statement lifecycle RPCs + settlement (rides the existing post-payment edge function, not a self-contained RPC), the workbench UI, and workstream 3 (document mirroring). Tracking spec: .ai/specs/2026-07-04-intercompany-maturity.md Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
What
Workstream 4 (netting) data-model foundation for intercompany maturity (issue #1058), from
.ai/specs/2026-07-04-intercompany-maturity.md.Stacked on #1224 (tolerance + FX matching). Base is
feature/intercompany-maturity-matching; GitHub will retarget tomainwhen #1224 merges. Review #1224 first.Scope: schema only, on purpose
The consuming statement-lifecycle RPCs, accounting service functions, and workbench UI reference these new tables/columns in TypeScript, which requires regenerating
packages/database/src/types.tsagainst a migrated local DB. The build environment for this branch has no running stack, and repo policy is to not rebuild the DB autonomously (AGENTS.md: "Never rebuild the database to test changes — wait for the user"). So this PR lands the migration + seed only — every line is SQL or pure seed data, grounded in existing precedent — and the consuming code follows once types can be regenerated. This mirrors how #1224 shipped matching without new TS-referenced DB objects.Migration
20260725143012_intercompany-netting-foundation.sqlaccountDefault.intercompanyNettingAccount(FK toaccount.id, by id per the control-account lesson) + a per-group1135 Intercompany Netting Clearingcurrent-asset account, seeded (sibling of 1130, parent resolved byisGroup+name+class, never by number) and backfilled. Left NULLABLE so an unset account makes the future settlement path raise, rather than posting to the wrong clearing account.intercompanyNettingStatement+intercompanyNettingStatementLine— group-level, so they follow theintercompanyTransactionprecedent (single-column PK,companyGroupId+ explicit company columns,currencyCodea bare TEXT with no FK because a two-company row can't reference the per-companycurrency(code, companyId)table).payment.nettingStatementIdback-reference + partial index (settlement audit trail).ICNS-%{yyyy}-readable sequence backfilled for existing companies + seeded inseed.data.tsfor new ones.intercompanyTransactionsource-OR-target shape (accounting_create/update/delete). Line policies gate on the parent statement's two companies viaEXISTS, fully-qualifying the line'sstatementIdto disambiguate it from the statement's readable-number column of the same name (a bug I caught and fixed during review).Verification
pnpm exec biome checkonseed.data.ts— clean.pnpm exec turbo run typecheck --filter=@carbon/database— passes.db:migrate'd here (no local stack); the SQL is grounded line-for-line in20260724100357(the matching migration) and20260630093809(AR/AP payments). Please apply + regenerate types on a real stack before merge — that step also produces thetypes.tsupdate every DB PR carries.Follow-up (still needed for #1058)
createNettingStatement/ propose / agree / cancel) + settlement. Design note: settlement should ride the existingpost-paymentedge function (stage Draftpayment+invoiceSettlementrows, invoke per company) rather than a self-containedsettleNettingStatementRPC as the spec's RPC sketch implied — posting lives in the edge function, not an RPC. Resolve that gap when building settlement.Tracking spec:
.ai/specs/2026-07-04-intercompany-maturity.md🤖 Generated with Claude Code