1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-24 15:49:39 +02:00

Transfer and Payment auto-matching, model and UI improvements (#1585)

* Transfer data model migration

* Transfers and payment modeling and UI improvements

* Fix CI

* Transfer matching flow

* Better UI for transfers

* Auto transfer matching, approve, reject flow

* Mark transfers created from form as confirmed

* Account filtering

* Excluded rejected transfers from calculations

* Calculation tweaks with transfer exclusions

* Clean up migration
This commit is contained in:
Zach Gollwitzer 2025-01-07 09:41:24 -05:00 committed by GitHub
parent 46e129308f
commit 307a3687e8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
78 changed files with 1161 additions and 682 deletions

View file

@ -0,0 +1,100 @@
require "test_helper"
class TransferTest < ActiveSupport::TestCase
include Account::EntriesTestHelper
setup do
@outflow = account_transactions(:transfer_out)
@inflow = account_transactions(:transfer_in)
end
test "transfer has different accounts, opposing amounts, and within 4 days of each other" do
outflow_entry = create_transaction(date: Date.current, account: accounts(:depository), amount: 500)
inflow_entry = create_transaction(date: 1.day.ago.to_date, account: accounts(:credit_card), amount: -500)
assert_difference -> { Transfer.count } => 1 do
Transfer.create!(
inflow_transaction: inflow_entry.account_transaction,
outflow_transaction: outflow_entry.account_transaction,
)
end
end
test "transfer cannot have 2 transactions from the same account" do
outflow_entry = create_transaction(date: Date.current, account: accounts(:depository), amount: 500)
inflow_entry = create_transaction(date: 1.day.ago.to_date, account: accounts(:depository), amount: -500)
transfer = Transfer.new(
inflow_transaction: inflow_entry.account_transaction,
outflow_transaction: outflow_entry.account_transaction,
)
assert_no_difference -> { Transfer.count } do
transfer.save
end
assert_equal "Transfer must have different accounts", transfer.errors.full_messages.first
end
test "Transfer transactions must have opposite amounts" do
outflow_entry = create_transaction(date: Date.current, account: accounts(:depository), amount: 500)
inflow_entry = create_transaction(date: Date.current, account: accounts(:credit_card), amount: -400)
transfer = Transfer.new(
inflow_transaction: inflow_entry.account_transaction,
outflow_transaction: outflow_entry.account_transaction,
)
assert_no_difference -> { Transfer.count } do
transfer.save
end
assert_equal "Transfer transactions must have opposite amounts", transfer.errors.full_messages.first
end
test "transfer dates must be within 4 days of each other" do
outflow_entry = create_transaction(date: Date.current, account: accounts(:depository), amount: 500)
inflow_entry = create_transaction(date: 5.days.ago.to_date, account: accounts(:credit_card), amount: -500)
transfer = Transfer.new(
inflow_transaction: inflow_entry.account_transaction,
outflow_transaction: outflow_entry.account_transaction,
)
assert_no_difference -> { Transfer.count } do
transfer.save
end
assert_equal "Transfer transaction dates must be within 4 days of each other", transfer.errors.full_messages.first
end
test "from_accounts converts amounts to the to_account's currency" do
accounts(:depository).update!(currency: "EUR")
eur_account = accounts(:depository).reload
usd_account = accounts(:credit_card)
ExchangeRate.create!(
from_currency: "EUR",
to_currency: "USD",
rate: 1.1,
date: Date.current,
)
transfer = Transfer.from_accounts(
from_account: eur_account,
to_account: usd_account,
date: Date.current,
amount: 500,
)
assert_equal 500, transfer.outflow_transaction.entry.amount
assert_equal "EUR", transfer.outflow_transaction.entry.currency
assert_equal -550, transfer.inflow_transaction.entry.amount
assert_equal "USD", transfer.inflow_transaction.entry.currency
assert_difference -> { Transfer.count } => 1 do
transfer.save!
end
end
end