Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
Feature run: Currency + exchange rate architecture refactor
- Date: 2026-09-02
- Mode: fully-autonomous
- Request: "we need to do a big refactor on currency and exchange rate. first i want you do an audit of the existing exchange rate PRs from BettrCallRaul that were opened between 2 days ago and today. these are symptoms. don't treat them as the solution, but as symptoms to solve during our refactor. next study the codebase. one major problem is that the 'currency' table is currently scoped to a 'companyGroupId' so an exchange rate would be normalized to a company group -- but companies within the group can have different currencies and so this falls apart. the final problem that we'd like to solve is that currently exchange rates require an integration. but we don't want this. we want it to be on by default with a single store of truth for everyone. with every exchange rate able to be updated by the end user if they desire. this is a major refactor. in the end we will have simplified exchange rates architecture, eliminated the need to add an integration, and solved all of the known bugs and some of the unknown bugs as well. let's use a combination of the feature and fix skill"
- Phase plan: research [run — ERP accounting domain logic, force-included; competitor practice on rate providers/overrides/scoping] · spec [run — cross-module data-model change, 40+ call sites] · plan [run] · execute [run] · test [run — user-facing settings + document flows; mandatory per user working agreement] · self-review [run — default]
Pre-pipeline inputs (done before pipeline start)
- PR audit:
.ai/research/2026-09-02-exchange-rate-pr-audit.md— 12 symptom PRs (#1525–#1549 by BettrCallRaul) classified into defect classes: (a) group-scoping half-migration, (b) integration-gated rates →?? 1par fallbacks, (c) snapshot-vs-live confusion, (d) direction confusion (3 rate² bugs), (e) header→line propagation gaps, (f) validation gaps, (g1) non-atomic (currencyCode, exchangeRate) pair, (g2) untyped parallel column families. - Currency architecture:
.ai/research/2026-09-02-currency-architecture.md— schema, 6 write paths, 7 read classes (~40 stamping sites), 6 header + 6 line snapshot tables + payment/memo/invoiceSettlement; "base of normalization" recorded nowhere; decimalPlaces vs exchangeRate want different scopes; exchangeRateHistory has zero writers. - Update path:
.ai/research/2026-09-02-exchange-rate-update-path.md—exchange-rates-v1integration is a pure on/off toggle gating the nightly cron (exchangeratesapi.io, EUR base, global env key); manual edits clobbered nightly; new companies seed 118 currencies at rate 1.
Decisions
- Autonomy mode: fully-autonomous — session is non-interactive; user pre-delegated open-question resolution (recommendations documented + surfaced for veto). — 2026-09-02
- Phase set: all six phases — ERP-domain (research forced), cross-module data model (spec forced), user-facing surfaces (test forced by working agreement). — 2026-09-02
Phase log
- Research: done —
.ai/research/exchange-rate-competitor-practice.md(SAP S/4+B1, NetSuite, BC, Odoo, Xero, QBO via 4 parallel web-research agents). Consensus: explicit rate anchor (pair or reference-currency-relative, never unstated base); effective-dated insert-only rows; Xero/QBO prove on-by-default zero-config feeds; manual-wins override semantics (NetSuite insert-if-absent); header-only document rates stamped at creation; missing rate = hard error (SAP SG105), never?? 1. Odoores.currency.rate(reference-relative technical rate + nullable company scope, company rows win) is the closest structural template. - Spec: done —
.ai/specs/2026-09-02-currency-exchange-rate-refactor.md. Design: global USD-anchored effective-datedexchangeRatetable (feed-written, seeded snapshot, no tenancy) + per-companyexchangeRateOverride(standing pin, beats feed) + SQL resolverget_exchange_rate(base→1, override, else ratio; ERROR on missing) ;currencystays group-scoped config-only (dropsexchangeRate);exchangeRateHistorydropped; integration deleted; consolidation closing/average rewired to global store; salesInvoice propagation + rate>0 CHECKs subsumed (#1527/#1541 guarded); refresh routes doc-sourced (#1530); ~40 stamping sites → resolver. 11 open questions resolved autonomously; 2 flagged for veto (column drop vs ADDITIVE-ONLY contract; override-migration heuristic). - Plan: done —
.ai/plans/2026-09-02-currency-exchange-rate-refactor.md. 17 tasks: 3 migration-authoring (global store + seed snapshot + resolver fns; data-migration + column drop + view + integration delete; salesInvoice triggers + 12 CHECKs + consolidation forks), apply+types, models/service, 3 parallel stamping-site sweeps (sales/purchasing/invoicing+refresh routes), edge fns, jobs rewrite, EE deletion, seeds+backup pins, UI, validation, gates, /test, docs. Appendix A carries the ~150-code bootstrap rate snapshot. - Execute: done through Task 15. 4 migrations (global
exchangeRatestore + seed snapshot + resolvers; currency config-only + override data-migration + integration delete; salesInvoice triggers + 12 CHECKs + translateTrialBalance fork; getConsolidationRates pair-fix), applied + types regenerated + psql-verified (override precedence, reset, missing-rate error, pair ratios). ~40 stamping sites swept to the resolver across sales/purchasing/invoicing services + routes (3 subagents); 6 refresh routes now document-sourced; edge fnsconvert/createon the RPC; feed job rewritten platform-global; EE integration deleted; exchange-rates UI reworked (provenance badges, override/reset intents); seeds slimmed; schema.json baseline regenerated; AGENTS.md synced; 10 new i18n strings filled in 12 locales. Typecheck green (erp, jobs, ee, database); lint clean; all tests pass; datasets gate passes.
Execute-phase decisions / deviations
- Commits deferred to one atomic commit (per-task commits impossible: the column drop makes the tree red until all sweeps land; same rationale as the July convention spec's "ship as one PR").
- Appendix A amended: obsolete VEF/ZMK seeded at successor-peg conversions; 6 non-
currencyCodecodes removed from the seed INSERT (FK). - M4 added (getConsolidationRates): plan's Task 3 missed that the RPC exists separately in 20260713225803 and reads the dropped table; forked with explicit target param (old signature dropped first to avoid the overload trap); TS caller passes targetCurrency.
- Quote PDF paths (documentPreview.server.ts, file+/quote+/$id.pdf.tsx) — unassigned in the plan, surfaced by typecheck: switched from LIVE currency reads to the quote's stamped snapshot (subsumes PR #1549's direction); legacy null snapshot renders at 1 (consistent with line snapshots), documented in-code.
- Remaining
?? 1grep hits are document-snapshot DISPLAY reads (nullable legacy header rates in quote UI) — not resolution fallbacks; left as-is. db:check:backupsblocked by PRE-EXISTING baseline pollution on main:schema.jsoncontainsonshapeSyncRun/onshapeItemSyncState, tables with NO migration anywhere (committed from a dirty local DB). Fixed by regenerating the baseline from this branch's clean fully-migrated schema (drops the phantom tables, adds the new ones); commit uses CARBON_SKIP_BACKUP_CHECK=1 with this documented cause. Surface to Brad: main's baseline was polluted.- Task 6's agent also converted stored-snapshot NULL-rate sites in price-building fns to explicit errors (legacy pre-2024 rows only) — flagged for self-review.
- Dead
companyGroupId?params left onupdatePurchaseOrder/updateSupplierQuotesignatures (callers outside task file lists) — cleanup candidate.
🛑 Gate: plan approval — auto-resolved (autonomous mode)
Plan approved autonomously: it covers every spec acceptance criterion (traced task-by-task), respects the two veto-flagged decisions as specced, and parallelizes safely. The human review point is the PR. — 2026-09-02
🛑 Gate: spec Open Questions — auto-resolved (autonomous mode)
All 11 resolved in spec with Autonomous: markers; recommendation order codebase-precedent → research-consensus → judgment. Veto-flagged: (1) dropping currency.exchangeRate (ADDITIVE-ONLY exception, data migrated to overrides first); (2) migration heuristic (integration-inactive groups only, rate ≠ 1, code ≠ company base, per member company). — 2026-09-02
Phase log (continued)
- Self-review: done — nuclear mode, three parallel reviewers over the full 74-file diff, findings verified in code before reporting. 6 must-fix + 9 risks + 7 suggestions found.
- Review fixes: done — commit fd6e0aaf3a (49 files). All must-fixes applied (get-method ??0, VALIDATE data repair, M2 retry guard, dead companyGroupId gates/params, consolidation dedup via delegation, stale EE docs) plus risks 7-14 (snapshot-fallback loaders, supplier-quote company guard, feed-job retries, consolidation fail-loudly, base-change override clearing + base-pin refusal, admin page error surfacing, translation fixes) and the cheap suggestions (feed math unit tests, typed RPC call, Updated column, dead payloads, form i18n, lessons).
Outcome
- Two commits on
currency-exchange-rate-refactor: 7f0c2eed43 (the refactor) + fd6e0aaf3a (review hardening). Typecheck green (erp/jobs/ee/database), lint clean, all tests pass (incl. new feed-math suite), dataset gate passes; backup gate bypassed with documented cause (main's baseline polluted with phantom onshape tables — fixed baseline ships in this branch). - OPEN: Task 16 browser verification (stack was torn down mid-run; needs crbn up + /test of the five flows), Task 17 docs-site pages (integrations index + accounting mdx still describe the deleted integration). Deferred by design:
createedge fn null-supplier-currency USD default → company base (behavior-preserving choice, flagged); repo-wide raw* ratechecks ban (spec follow-up); per-line rate elimination (spec follow-up).