Skip to content

armgit / maybe

Public Imported from GitHub
0

The personal finance app for everyone

Bug fixes for specialized account pages (#1275)

Zach Gollwitzera2ab21792580
diff --git a/app/controllers/credit_cards_controller.rb b/app/controllers/credit_cards_controller.rb
index 41316db9..5854c9fa 100644
--- a/app/controllers/credit_cards_controller.rb
+++ b/app/controllers/credit_cards_controller.rb
@@ -27,7 +27,7 @@ class CreditCardsController < ApplicationController
def account_params
params.require(:account)
.permit(
- :name, :balance, :start_date, :start_balance, :currency, :accountable_type,
+ :name, :balance, :institution_id, :start_date, :start_balance, :currency, :accountable_type,
accountable_attributes: [
:id,
:available_credit,
diff --git a/app/controllers/loans_controller.rb b/app/controllers/loans_controller.rb
index 65d3fdc3..b084e566 100644
--- a/app/controllers/loans_controller.rb
+++ b/app/controllers/loans_controller.rb
@@ -27,7 +27,7 @@ class LoansController < ApplicationController
def account_params
params.require(:account)
.permit(
- :name, :balance, :start_date, :start_balance, :currency, :accountable_type,
+ :name, :balance, :institution_id, :start_date, :start_balance, :currency, :accountable_type,
accountable_attributes: [
:id,
:rate_type,
diff --git a/app/controllers/properties_controller.rb b/app/controllers/properties_controller.rb
index b15c5f86..71d46f0e 100644
--- a/app/controllers/properties_controller.rb
+++ b/app/controllers/properties_controller.rb
@@ -27,7 +27,7 @@ class PropertiesController < ApplicationController
def account_params
params.require(:account)
.permit(
- :name, :balance, :start_date, :start_balance, :currency, :accountable_type,
+ :name, :balance, :institution_id, :start_date, :start_balance, :currency, :accountable_type,
accountable_attributes: [
:id,
:year_built,
diff --git a/app/controllers/vehicles_controller.rb b/app/controllers/vehicles_controller.rb
index edfc6def..e9822b9b 100644
--- a/app/controllers/vehicles_controller.rb
+++ b/app/controllers/vehicles_controller.rb
@@ -27,7 +27,7 @@ class VehiclesController < ApplicationController
def account_params
params.require(:account)
.permit(
- :name, :balance, :start_date, :start_balance, :currency, :accountable_type,
+ :name, :balance, :institution_id, :start_date, :start_balance, :currency, :accountable_type,
accountable_attributes: [
:id,
:make,
diff --git a/app/models/account.rb b/app/models/account.rb
index b6920e9e..61d473d8 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -83,7 +83,8 @@ class Account < ApplicationRecord
end
def original_balance
- balances.chronological.first&.balance || balance
+ balance_amount = balances.chronological.first&.balance || balance
+ Money.new(balance_amount, currency)
end
def owns_ticker?(ticker)
diff --git a/app/models/credit_card.rb b/app/models/credit_card.rb
index 467c103a..5c8bb0ae 100644
--- a/app/models/credit_card.rb
+++ b/app/models/credit_card.rb
@@ -1,3 +1,15 @@
class CreditCard < ApplicationRecord
include Accountable
+
+ def available_credit_money
+ available_credit ? Money.new(available_credit, account.currency) : nil
+ end
+
+ def minimum_payment_money
+ minimum_payment ? Money.new(minimum_payment, account.currency) : nil
+ end
+
+ def annual_fee_money
+ annual_fee ? Money.new(annual_fee, account.currency) : nil
+ end
end
diff --git a/app/models/loan.rb b/app/models/loan.rb
index cc6dbcb5..11eb3058 100644
--- a/app/models/loan.rb
+++ b/app/models/loan.rb
@@ -3,12 +3,12 @@ class Loan < ApplicationRecord
def monthly_payment
return nil if term_months.nil? || interest_rate.nil? || rate_type.nil? || rate_type != "fixed"
- return Money.new(0, account.currency) if account.original_balance.zero? || term_months.zero?
+ return Money.new(0, account.currency) if account.original_balance.amount.zero? || term_months.zero?
annual_rate = interest_rate / 100.0
monthly_rate = annual_rate / 12.0
- payment = (account.original_balance * monthly_rate * (1 + monthly_rate)**term_months) / ((1 + monthly_rate)**term_months - 1)
+ payment = (account.original_balance.amount * monthly_rate * (1 + monthly_rate)**term_months) / ((1 + monthly_rate)**term_months - 1)
Money.new(payment.round, account.currency)
end
diff --git a/app/views/accounts/accountables/credit_card/_overview.html.erb b/app/views/accounts/accountables/credit_card/_overview.html.erb
index fcedf192..10864d04 100644
--- a/app/views/accounts/accountables/credit_card/_overview.html.erb
+++ b/app/views/accounts/accountables/credit_card/_overview.html.erb
@@ -2,15 +2,15 @@
<div class="grid grid-cols-3 gap-2">
<%= summary_card title: t(".amount_owed") do %>
- <%= format_money(account.balance) %>
+ <%= format_money(account.balance_money) %>
<% end %>
<%= summary_card title: t(".available_credit") do %>
- <%= format_money(account.credit_card.available_credit) || t(".unknown") %>
+ <%= format_money(account.credit_card.available_credit_money) || t(".unknown") %>
<% end %>
<%= summary_card title: t(".minimum_payment") do %>
- <%= format_money(account.credit_card.minimum_payment) || t(".unknown") %>
+ <%= format_money(account.credit_card.minimum_payment_money) || Money.new(0, account.currency) %>
<% end %>
<%= summary_card title: t(".apr") do %>
@@ -22,6 +22,6 @@
<% end %>
<%= summary_card title: t(".annual_fee") do %>
- <%= format_money(account.credit_card.annual_fee) || t(".unknown") %>
+ <%= format_money(account.credit_card.annual_fee_money) || Money.new(0, account.currency) %>
<% end %>
</div>
diff --git a/app/views/accounts/accountables/loan/_overview.html.erb b/app/views/accounts/accountables/loan/_overview.html.erb
index e71caf58..1ab8f282 100644
--- a/app/views/accounts/accountables/loan/_overview.html.erb
+++ b/app/views/accounts/accountables/loan/_overview.html.erb
@@ -6,7 +6,7 @@
<% end %>
<%= summary_card title: t(".remaining_principal") do %>
- <%= format_money account.balance %>
+ <%= format_money account.balance_money %>
<% end %>
<%= summary_card title: t(".interest_rate") do %>
diff --git a/app/views/accounts/show.html.erb b/app/views/accounts/show.html.erb
index 78825eec..b80a0581 100644
--- a/app/views/accounts/show.html.erb
+++ b/app/views/accounts/show.html.erb
@@ -7,7 +7,7 @@
<div>
<h2 class="font-medium text-xl"><%= @account.name %></h2>
- <% if @account.property? && @account.property.address %>
+ <% if @account.property? && @account.property.address&.line1.present? %>
<p class="text-gray-500"><%= @account.property.address %></p>
<% end %>
</div>