Settlement balance guards, per-currency netting, Decimal rates #57
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/settlement-balance-and-decimal"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Third PR of the refactor series (stacked on #56 → #55; merge those first).
Problems (CODE-REVIEW-2026-06 #2, #8, #13 + libra-#38 + a new finding):
get_unsettled_entries_bqlhardcodedfiat_currency = "EUR"and usedfloat()— USD (or SATS-only) entries were summed as if EUR when netting settlements.fiat_rate/btc_ratecost-basis metadata was computed with float division, baking drift into every entry.format_posting_at_average_costemitted invalidSATS {}when no cost currency.validate_metadataleaked rawdecimal.InvalidOperation(libra-#38).Changes:
format_net_settlement_entryenforces the same inline balance constraint as the fiat formatter (payment = receivable − payable + credit) and supports a credit-overflow leg. Unbalanced settlements now raise instead of reaching the ledger.on_invoice_paidsettles only what the payment covers; excess becomes user credit (same semantics as the fiat path's libra-#41 handling). Settlement links attach only on full-balance coverage, same-currency entries only.get_unsettled_entries_bqlreturns real posting currencies and exact Decimal strings;/receivables/settlenets only same-currency entries.fiat_rate_metadata()helper computes rates in Decimal; all four call sites converted.Tests: 10 new unit tests (balance guard, credit leg, cost braces, rate exactness); settlement test updated for the string payload contract. Full suite: 168 passed, 3 skipped, 7 xfailed.
🤖 Generated with Claude Code
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.