Files
sure/app/controllers/valuations_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

110 lines
3.1 KiB
Ruby

class ValuationsController < ApplicationController
include EntryableResource, StreamExtensions
def confirm_create
@account = accessible_accounts.find(params.dig(:entry, :account_id))
return unless require_account_permission!(@account)
@entry = @account.entries.build(entry_params.merge(currency: @account.currency))
if entry_params[:amount].blank?
@error_message = t("valuations.errors.amount_required")
render :new, status: :unprocessable_entity
return
end
@reconciliation_dry_run = @entry.account.create_reconciliation(
balance: entry_params[:amount],
date: entry_params[:date],
dry_run: true
)
render :confirm_create
end
def confirm_update
@entry = Current.accessible_entries.find(params[:id])
return unless require_account_permission!(@entry.account)
@account = @entry.account
if entry_params[:amount].blank?
@error_message = t("valuations.errors.amount_required")
render :show, status: :unprocessable_entity
return
end
@entry.assign_attributes(entry_params.merge(currency: @account.currency))
@reconciliation_dry_run = @entry.account.update_reconciliation(
@entry,
balance: entry_params[:amount],
date: entry_params[:date],
dry_run: true
)
render :confirm_update
end
def create
account = accessible_accounts.find(params.dig(:entry, :account_id))
return unless require_account_permission!(account)
result = account.create_reconciliation(
balance: entry_params[:amount],
date: entry_params[:date],
)
if result.success?
respond_to do |format|
format.html { redirect_back_or_to account_path(account), notice: t(".account_updated") }
format.turbo_stream { stream_redirect_back_or_to(account_path(account), notice: t(".account_updated")) }
end
else
@error_message = result.error_message
render :new, status: :unprocessable_entity
end
end
def update
return unless require_account_permission!(@entry.account)
# Notes updating is independent of reconciliation, just a simple CRUD operation
@entry.update!(notes: entry_params[:notes]) if entry_params[:notes].present?
if entry_params[:date].present? && entry_params[:amount].present?
result = @entry.account.update_reconciliation(
@entry,
balance: entry_params[:amount],
date: entry_params[:date],
)
end
if result.nil? || result.success?
@entry.reload
respond_to do |format|
format.html { redirect_back_or_to account_path(@entry.account), notice: t(".entry_updated") }
format.turbo_stream do
render turbo_stream: [
turbo_stream.replace(
dom_id(@entry, :header),
partial: "valuations/header",
locals: { entry: @entry }
),
turbo_stream.replace(@entry)
]
end
end
else
@error_message = result.error_message
render :show, status: :unprocessable_entity
end
end
private
def entry_params
params.require(:entry).permit(:date, :amount, :notes)
end
end