invoices: self-contained payout addresses

Crypto options were limited to a hard-coded asset list, with one
address per coin in a side table. A payout address now carries
everything an invoice needs: ticker, name, QR URI scheme, amount
parameter, CoinGecko id, address and an active flag. Any coin can be
added, several addresses per ticker are fine, and known tickers fill the
QR and rate fields from the built-in templates.

The new-invoice form picks a payout address. The invoice snapshots the
ticker, address, name, scheme and amount parameter, and the PDF and QR
render from that copy, so editing, retiring or deleting a payout entry
never changes an issued invoice. "Fetch live" looks up the rate by the
payout address's CoinGecko id.

Migration 012 keeps the existing rows and backfills both the payout
metadata and the snapshots on existing crypto invoices.

Assisted-by: Claude:opus-5
This commit is contained in:
Sergei Poljanski 2026-10-10 09:17:09 +04:00
commit 33ba7650c3
Signed by: asxpi
GPG key ID: 4F8851660FA4121B
19 changed files with 420 additions and 176 deletions

View file

@ -72,7 +72,7 @@ class AppTest < Minitest::Test
client_name: 'ACME', client_email: 'billing@example.com', client_address: '',
currency: 'EUR', gel_rate: '3.05',
issued_on: Date.today.to_s, due_on: (Date.today + 14).to_s, notes: '',
crypto_coin: 'LTC', crypto_address: '', crypto_rate: '', crypto_amount: '',
payout_id: '', crypto_rate: '', crypto_amount: '',
items: { '0' => { 'description' => 'Engineering — test', 'qty' => '2', 'unit_price' => '100.50' } } }
end
@ -94,16 +94,22 @@ class AppTest < Minitest::Test
skip 'TEST_DATABASE_URL not set' unless TestDb.available?
token = csrf_token_from('/admin/invoices/new', admin_env)
params = invoice_form_params(token).merge(
crypto_coin: 'USDT-TRC20', crypto_address: 'TXYZexampleexampleexampleexample12',
crypto_rate: '1.00', crypto_amount: ''
)
payout = PayoutAddress.create(coin: 'USDT-TRC20', name: 'Tether (Tron)', address: 'TXYZexampleexampleexampleexample12',
updated_by: 't', updated_at: Time.now.utc)
params = invoice_form_params(token).merge(payout_id: payout.id.to_s, crypto_rate: '1.00', crypto_amount: '')
post '/admin/invoices', params, admin_env
assert_equal 302, last_response.status, last_response.body
invoice = Invoice.first
assert_equal 'USDT-TRC20', invoice.crypto_coin
assert_equal 'TXYZexampleexampleexampleexample12', invoice.crypto_address
assert_nil invoice.crypto_scheme # token: bare address QR
assert_equal BigDecimal('201'), invoice.crypto_amount_due
payout.update(address: 'TNEWexampleexampleexampleexample99', name: 'Renamed')
assert_equal 'TXYZexampleexampleexampleexample12', invoice.refresh.crypto_address # snapshot kept
ensure
payout&.destroy
end
def test_create_invoice_validation_failure_rerenders_form