Files
sure/app/controllers/transfer_matches_controller.rb
Brendon Scheiber 0c126b1674 feat(i18n): extract hardcoded English strings to locale files (#1806)
* Extract hardcoded strings to i18n

Replace numerous hardcoded English strings with I18n lookups (t / I18n.t) across controllers, views, helpers, and components, and convert model validation error messages to symbol keys. Added multiple locale files under config/locales for models and views. This centralizes user-facing notices/alerts, UI text, import/validation messages, and prepares the app for localization and easier translation maintenance.

* Update en.yml

* Update preview-cleanup.yml

* Revert "Update preview-cleanup.yml"

This reverts commit 1ba6d3c34c.

* test: align i18n assertions with translated messages

* Standardize balance error key and tweak locales

Replace SophtronAccount's :requires_balance error key with :no_balance and update related locale strings for sophtron, plaid, and simplefin accounts to use the new key and clearer copy. Also switch the QIF upload redirect notice to use a relative translation key (t('.qif_uploaded')), remove an unused SSO providers help line, and fix a trailing-newline/whitespace issue in the subscriptions locale. These changes standardize validation keys and improve translation consistency and messaging.

---------

Co-authored-by: KiloClaw <kiloclaw@openclaw.ai>
2026-05-17 09:52:49 +02:00

87 lines
3.2 KiB
Ruby

class TransferMatchesController < ApplicationController
before_action :set_entry
def new
@accounts = Current.family.accounts.writable_by(Current.user).visible.alphabetically.where.not(id: @entry.account_id)
@transfer_match_candidates = @entry.transaction.transfer_match_candidates
end
def create
return unless require_account_permission!(@entry.account, redirect_path: transactions_path)
target_account = resolve_target_account
return unless require_account_permission!(target_account, redirect_path: transactions_path)
@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: t(".success")
end
private
def set_entry
@entry = Current.accessible_entries.find(params[:transaction_id])
end
def transfer_match_params
params.require(:transfer_match).permit(:method, :matched_entry_id, :target_account_id)
end
def resolve_target_account
if transfer_match_params[:method] == "new"
accessible_accounts.find(transfer_match_params[:target_account_id])
else
Current.accessible_entries.find(transfer_match_params[:matched_entry_id]).account
end
end
def build_transfer
if transfer_match_params[:method] == "new"
target_account = accessible_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.accessible_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