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.
Exchange-Rate PR Audit — BettrCallRaul, 2026-08-31..2026-09-02
Audit of 12 currency/exchange-rate bug-fix PRs, treated as symptoms of the architecture
about to be refactored: currency scoped to companyGroupId (while companies in a group
can have different base currencies), and exchange rates populated only by an integration
(so rates are missing/stale/1.0 by default).
Root-cause classes:
- (a) currency/rates normalized to
companyGroupIdwhile group members have different base currencies - (b) rates only exist via integration → missing/stale/1.0 defaults
- (c) document-level
exchangeRatesnapshot vs live currency-table rate confusion - (d) direction confusion (multiply vs divide; rate is foreign-per-base)
- (e) missing rate propagation (header→line, document→PDF/email/sync payload)
- (f) validation gaps (0/negative/null/unchecked errors)
- (g) other — two named recurring "others": (g1)
(currencyCode, exchangeRate)not treated as an atomic pair; (g2) dual parallel column families (baseunitPricevsconverted*/supplier*generated mirrors) with no type-level distinction, making wrong-column selection invisible
Summary table
| PR | State | Symptom | Root-cause class | Recommendation |
|---|---|---|---|---|
| #1549 | OPEN | Reprinting a quote after the rate cron ran mixed two rates on one PDF: lines at the quote's snapshot, header shipping/charges at today's live rate; total reconciled to neither | (c) primary; (b) enabling (let exchangeRate = 1 + live lookup) |
Merge first; refactor subsumes under a "document snapshot always wins on documents" contract |
| #1548 | OPEN | Sales-order and PO emails printed the BASE unit price labelled with the document currency; qty × unit ≠ line total on the same row, sent to customers/suppliers | (e) primary; (g2) enabling | Merge first (wrong numbers leaving the building); refactor subsumes if column families get typed |
| #1547 | OPEN | EUR invoice on USD-base company synced to Xero/Rillet with USD amounts declared as EUR; provider revenue/AR/FX all wrong by the rate | (e) primary; (g2) enabling; (d) appeared and was reverted mid-branch (CurrencyRate inversion) | Merge first; refactor must generalize — PR itself names the same defect still open in Xero SO/PO, QBO invoice/bill/PO/payment, Rillet bill |
| #1544 | OPEN | Foreign-currency receipts with header shipping capitalised cost wrong by rate² into costLedger + weighted-average item cost (multiply instead of divide) |
(d) | Merge first (irreversible valuation corruption); refactor subsumes via to-base/from-base helpers |
| #1543 | OPEN | Supplier part prices prefilled into PO/invoice lines wrong by rate² (SEK 1,290 instead of SEK 162,980) — divided base→supplier where multiply was correct, then divided again on price breaks | (d) primary; (g2) enabling (supplierPart price columns have no currency column — implicitly base) |
Merge first; refactor subsumes by giving stored prices an explicit currency |
| #1542 | OPEN | Group with companies on different base currencies + active integrations: nightly job rebased the SHARED currency rows once per company; last writer won, rates flipped nightly | (a) primary; (b) is the delivery mechanism | Refactor supersedes — this enforces exactly the invariant (one base per group) the refactor must decide; merge only as a stopgap if the refactor is weeks out |
| #1541 | OPEN | A typed/imported 0 or negative rate saved silently; 0 zeroes every sales converted* column, purchasing substitutes par |
(f) | Merge first, refactor keeps — DB CHECKs on 12 document tables survive any re-architecture |
| #1532 | OPEN | Sales invoice summary multiplied the base-stored header shipping by the rate on the BASE side, overstating the base total | (d) (converted a value already in base); (g2) enabling | Merge first; one line, independent of everything else |
| #1530 | OPEN | Crafted POST to any of six *.exchange-rate routes stamps another currency's rate onto a document that keeps its own code (SEK rate on a USD invoice) |
(g1) primary; (f) (trusting client input); (c) adjacent (defines "refresh" semantics) | Merge after #1526 (stacked on its resolveCurrencyAndRate); refactor subsumes the resolver |
| #1527 | OPEN | Refreshing a sales invoice rate updated the header only; lines (and their converted* columns) kept stale rates; PDF total existed at no rate; new lines stranded at DEFAULT 1 |
(e) (header→line cascade missing on 1 of 6 documents) | Merge first; refactor may supersede if line-level rates are eliminated — flag "rate 1 = unset" tradeoff as a design input |
| #1526 | OPEN | Six bulk-update routes set currencyCode without exchangeRate: party reassignment kept rate 1 (foreign customer quoted at par); the currencyCode case fell through to the generic setter |
(g1) primary; (b) (missing rate → fabricate 1); (f) | Merge first; refactor absorbs resolveCurrencyAndRate as the seed of the new currency service |
| #1525 | MERGED | RFQ→Quote for a foreign-currency customer silently quoted at par: currency lookup still filtered on the DROPPED companyId column, error unchecked, ?? 1 |
(a) primary; (f) (unchecked error); (b) (default-to-1) | Merged. Refactor should sweep for remaining stale per-company assumptions on group-scoped tables |
Per-PR detail
#1549 — fix(sales): print the quote PDF at the quote's own exchange rate (OPEN)
- Symptom: One quote PDF mixed two exchange rates. Line amounts render from
converted*generated columns (baked at the quote's stored rate); header shipping and add-on charges were converted at the LIVE currency-table rate. The moment the daily cron moved the currency, the total reconciled to neither, and reprinting an old quote silently changed it. - Proximate cause:
apps/erp/app/routes/file+/quote+/$id[.]pdf.tsxinitializedlet exchangeRate = 1and overwrote it fromgetCurrencyByCode(...)instead of readingquote.data.exchangeRate. Fix: rate comes from the quote; the currency row is read only fordecimalPlaces. - Root cause class: (c) snapshot-vs-live confusion. (b) is the enabling condition —
a live-table lookup only exists because the rate wasn't trusted to be on the document.
PR notes the quote PDF was the only
file+route passing a scalar rate (16 audited). - Fix shape: Point patch, correct direction. Merge first. The refactor should encode the contract this patch implies: on a document surface, the document's snapshot rate ALWAYS wins; the currency table is for defaults at creation and metadata (decimals).
- Files:
apps/erp/app/routes/file+/quote+/$id[.]pdf.tsx(+6/−4).
#1548 — fix(documents): email the line unit price in the currency the email is formatted in (OPEN)
- Symptom:
SalesOrderEmailprintedsalesOrderLine.unitPrice(BASE) under the customer's currency label while the adjacent line total summedconvertedUnitPrice— qty × unit price ≠ total on the same row.PurchaseOrderEmailprinted the generated baseunitPriceunder the supplier's currency while its total summedsupplierUnitPrice. These are externally sent. - Proximate cause: The formatter's currency was fixed in all three emails at some point;
the amount column was fixed in only one (
SalesInvoiceEmailalready usedconvertedUnitPrice). Fix: each email formats the same column its own total helper sums (convertedUnitPrice/supplierUnitPrice), plus switches unit prices from the money formatter to a rate formatter (per the numeric-precision rate-vs-money kinds), and tests!= nullinstead of falsiness so zero-priced lines print. - Root cause class: (e) document→email payload propagation, enabled by (g2) — two parallel column families with identical types make wrong-column picks silent.
- Fix shape: Point patch. Merge first. The refactor subsumes only if it types the column families (e.g. branded Money vs Money at select time) or collapses them.
- Files:
packages/documents/src/email/PurchaseOrderEmail.tsx,SalesOrderEmail.tsx,SalesInvoiceEmail.tsx(+42/−7).
#1547 — fix(accounting): push AR invoice amounts in the currency the payload declares (OPEN)
- Symptom: Foreign-currency AR invoices synced to Xero and Rillet with base-currency
line amounts under the document's
CurrencyCode— a EUR invoice on a USD-base company ships USD numbers labelled EUR; provider revenue, AR balance and realised FX are wrong by the rate. - Proximate cause: Both syncers selected/pushed
unitPrice(base). Fix selectsconvertedUnitPricewith fallback tounitPricewhen null (base-currency invoices). Notably, an earlier commit on the same branch ALSO inverted Xero'sCurrencyRateon a wrong premise and was reverted — Xero'sCurrencyRateis foreign-per-base, same as Carbon's; it passes through unchanged, and is omitted (not 1) on base-currency invoices. - Root cause class: (e) document→sync payload, enabled by (g2). The reverted inversion is a live demonstration of (d) — even the fixer got the direction wrong once.
- Fix shape: Point patch + unit tests (6/6 Xero invoice suite, 3 new FX cases). Merge
first, but the PR itself documents the same defect still open in: Xero sales-order and
purchase-order pushes, QuickBooks invoice/bill/PO/payment mappings, Rillet bill. QBO's
ExchangeRategenuinely IS base-per-foreign and is currently written un-inverted. The refactor must define ONE payload contract ("every amount on a payload is in the currency the payload declares; each provider adapter owns its rate direction") rather than letting each entity syncer re-derive it. Not verified against a live Xero org (no sandbox). - Files:
packages/ee/src/accounting/core/models.ts,providers/rillet/entities/invoice.ts,providers/xero/entities/invoice.ts(+ tests) (+123/−5).
#1544 — fix(inventory): divide receipt header shipping to base, don't multiply (OPEN)
- Symptom: Every foreign-currency PO receipt carrying header shipping capitalised the
wrong number by rate² — weighted across receipt lines into the cost-ledger layer value,
per-piece cost, and Inventory/GR-IR journal, dragging weighted-average item cost with it.
No later journal correction repairs
costLedger. - Proximate cause:
post-receipt/index.ts:623computedsupplierShippingCost * exchangeRate; supplier→base is DIVIDE (rate is foreign-per-base). The codebase already knew:post-purchase-invoice/index.ts:559divides with an explanatory comment, and migration20260702061504is literally titled "Fix supplierShippingCost currency conversion: divide, not multiply" — it fixed the views but not this edge function. - Root cause class: (d). Third occurrence of the exact same expression bug in the codebase's history — direction is re-derived at every call site.
- Fix shape: Point patch (also hardens
?? 1to|| 1against rate 0). Merge first — this is active valuation corruption. Refactor supersedes the PATTERN (atoBase()/fromBase()helper pair so no call site ever writes* rateor/ rateraw) but not this fix. - Files:
packages/database/supabase/functions/post-receipt/index.ts(+9/−2).
#1543 — fix(purchasing): convert supplier part prices to the supplier's currency, not away from it (OPEN)
- Symptom: Adding a supplier part to a foreign-currency PO/purchase invoice prefilled a unit price wrong by rate² (verified: SEK 1,290.04 where SEK 162,980 was correct — 126× understatement). The generated base column then derives from the wrong supplier price, so receiving creates cost layers at the wrong magnitude.
- Proximate cause:
supplierPart.unitPrice/supplierPartPrice.unitPriceare stored in BASE (no currency column on either table). The target fieldsupplierUnitPriceis supplier-currency, so base→supplier is MULTIPLY; both line forms divided, andresolveSupplierPricedivided AGAIN on the price-break path. Fix:resolveSupplierPricetakes base inputs, returns supplier-currency output, callers hand it raw base; thefallbackUnitPriceinitializer (seeded from a supplier-currency value into a base-meaning field) now divides to base explicitly. - Root cause class: (d), enabled by (g2) — a price table whose currency is implicit (base by convention, no column) guarantees somebody converts the wrong way.
- Fix shape: Point patch that also documents the contract in
resolveSupplierPrice's JSDoc — a small step toward architecture. Merge first. The refactor should give supplier price rows an explicit currency (or an explicit "always base" branded type). - Files:
apps/erp/app/modules/shared/shared.service.ts(shared helper — check for other callers),purchasing/ui/PurchaseOrder/PurchaseOrderLineForm.tsx,invoicing/ui/PurchaseInvoice/PurchaseInvoiceLineForm.tsx(+30/−14).
#1542 — fix(jobs): rebase exchange rates once per company group, not once per company (OPEN)
- Symptom: A company group whose members use different base currencies, with the
exchange-rate integration active on more than one member: the nightly job rebased the
SHARED group-scoped
currencyrows once per company, each overwriting the last. Rates flipped every night; the same document's converted totals changed day to day. - Proximate cause:
currencyis group-scoped (20260228023426) butcompanyIntegrationis company-scoped; the job iterated integrations and rebased to each company's ownbaseCurrencyCode. Fix: group active integrations bycompanyGroupId, resolve the base once, rebase once, write once; REFUSE (log + throw after healthy groups complete) when a group's members disagree on base currency. Also: warns on feed-omitted currencies (silent staleness), setsupdatedBy. - Root cause class: (a) — this is the purest expression of the architectural flaw: nothing in the schema records a group-level base currency, yet the shared rate rows can only express one. (b) is the delivery mechanism (rates only move when the integration job runs). The PR itself states: "That assumption was just never enforced where the rates are written."
- Fix shape: Half-architecture: it enforces one-base-per-group by refusal at ONE writer,
but the invariant remains unrecorded in the schema. The refactor supersedes this —
whichever way the refactor goes (per-company currency rows, or a schema-level group base
currency), this job gets rewritten. Merge only as a stopgap if the refactor is weeks out;
if merged, note its refusal policy (throw after healthy groups) is temporary behavior the
refactor must consciously keep or replace. Not executed end-to-end (needs
EXCHANGE_RATES_API_KEY+ live provider); decision logic exercised against the real schema. - Files:
packages/jobs/src/inngest/functions/scheduled/update-exchange-rates.ts(+99/−39).
#1541 — fix(accounting): refuse a non-positive exchange rate at every layer (OPEN)
- Symptom: A zero (or negative) exchange rate could be typed or imported and saved
silently. Zero zeroes every sales
converted*generated column (no zero-guard); purchasing's columns substitute 1, silently pricing a foreign document at par. - Proximate cause:
currencyhas hadCHECK ("exchangeRate" > 0)since 2023, andpayment/memosince 2026-06 — but all 12 document tables were missed. The zod schema said.min(0)("Rate is required"), and the form'sminValue={0}CLAMPED a typed 0 to the step (0.00001) on blur instead of refusing. Fix: CHECK on all 12 tables (> 0 AND <> 'NaN', NULL-tolerant where nullable, added NOT VALID + VALIDATE to avoid write-blocking locks),.positive()in zod,minValueunset for foreign currencies. NaN excluded explicitly because Postgres orders NaN above all finite values so> 0alone accepts it. - Root cause class: (f). NULL deliberately left alone ("no rate set" is a different condition — a data decision for the refactor, not a schema one).
- Fix shape: The most durable of the twelve — DB constraints survive any
re-architecture. Merge first; the refactor keeps it. Interaction: its migration
(
20260901161207) validatessalesInvoiceLine.exchangeRate > 0AFTER #1527's backfill migration (20260901134416) by timestamp order — fine if both merge, but if #1527 is dropped, verify no NULL/zero line rates exist before VALIDATE. - Files: migration
20260901161207_exchange-rate-positive-constraint.sql,apps/erp/app/modules/accounting/accounting.models.ts,accounting/ui/ExchangeRates/ExchangeRateForm.tsx(+119/−4).
#1532 — fix(invoicing): stop converting the base-currency shipping on the invoice summary (OPEN)
- Symptom: Sales invoice summary's BASE-side shipping figure (and base total) was the stored base amount multiplied by the exchange rate — base total overstated (verified: €11,240 rendered where €1,000 was stored; total off by 10,240).
- Proximate cause:
SalesInvoiceSummarykeeps two parallel families (base from raw columns, customer-facing fromconverted*); header shipping was computed identically — multiplied — in BOTH.salesInvoiceShipment.shippingCostis stored in base (thesalesInvoicesview adds it straight onto the base subtotal), so only the customer figure should convert. The purchasing sibling already did the mirror-image correctly. - Root cause class: (d) (converted a value that was already in the target currency), enabled by (g2).
- Fix shape: One-line point patch, explicitly independent of #1527 and the rest (no shared files). Merge first.
- Files:
apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceSummary.tsx(+5/−3).
#1530 — fix(accounting): take the refresh rate from the document, not the request (OPEN)
- Symptom: The six
*.exchange-raterefresh routes readcurrencyCodefrom the posted form, looked up THAT currency's rate, and wrote onlyexchangeRate— a crafted POST could stamp SEK's 11.24 onto a USD invoice that keeps its USD code, mispricing every line viaconverted*. (The UI always posts the document's own code, so in practice it behaved as a refresh — the parameter carried no information the server didn't have.) - Proximate cause: Client-supplied currency trusted; code/rate pair splittable by
construction. Fix: read the currency from the document (already loaded for the locked
check), stop parsing the form entirely, resolve through
resolveCurrencyAndRateso a refresh can't install a zero/missing rate. - Root cause class: (g1) pair atomicity, with (f) (trusting client input) and a (c) flavor — these routes are the ONE sanctioned place a live table rate overwrites a document snapshot, and this PR pins down that semantic.
- Fix shape: Point patch stacked on #1526 (uses its
resolveCurrencyAndRate; branch needs retargeting to main once #1526 merges). Merge second. Refactor subsumes along with #1526's resolver. Post-fix runtime re-test of the SEK-onto-USD POST was not completed (browser extension disconnected); pre-fix repro was confirmed. - Files: six routes
apps/erp/app/routes/x+/{purchase-invoice,purchase-order,quote,sales-invoice,sales-order,supplier-quote}+/*.exchange-rate.tsx(+60/−48).
#1527 — fix(invoicing): cascade the sales invoice exchange rate to its lines (OPEN)
- Symptom:
salesInvoicewas the only rate-bearing header (of six) with NO header→line cascade. Refreshing the rate or changing currency updated the header alone; lines — and everyconverted*column generated off them — stayed at creation-time rates. The PDF summed lines at line rates and header shipping at the header rate: a total that exists at no exchange rate. A line added after a rate change was stranded at the DEFAULT of 1. - Proximate cause: quote/salesOrder cascade via event interceptors; purchaseOrder/
purchaseInvoice/supplierQuote via
AFTER UPDATE OFtriggers; salesInvoice had neither. Fix (migration only): backfill drifted lines,AFTER UPDATE OF "exchangeRate"cascade trigger,BEFORE INSERTinherit trigger — mirroring the purchaseInvoice pair exactly. - Root cause class: (e) header→line propagation gap. Underlying design smell for the
refactor: lines carry their OWN
exchangeRateat all, requiring 6 documents × 2 triggers of glue, and via 2 different mechanisms (interceptors vs triggers). - Fix shape: Point patch consistent with existing architecture; verified end-to-end locally. Merge first. Known tradeoff inherited on purpose: the insert trigger treats rate 1 as "unset", so a line can never deliberately hold rate 1 on a document whose header differs — the refactor should kill this ambiguity (NULL = unset, or drop line rates).
- Files: migration
20260901134416_sales-invoice-rate-cascade.sql(+61/−0).
#1526 — fix(accounting): never write a document currency without its exchange rate (OPEN)
- Symptom: Six bulk-update routes could set
currencyCodeand leaveexchangeRatebehind. Two paths: (1) party reassignment — quote/supplier-quote adopted the new customer's/supplier's currency and never touched the rate, so a quote reassigned to a foreign-currency customer kept rate 1 and every line stayed at the base price (and the cascade'sIS DISTINCT FROMguard never fired since the rate value didn't change); (2) thecurrencyCodecase falling through to the generic[field]: valuesetter in all six routes. - Proximate cause: Code and rate written independently, with
exchangeRate: currency.data?.exchangeRate ?? 1fabricating par when the lookup found nothing. Fix: newresolveCurrencyAndRate(client, companyGroupId, currencyCode)inaccounting.ee.service.tsresolves the pair together or refuses (also refuses 0, negative, Infinity), and stampsexchangeRateUpdatedAtso a set rate is distinguishable from never-set. Behaviour change: setting a currency with no configured rate now errors instead of silently writing rate 1 — unreachable via UI, a guard for CSV/API paths. - Root cause class: (g1) pair atomicity (the PR literally says "one value pair" —
same doctrine as the taxPercent/amount pair in the numeric-precision rule), with (b)
as the reason lookups come back empty (rates exist only where an integration or manual
entry put them) and (f) for the
?? 1fallback. - Fix shape: The most architectural of the app-layer PRs —
resolveCurrencyAndRateis a single resolution point the refactor should absorb as the seed of its currency service (and extend to document creation paths, which still resolve independently). Merge first; #1530 stacks on it. - Files:
apps/erp/app/modules/accounting/accounting.ee.service.ts, six routesapps/erp/app/routes/x+/{purchase-invoice,purchase-order,quote,sales-invoice,sales-order,supplier-quote}+/update.tsx(+300/−144).
#1525 — fix(accounting): resolve quote currency by company group, not dropped companyId (MERGED)
- Symptom: Every Sales RFQ → Quote conversion for a foreign-currency customer produced a quote at rate 1 (par), silently.
- Proximate cause:
convert/index.tsstill filteredcurrencyoncompanyId— a column DROPPED on 2026-02-28 when the table moved to group scoping. PostgREST rejected the filter, the error was never checked, and?? 1wrote par. Fix: filter oncompanyGroupId(matchingcreate/index.ts), throw on lookup failure for non-base currencies (base is exempt — 1 is correct there by definition). - Root cause class: (a) — the group-scoping migration left a stale consumer behind
for six months; (f) unchecked PostgREST error; (b)-flavored
?? 1default. The PR swept the other two tables that moved in the same migration (account,accountCategory) — no other stale filters found. - Fix shape: Point patch, already merged and verified locally. For the refactor: this is
the canary — any re-scoping of
currencyMUST include a sweep of every consumer (PostgREST errors on dropped-column filters are silent to callers that don't check.error), ideally plus a conformance check. - Files:
packages/database/supabase/functions/convert/index.ts(+7/−1).
Patterns across PRs
Count per architectural suspect (primary / including secondary)
| Suspect | Primary | Incl. secondary | PRs |
|---|---|---|---|
| (a) group-scoping vs per-company base | 2 | 2 | #1542, #1525 |
| (b) integration-only rates → missing/1.0 defaults | 0 | 4 | #1526, #1525, #1549, #1542 (delivery mechanism) |
| (c) snapshot vs live rate | 1 | 2 | #1549; #1530 (defines refresh semantics) |
| (d) direction confusion (×/÷) | 3 | 4 | #1544, #1543, #1532; #1547 (reverted mid-branch) |
| (e) missing propagation (header→line, doc→PDF/email/sync) | 3 | 3 | #1527, #1548, #1547 |
| (f) validation gaps | 1 | 5 | #1541; #1526, #1530, #1525, #1542 (silent overwrite) |
| (g1) code/rate pair atomicity | 2 | 3 | #1526, #1530; #1527 (line rate drifts from header) |
| (g2) untyped dual column families (base vs converted/supplier) | 0 | 5 | #1548, #1547, #1532, #1543, #1544 (enabling condition) |
Recurring defects, named
The
?? 1reflex (#1525, #1526, pre-fix #1549, #1527's stranded DEFAULT 1,|| 1in #1544). Everywhere a rate can be missing, some call site fabricates par — the single most damaging silent failure mode, and a direct consequence of suspect (b): because rates only exist where an integration (or manual entry) put them, every consumer needs a fallback, and the fallback chosen is always 1. The refactor's highest-leverage move: make "no rate" an ERROR at resolution time, everywhere, with exactly one sanctioned exception (base currency = 1 by definition, per #1525).resolveCurrencyAndRate(#1526) is the seed.Direction is tribal knowledge (#1544, #1543, #1532; #1547's reverted inversion).
currency.exchangeRateis foreign-per-base, encoded in zero types and re-derived by hand at every call site — producing three rate² bugs and one near-miss inversion, including a repeat of an expression already fixed by name in migration20260702061504. Even the author of these fixes inverted Xero's rate once before reverting. The refactor should shiptoBase(amount, rate)/fromBase(amount, rate)helpers (mirroring howprecision.tscentralized rounding) and ban raw* exchangeRate// exchangeRatevia a@carbon/checksconformance check.Untyped parallel column families (#1548, #1547, #1532, #1543, #1544). Base
unitPrice/shippingCostand theirconverted*/supplier*mirrors are all barenumber; some tables (supplierPart) don't even have the mirror, storing base by unwritten convention. Five PRs are "picked the wrong sibling" or "converted the already-converted". Refactor options: branded types at the select layer, naming conventions enforced by a check, or collapsing to one stored currency + one conversion point per surface.(currencyCode, exchangeRate) is not atomic (#1526, #1530, #1527). The pair can be split by bulk updates, crafted POSTs, and header-only refreshes — the exact "one value pair" doctrine the codebase already applies to taxPercent/taxAmount (
.claude/rules/numeric-precision.md) but never applied to currency/rate. #1526's resolver plus #1527's cascade are the point-fix version; the refactor should make it structural (single write path, or DB-level coupling).The group-scoping half-migration (#1525, #1542).
currencymoved tocompanyGroupIdon 2026-02-28 with no group-level base currency to anchor it, and consumers/jobs were not swept: one edge function silently broke for six months (#1525), and the nightly job still rebased per company (#1542). This is the refactor's core question — either currency rows return to per-company scope, or the group grows an explicit base currency with #1542's one-base-per-group invariant enforced in the schema rather than in one job's refusal path.Propagation glue instead of a propagation design (#1527, plus context). Six document headers cascade rates to lines via TWO different mechanisms (event interceptors for quote/salesOrder, DB triggers for the purchasing three + now salesInvoice), and one of six was simply missing for years. Every new rate-bearing document re-earns this bug. If lines kept no rate of their own, classes (e) and half of (g1) disappear.
PR interactions and conflicts
- #1530 is stacked on #1526 (uses
resolveCurrencyAndRate; PR body says it needs retargeting to main once #1526 merges). Merge order: #1526 → #1530. - #1527 and #1541 are both migrations touching
salesInvoiceLine.exchangeRate. No file conflict; timestamp order (#152720260901134416before #154120260901161207) means #1527's backfill runs before #1541'sVALIDATE CONSTRAINT— if #1527 is dropped or reordered, re-verify no non-positive/NULL line rates exist before #1541 validates. Also #1527's "rate 1 = unset" insert-trigger semantics and #1541's ">0" constraint are compatible today but both feed the refactor's "what does an unset rate mean" decision. - #1526 and #1541 overlap semantically (both refuse rate ≤ 0: #1526 in the resolver and a
route-level
exchangeRatewrite guard; #1541 at zod + DB). Complementary layers, no file conflict. - #1547 and #1548 both change what sales-invoice line value goes out (sync payload vs
email) — consistent direction (
convertedUnitPrice), no shared files. - #1543 changes
resolveSupplierPriceinshared.service.ts, a shared helper — the PR claims the two updated forms are the only callers; verify before merge. - #1532 explicitly shares no files with any other PR in the set (per its own body, found while verifying #1527).
- #1547 leaves the same defect open in Xero SO/PO, QBO invoice/bill/PO/payment, and Rillet bill syncers — unfixed sibling work the refactor should fold in rather than awaiting six more point PRs.
Verification caveats (for merge sequencing)
Fully verified end-to-end locally: #1525, #1543, #1532, #1527, #1526. Partially verified:
#1541 (DB layer exercised; zod layer unproven in isolation), #1530 (pre-fix repro confirmed,
post-fix runtime check outstanding), #1542 (decision logic against real schema; job not
fired). Reading-only: #1549 (quote PDF route has a PRE-EXISTING render crash on main —
Cannot read properties of undefined (reading 'width') — worth its own issue), #1548 (no
email harness), #1544 (declined to post into shared instance), #1547 (no Xero sandbox; PR
itself recommends a demo-org round-trip before merge).