mirror of
https://github.com/we-promise/sure.git
synced 2026-04-07 14:31:25 +00:00
* fix: Include investment_contribution in transfer? check and protect transfer entries from sync Transfer transactions with kind "investment_contribution" were not recognized as transfers by the UI, causing missing +/- indicators, "Transfer" labels, and showing regular transaction forms instead of transfer details. Also adds user_modified: true to entries created via TransferMatchesController and SetAsTransferOrPayment rule action to protect them from provider sync overwrites, matching the existing behavior in Transfer::Creator. https://claude.ai/code/session_019BZ5Z1aqKSK3cRdR81P5Jg * fix: Centralize transfer/budget kind constants for consistent investment_contribution handling Define TRANSFER_KINDS and BUDGET_EXCLUDED_KINDS on Transaction to eliminate hard-coded kind lists scattered across filters, rules, and analytics code. investment_contribution is now consistently treated as a transfer in search filters, rule conditions, and UI display (via TRANSFER_KINDS), while budget analytics correctly continue treating it as an expense (via BUDGET_EXCLUDED_KINDS). https://claude.ai/code/session_019BZ5Z1aqKSK3cRdR81P5Jg * fix: Update tests for consistent investment_contribution as transfer kind - search_test: loan_payment is now in TRANSFER_KINDS, so uncategorized filter correctly excludes it (same as funds_movement/cc_payment) - condition_test: investment_contribution is now a transfer kind, so it matches the transfer filter rather than expense filter https://claude.ai/code/session_019BZ5Z1aqKSK3cRdR81P5Jg * fix: Eliminate SQL injection warnings in Transaction::Search Replace string-interpolated SQL with parameterized queries: - totals: use sanitize_sql_array with ? placeholders - apply_category_filter: pass TRANSFER_KINDS as bind parameter - apply_type_filter: use where(kind:)/where.not(kind:) and parameterized IN (?) for compound OR conditions - Remove unused transfer_kinds_sql helper https://claude.ai/code/session_019BZ5Z1aqKSK3cRdR81P5Jg --------- Co-authored-by: Claude <noreply@anthropic.com>
74 lines
2.6 KiB
Ruby
74 lines
2.6 KiB
Ruby
class TransferMatchesController < ApplicationController
|
|
before_action :set_entry
|
|
|
|
def new
|
|
@accounts = Current.family.accounts.visible.alphabetically.where.not(id: @entry.account_id)
|
|
@transfer_match_candidates = @entry.transaction.transfer_match_candidates
|
|
end
|
|
|
|
def create
|
|
@transfer = build_transfer
|
|
Transfer.transaction do
|
|
@transfer.save!
|
|
|
|
# Use DESTINATION (inflow) account for kind, matching Transfer::Creator logic
|
|
destination_account = @transfer.inflow_transaction.entry.account
|
|
outflow_kind = Transfer.kind_for_account(destination_account)
|
|
outflow_attrs = { kind: outflow_kind }
|
|
|
|
if outflow_kind == "investment_contribution"
|
|
category = destination_account.family.investment_contributions_category
|
|
outflow_attrs[:category] = category if category.present? && @transfer.outflow_transaction.category_id.blank?
|
|
end
|
|
|
|
@transfer.outflow_transaction.update!(outflow_attrs)
|
|
@transfer.inflow_transaction.update!(kind: "funds_movement")
|
|
end
|
|
|
|
@transfer.sync_account_later
|
|
|
|
redirect_back_or_to transactions_path, notice: "Transfer created"
|
|
end
|
|
|
|
private
|
|
def set_entry
|
|
@entry = Current.family.entries.find(params[:transaction_id])
|
|
end
|
|
|
|
def transfer_match_params
|
|
params.require(:transfer_match).permit(:method, :matched_entry_id, :target_account_id)
|
|
end
|
|
|
|
def build_transfer
|
|
if transfer_match_params[:method] == "new"
|
|
target_account = Current.family.accounts.find(transfer_match_params[:target_account_id])
|
|
|
|
missing_transaction = Transaction.new(
|
|
entry: target_account.entries.build(
|
|
amount: @entry.amount * -1,
|
|
currency: @entry.currency,
|
|
date: @entry.date,
|
|
name: "Transfer to #{@entry.amount.negative? ? @entry.account.name : target_account.name}",
|
|
user_modified: true,
|
|
)
|
|
)
|
|
|
|
transfer = Transfer.find_or_initialize_by(
|
|
inflow_transaction: @entry.amount.positive? ? missing_transaction : @entry.transaction,
|
|
outflow_transaction: @entry.amount.positive? ? @entry.transaction : missing_transaction
|
|
)
|
|
transfer.status = "confirmed"
|
|
transfer
|
|
else
|
|
target_transaction = Current.family.entries.find(transfer_match_params[:matched_entry_id])
|
|
|
|
transfer = Transfer.find_or_initialize_by(
|
|
inflow_transaction: @entry.amount.negative? ? @entry.transaction : target_transaction.transaction,
|
|
outflow_transaction: @entry.amount.negative? ? target_transaction.transaction : @entry.transaction
|
|
)
|
|
transfer.status = "confirmed"
|
|
transfer
|
|
end
|
|
end
|
|
end
|