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:
parent
46e129308f
commit
307a3687e8
78 changed files with 1161 additions and 682 deletions
|
@ -38,7 +38,7 @@ class Account::TradesControllerTest < ActionDispatch::IntegrationTest
|
|||
|
||||
assert_difference -> { Account::Entry.count } => 2,
|
||||
-> { Account::Transaction.count } => 2,
|
||||
-> { Account::Transfer.count } => 1 do
|
||||
-> { Transfer.count } => 1 do
|
||||
post account_trades_url, params: {
|
||||
account_entry: {
|
||||
account_id: @entry.account_id,
|
||||
|
@ -59,7 +59,7 @@ class Account::TradesControllerTest < ActionDispatch::IntegrationTest
|
|||
|
||||
assert_difference -> { Account::Entry.count } => 2,
|
||||
-> { Account::Transaction.count } => 2,
|
||||
-> { Account::Transfer.count } => 1 do
|
||||
-> { Transfer.count } => 1 do
|
||||
post account_trades_url, params: {
|
||||
account_entry: {
|
||||
account_id: @entry.account_id,
|
||||
|
@ -78,7 +78,7 @@ class Account::TradesControllerTest < ActionDispatch::IntegrationTest
|
|||
test "deposit and withdrawal has optional transfer account" do
|
||||
assert_difference -> { Account::Entry.count } => 1,
|
||||
-> { Account::Transaction.count } => 1,
|
||||
-> { Account::Transfer.count } => 0 do
|
||||
-> { Transfer.count } => 0 do
|
||||
post account_trades_url, params: {
|
||||
account_entry: {
|
||||
account_id: @entry.account_id,
|
||||
|
@ -93,7 +93,6 @@ class Account::TradesControllerTest < ActionDispatch::IntegrationTest
|
|||
created_entry = Account::Entry.order(created_at: :desc).first
|
||||
|
||||
assert created_entry.amount.positive?
|
||||
assert created_entry.marked_as_transfer
|
||||
assert_redirected_to @entry.account
|
||||
end
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ class Account::TransactionsControllerTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
test "can destroy many transactions at once" do
|
||||
transactions = @user.family.entries.account_transactions
|
||||
transactions = @user.family.entries.account_transactions.incomes_and_expenses
|
||||
delete_count = transactions.size
|
||||
|
||||
assert_difference([ "Account::Transaction.count", "Account::Entry.count" ], -delete_count) do
|
||||
|
|
42
test/controllers/account/transfer_matches_controller_test.rb
Normal file
42
test/controllers/account/transfer_matches_controller_test.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
require "test_helper"
|
||||
|
||||
class Account::TransferMatchesControllerTest < ActionDispatch::IntegrationTest
|
||||
include Account::EntriesTestHelper
|
||||
|
||||
setup do
|
||||
sign_in @user = users(:family_admin)
|
||||
end
|
||||
|
||||
test "matches existing transaction and creates transfer" do
|
||||
inflow_transaction = create_transaction(amount: 100, account: accounts(:depository))
|
||||
outflow_transaction = create_transaction(amount: -100, account: accounts(:investment))
|
||||
|
||||
assert_difference "Transfer.count", 1 do
|
||||
post account_transaction_transfer_match_path(inflow_transaction), params: {
|
||||
transfer_match: {
|
||||
method: "existing",
|
||||
matched_entry_id: outflow_transaction.id
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
assert_redirected_to transactions_url
|
||||
assert_equal "Transfer created", flash[:notice]
|
||||
end
|
||||
|
||||
test "creates transfer for target account" do
|
||||
inflow_transaction = create_transaction(amount: 100, account: accounts(:depository))
|
||||
|
||||
assert_difference [ "Transfer.count", "Account::Entry.count", "Account::Transaction.count" ], 1 do
|
||||
post account_transaction_transfer_match_path(inflow_transaction), params: {
|
||||
transfer_match: {
|
||||
method: "new",
|
||||
target_account_id: accounts(:investment).id
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
assert_redirected_to transactions_url
|
||||
assert_equal "Transfer created", flash[:notice]
|
||||
end
|
||||
end
|
|
@ -1,19 +1,19 @@
|
|||
require "test_helper"
|
||||
|
||||
class Account::TransfersControllerTest < ActionDispatch::IntegrationTest
|
||||
class TransfersControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
sign_in users(:family_admin)
|
||||
end
|
||||
|
||||
test "should get new" do
|
||||
get new_account_transfer_url
|
||||
get new_transfer_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "can create transfers" do
|
||||
assert_difference "Account::Transfer.count", 1 do
|
||||
post account_transfers_url, params: {
|
||||
account_transfer: {
|
||||
assert_difference "Transfer.count", 1 do
|
||||
post transfers_url, params: {
|
||||
transfer: {
|
||||
from_account_id: accounts(:depository).id,
|
||||
to_account_id: accounts(:credit_card).id,
|
||||
date: Date.current,
|
||||
|
@ -26,8 +26,8 @@ class Account::TransfersControllerTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
test "can destroy transfer" do
|
||||
assert_difference -> { Account::Transfer.count } => -1, -> { Account::Transaction.count } => -2 do
|
||||
delete account_transfer_url(account_transfers(:one))
|
||||
assert_difference -> { Transfer.count } => -1, -> { Account::Transaction.count } => 0 do
|
||||
delete transfer_url(transfers(:one))
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue