Files
sure/test/support/entries_test_helper.rb
DataEnginr e75f2a0c78 Fix fee display consistency, derive fees from entries, clean schema churn
- Show principal-only transfer amounts on both sides with separate fee and total lines (fixes inconsistent gross/net convention)
- Derive displayed fee amounts from fee_transactions entries (single source of truth) instead of stored columns
- Remove stored source_fee_amount/destination_fee_amount columns from transfers table
- Add foreign key for transactions.transfer_id -> transfers.id (replaces invalid CHECK subquery)
- Move destination fee line inside destination side div for consistent layout
- Remove orphaned view_fee_transaction locale keys from 7 locale files
- Rebuild schema.rb from origin/main to eliminate unrelated column reordering churn
2026-06-28 19:47:53 +00:00

110 lines
3.1 KiB
Ruby

module EntriesTestHelper
def create_transaction(attributes = {})
entry_attributes = attributes.except(:category, :tags, :merchant, :kind)
transaction_attributes = attributes.slice(:category, :tags, :merchant, :kind)
entry_defaults = {
account: accounts(:depository),
name: "Transaction",
date: Date.current,
currency: "USD",
amount: 100,
entryable: Transaction.new(transaction_attributes)
}
Entry.create! entry_defaults.merge(entry_attributes)
end
def create_valuation(attributes = {})
entry_attributes = attributes.except(:kind)
valuation_attributes = attributes.slice(:kind)
account = attributes[:account] || accounts(:depository)
amount = attributes[:amount] || 5000
entry_defaults = {
account: account,
name: "Valuation",
date: 1.day.ago.to_date,
currency: "USD",
amount: amount,
entryable: Valuation.new({ kind: "reconciliation" }.merge(valuation_attributes))
}
Entry.create! entry_defaults.merge(entry_attributes)
end
def create_trade(security, account:, qty:, date:, price: nil, currency: "USD")
trade_price = price || Security::Price.find_by!(security: security, date: date).price
trade = Trade.new \
qty: qty,
security: security,
price: trade_price,
currency: currency,
investment_activity_label: qty > 0 ? "Buy" : "Sell"
account.entries.create! \
name: "Trade",
date: date,
amount: qty * trade_price,
currency: currency,
entryable: trade
end
def create_transfer(from_account:, to_account:, amount:, date: Date.current, currency: "USD", source_fee_amount: 0, destination_fee_amount: 0)
outflow_transaction = Transaction.create!(kind: "funds_movement")
inflow_transaction = Transaction.create!(kind: "funds_movement")
transfer = Transfer.create!(
outflow_transaction: outflow_transaction,
inflow_transaction: inflow_transaction,
amount: amount.abs
)
from_account.entries.create!(
name: "Transfer to #{to_account.name}",
date: date,
amount: amount.abs,
currency: currency,
entryable: outflow_transaction
)
to_account.entries.create!(
name: "Transfer from #{from_account.name}",
date: date,
amount: -(amount.abs),
currency: currency,
entryable: inflow_transaction
)
if source_fee_amount > 0
fee_tx = Transaction.create!(
kind: "standard",
entry: from_account.entries.create!(
name: "Transfer fee to #{to_account.name}",
date: date,
amount: source_fee_amount,
currency: currency,
)
)
transfer.fee_transactions << fee_tx
end
if destination_fee_amount > 0
fee_tx = Transaction.create!(
kind: "standard",
entry: to_account.entries.create!(
name: "Transfer fee from #{from_account.name}",
date: date,
amount: destination_fee_amount,
currency: currency,
)
)
transfer.fee_transactions << fee_tx
end
transfer
end
end