Ensure transfer name is populated (#1042)

* Ensure transfer name is populated

* Transfer amount fallback
This commit is contained in:
Zach Gollwitzer
2024-08-01 12:10:30 -04:00
committed by GitHub
parent f2a2d2f7e4
commit c70c8b6d86
3 changed files with 6 additions and 5 deletions

View File

@@ -9,19 +9,18 @@ class Account::Transfer < ApplicationRecord
end
def amount_money
entries.first&.amount_money&.abs
entries.first&.amount_money&.abs || Money.new(0)
end
def from_name
outflow_transaction&.account&.name
outflow_transaction&.account&.name || I18n.t("account.transfer.from_fallback_name")
end
def to_name
inflow_transaction&.account&.name
inflow_transaction&.account&.name || I18n.t("account.transfer.to_fallback_name")
end
def name
return nil unless from_name && to_name
I18n.t("account.transfer.name", from_account: from_name, to_account: to_name)
end