mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-08 15:05:22 +02:00
Remove stale methods
This commit is contained in:
parent
1e76df9520
commit
cd41e61caa
2 changed files with 0 additions and 72 deletions
|
@ -12,48 +12,6 @@ class Transfer < ApplicationRecord
|
|||
validate :transfer_within_date_range
|
||||
validate :transfer_has_same_family
|
||||
|
||||
class << self
|
||||
def from_accounts(from_account:, to_account:, date:, amount:)
|
||||
# Attempt to convert the amount to the to_account's currency.
|
||||
# If the conversion fails, use the original amount.
|
||||
converted_amount = begin
|
||||
Money.new(amount.abs, from_account.currency).exchange_to(to_account.currency)
|
||||
rescue Money::ConversionError
|
||||
Money.new(amount.abs, from_account.currency)
|
||||
end
|
||||
|
||||
outflow_kind = if to_account&.accountable_type == "Loan"
|
||||
"loan_payment"
|
||||
elsif to_account&.liability?
|
||||
"payment"
|
||||
else
|
||||
"transfer"
|
||||
end
|
||||
|
||||
new(
|
||||
inflow_transaction: Transaction.new(
|
||||
kind: "transfer",
|
||||
entry: to_account.entries.build(
|
||||
amount: converted_amount.amount.abs * -1,
|
||||
currency: converted_amount.currency.iso_code,
|
||||
date: date,
|
||||
name: "Transfer from #{from_account.name}",
|
||||
)
|
||||
),
|
||||
outflow_transaction: Transaction.new(
|
||||
kind: outflow_kind,
|
||||
entry: from_account.entries.build(
|
||||
amount: amount.abs,
|
||||
currency: from_account.currency,
|
||||
date: date,
|
||||
name: "Transfer to #{to_account.name}",
|
||||
)
|
||||
),
|
||||
status: "confirmed"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def reject!
|
||||
Transfer.transaction do
|
||||
RejectedTransfer.find_or_create_by!(inflow_transaction_id: inflow_transaction_id, outflow_transaction_id: outflow_transaction_id)
|
||||
|
|
|
@ -93,36 +93,6 @@ class TransferTest < ActiveSupport::TestCase
|
|||
assert_equal "Must be from same family", 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
|
||||
|
||||
test "transaction can only belong to one transfer" do
|
||||
outflow_entry = create_transaction(date: Date.current, account: accounts(:depository), amount: 500)
|
||||
inflow_entry1 = create_transaction(date: Date.current, account: accounts(:credit_card), amount: -500)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue