Accept ex_money %Money{} amounts + single-currency check (1.5.1) - #22
Merged
Conversation
Cash-flow amounts can now be ex_money %Money{} values. Finance takes the Decimal
amount via an is_struct guard — no dependency on ex_money — and rejects a series
that mixes currencies with {:error, :mixed_currencies}; plain numbers and Decimal
are currency-neutral. Relaxes the optional decimal requirement to
`~> 2.0 or ~> 3.0` so finance and ex_money (pinned to Decimal 2.x) can coexist.
A stand-in %Money{} in test/support exercises the path without pulling ex_money
into finance's own deps.
214 tests, 100% coverage, credo/dialyzer clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AVibXT2w1dEdVtMHqffFKn
The relaxed `decimal ~> 2.0 or ~> 3.0` needs its lower bound covered. Add a matrix job that pins Decimal to 2.x — on its own, not via ex_money.
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.
Cash-flow amounts can now be
ex_money%Money{}values, alongside numbers andDecimal— common when amounts come from an Ecto money column.What it does
Finance.Shared.to_amount/1gains a%Money{}clause (guarded byis_struct(_, Money), never a%Money{}pattern — the compile-time trap fixed in 1.4.4), taking theDecimalamount.{:error, :mixed_currencies}. Plain numbers andDecimalare currency-neutral and never conflict, so[Money.new(:USD, ...), 1100]is fine but[Money.new(:USD, ...), Money.new(:EUR, ...)]errors. Wired into every cash-flow function (xirr/irr/npv/xnpv/mirrand the*_manybatch forms).decimal ~> 2.0while finance pinned~> 3.0, so the two couldn't coexist. The optionaldecimalrequirement is relaxed to~> 2.0 or ~> 3.0.Testing
A stand-in
%Money{}intest/support/exercises the path (acceptance, currency-neutral mixing, per-series:mixed_currencies, batch) without pulling ex_money — and its Decimal 2.x pin — into finance's own deps.214 tests, 100% coverage, credo/dialyzer clean, 0 doc warnings. Patch →
1.5.1.🤖 Generated with Claude Code