mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-24 15:49:39 +02:00
Transaction transfers, payments, and matching (#883)
* Add transfer model and clean up family snapshot fixtures * Ignore transfers in income and expense snapshots * Add transfer validations * Implement basic transfer matching UI * Fix merge conflicts * Add missing translations * Tweak selection states for transfer types * Add missing i18n translation
This commit is contained in:
parent
b462bc8f8c
commit
ca39b26070
57 changed files with 991 additions and 427 deletions
49
test/models/transfer_test.rb
Normal file
49
test/models/transfer_test.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
require "test_helper"
|
||||
|
||||
class TransferTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
# Transfers can be posted on different dates
|
||||
@outflow = accounts(:checking).transactions.create! date: 1.day.ago.to_date, name: "Transfer to Savings", amount: 100, marked_as_transfer: true
|
||||
@inflow = accounts(:savings).transactions.create! date: Date.current, name: "Transfer from Savings", amount: -100, marked_as_transfer: true
|
||||
end
|
||||
|
||||
test "transfer valid if it has inflow and outflow from different accounts for the same amount" do
|
||||
transfer = Transfer.create! transactions: [ @inflow, @outflow ]
|
||||
|
||||
assert transfer.valid?
|
||||
end
|
||||
|
||||
test "transfer must have 2 transactions" do
|
||||
invalid_transfer_1 = Transfer.new transactions: [ @outflow ]
|
||||
invalid_transfer_2 = Transfer.new transactions: [ @inflow, @outflow, transactions(:savings_four) ]
|
||||
|
||||
assert invalid_transfer_1.invalid?
|
||||
assert invalid_transfer_2.invalid?
|
||||
end
|
||||
|
||||
test "transfer cannot have 2 transactions from the same account" do
|
||||
account = accounts(:checking)
|
||||
inflow = account.transactions.create! date: Date.current, name: "Inflow", amount: -100
|
||||
outflow = account.transactions.create! date: Date.current, name: "Outflow", amount: 100
|
||||
|
||||
assert_raise ActiveRecord::RecordInvalid do
|
||||
Transfer.create! transactions: [ inflow, outflow ]
|
||||
end
|
||||
end
|
||||
|
||||
test "all transfer transactions must be marked as transfers" do
|
||||
@inflow.update! marked_as_transfer: false
|
||||
|
||||
assert_raise ActiveRecord::RecordInvalid do
|
||||
Transfer.create! transactions: [ @inflow, @outflow ]
|
||||
end
|
||||
end
|
||||
|
||||
test "transfer transactions must net to zero" do
|
||||
@outflow.update! amount: 105
|
||||
|
||||
assert_raises ActiveRecord::RecordInvalid do
|
||||
Transfer.create! transactions: [ @inflow, @outflow ]
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue