Merge pull request #608 from luckyPipewrench/investment-activity

Investment activity labels and classification
This commit is contained in:
soky srm
2026-01-13 10:13:31 +01:00
committed by GitHub
22 changed files with 284 additions and 39 deletions

View File

@@ -285,4 +285,22 @@ class IncomeStatementTest < ActiveSupport::TestCase
assert_equal 5, totals.transactions_count
assert_equal Money.new(1050, @family.currency), totals.expense_money # 900 + 150
end
test "excludes investment_contribution transactions from income statement" do
# Create a transfer to investment account (marked as investment_contribution)
investment_contribution = create_transaction(
account: @checking_account,
amount: 1000,
category: nil,
kind: "investment_contribution"
)
income_statement = IncomeStatement.new(@family)
totals = income_statement.totals(date_range: Period.last_30_days.date_range)
# investment_contribution should be excluded (it's in the exclusion list)
assert_equal 4, totals.transactions_count # Only original 4 transactions
assert_equal Money.new(1000, @family.currency), totals.income_money
assert_equal Money.new(900, @family.currency), totals.expense_money
end
end

View File

@@ -100,4 +100,36 @@ class Rule::ActionTest < ActiveSupport::TestCase
assert_equal new_name, transaction.reload.entry.name
end
end
test "set_investment_activity_label" do
# Does not modify transactions that are locked (user edited them)
@txn1.lock_attr!(:investment_activity_label)
action = Rule::Action.new(
rule: @transaction_rule,
action_type: "set_investment_activity_label",
value: "Dividend"
)
action.apply(@rule_scope)
assert_nil @txn1.reload.investment_activity_label
[ @txn2, @txn3 ].each do |transaction|
assert_equal "Dividend", transaction.reload.investment_activity_label
end
end
test "set_investment_activity_label ignores invalid values" do
action = Rule::Action.new(
rule: @transaction_rule,
action_type: "set_investment_activity_label",
value: "InvalidLabel"
)
result = action.apply(@rule_scope)
assert_equal 0, result
assert_nil @txn1.reload.investment_activity_label
end
end

View File

@@ -18,4 +18,36 @@ class TransactionTest < ActiveSupport::TestCase
assert_not transaction.pending?
end
test "investment_contribution is a valid kind" do
transaction = Transaction.new(kind: "investment_contribution")
assert_equal "investment_contribution", transaction.kind
assert transaction.investment_contribution?
end
test "all transaction kinds are valid" do
valid_kinds = %w[standard funds_movement cc_payment loan_payment one_time investment_contribution]
valid_kinds.each do |kind|
transaction = Transaction.new(kind: kind)
assert_equal kind, transaction.kind, "#{kind} should be a valid transaction kind"
end
end
test "ACTIVITY_LABELS contains all valid labels" do
assert_includes Transaction::ACTIVITY_LABELS, "Buy"
assert_includes Transaction::ACTIVITY_LABELS, "Sell"
assert_includes Transaction::ACTIVITY_LABELS, "Sweep In"
assert_includes Transaction::ACTIVITY_LABELS, "Sweep Out"
assert_includes Transaction::ACTIVITY_LABELS, "Dividend"
assert_includes Transaction::ACTIVITY_LABELS, "Reinvestment"
assert_includes Transaction::ACTIVITY_LABELS, "Interest"
assert_includes Transaction::ACTIVITY_LABELS, "Fee"
assert_includes Transaction::ACTIVITY_LABELS, "Transfer"
assert_includes Transaction::ACTIVITY_LABELS, "Contribution"
assert_includes Transaction::ACTIVITY_LABELS, "Withdrawal"
assert_includes Transaction::ACTIVITY_LABELS, "Exchange"
assert_includes Transaction::ACTIVITY_LABELS, "Other"
end
end

View File

@@ -104,4 +104,24 @@ class TransferTest < ActiveSupport::TestCase
Transfer.create!(inflow_transaction: inflow_entry2.transaction, outflow_transaction: outflow_entry.transaction)
end
end
test "kind_for_account returns investment_contribution for investment accounts" do
assert_equal "investment_contribution", Transfer.kind_for_account(accounts(:investment))
end
test "kind_for_account returns investment_contribution for crypto accounts" do
assert_equal "investment_contribution", Transfer.kind_for_account(accounts(:crypto))
end
test "kind_for_account returns loan_payment for loan accounts" do
assert_equal "loan_payment", Transfer.kind_for_account(accounts(:loan))
end
test "kind_for_account returns cc_payment for credit card accounts" do
assert_equal "cc_payment", Transfer.kind_for_account(accounts(:credit_card))
end
test "kind_for_account returns funds_movement for depository accounts" do
assert_equal "funds_movement", Transfer.kind_for_account(accounts(:depository))
end
end