Skip to content

armgit / maybe

Public Imported from GitHub
0

The personal finance app for everyone

Ensure transfer name is populated (#1042)

Zach Gollwitzerc70c8b6d86d3
diff --git a/app/models/account/transfer.rb b/app/models/account/transfer.rb
index 975e0440..85fa9406 100644
--- a/app/models/account/transfer.rb
+++ b/app/models/account/transfer.rb
@@ -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
diff --git a/app/views/account/transfers/_transfer.html.erb b/app/views/account/transfers/_transfer.html.erb
index 3b2bcc28..4dbfc26a 100644
--- a/app/views/account/transfers/_transfer.html.erb
+++ b/app/views/account/transfers/_transfer.html.erb
@@ -11,7 +11,7 @@
<%= tag.div class: short ? "max-w-[250px]" : "max-w-[325px]" do %>
<div class="flex items-center gap-2">
- <%= circle_logo("T") %>
+ <%= circle_logo(transfer.from_name[0].upcase) %>
<%= tag.p transfer.name, class: "truncate text-gray-900" %>
</div>
diff --git a/config/locales/models/account/transfer/en.yml b/config/locales/models/account/transfer/en.yml
index 877aeb8b..dc33084d 100644
--- a/config/locales/models/account/transfer/en.yml
+++ b/config/locales/models/account/transfer/en.yml
@@ -2,4 +2,6 @@
en:
account:
transfer:
+ from_fallback_name: Originator
name: Transfer from %{from_account} to %{to_account}
+ to_fallback_name: Receiver