Skip to content

Accept ex_money %Money{} amounts + single-currency check (1.5.1) - #22

Merged
tubedude merged 2 commits into
mainfrom
ex-money-support
Jul 5, 2026
Merged

Accept ex_money %Money{} amounts + single-currency check (1.5.1)#22
tubedude merged 2 commits into
mainfrom
ex-money-support

Conversation

@tubedude

@tubedude tubedude commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Cash-flow amounts can now be ex_money %Money{} values, alongside numbers and Decimal — common when amounts come from an Ecto money column.

What it does

  • Finance.Shared.to_amount/1 gains a %Money{} clause (guarded by is_struct(_, Money), never a %Money{} pattern — the compile-time trap fixed in 1.4.4), taking the Decimal amount.
  • A single-currency check rejects a series that mixes currencies with {:error, :mixed_currencies}. Plain numbers and Decimal are 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/mirr and the *_many batch forms).
  • No dependency on ex_money — finance reads the struct structurally. That also sidesteps a real conflict: ex_money pins decimal ~> 2.0 while finance pinned ~> 3.0, so the two couldn't coexist. The optional decimal requirement is relaxed to ~> 2.0 or ~> 3.0.

Testing

A stand-in %Money{} in test/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

tubedude and others added 2 commits July 5, 2026 12:24
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.
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 100.0%. remained the same — ex-money-support into main

@tubedude
tubedude merged commit 603ce36 into main Jul 5, 2026
4 checks passed
@tubedude
tubedude deleted the ex-money-support branch July 5, 2026 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants