Skip to content
This repository was archived by the owner on Jul 27, 2025. It is now read-only.

Commit d2debd8

Browse files
authored
Merge branch 'maybe-finance:main' into bugfix/ui-pwa-ios
2 parents 08fd6f9 + 9110ab2 commit d2debd8

File tree

17 files changed

+221
-34
lines changed

17 files changed

+221
-34
lines changed

app/components/button_component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<%= container do %>
22
<% if icon && (icon_position != :right) %>
3-
<%= helpers.icon(icon, size: size, color: icon_color) %>
3+
<%= helpers.icon(icon, size: size, color: icon_color, class: icon_classes) %>
44
<% end %>
55

66
<% unless icon_only? %>

app/components/buttonish_component.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class ButtonishComponent < ViewComponent::Base
55
icon_classes: "fg-inverse"
66
},
77
secondary: {
8-
container_classes: "text-secondary bg-gray-50 theme-dark:bg-gray-700 hover:bg-gray-100 theme-dark:hover:bg-gray-600 disabled:bg-gray-200 theme-dark:disabled:bg-gray-600",
8+
container_classes: "text-primary bg-gray-50 theme-dark:bg-gray-700 hover:bg-gray-100 theme-dark:hover:bg-gray-600 disabled:bg-gray-200 theme-dark:disabled:bg-gray-600",
99
icon_classes: "fg-primary"
1010
},
1111
destructive: {

app/models/account.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ def create_and_sync(attributes)
6464
transaction do
6565
# Create 2 valuations for new accounts to establish a value history for users to see
6666
account.entries.build(
67-
name: "Current Balance",
67+
name: Valuation.build_current_anchor_name(account.accountable_type),
6868
date: Date.current,
6969
amount: account.balance,
7070
currency: account.currency,
7171
entryable: Valuation.new
7272
)
7373
account.entries.build(
74-
name: "Initial Balance",
74+
name: Valuation.build_opening_anchor_name(account.accountable_type),
7575
date: 1.day.ago.to_date,
7676
amount: initial_balance,
7777
currency: account.currency,

app/models/account/balance_updater.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def update
2323

2424
valuation_entry.amount = balance
2525
valuation_entry.currency = currency if currency.present?
26-
valuation_entry.name = "Manual #{account.accountable.balance_display_name} update"
26+
valuation_entry.name = Valuation.build_reconciliation_name(account.accountable_type)
2727
valuation_entry.notes = notes if notes.present?
2828
valuation_entry.save!
2929
end

app/models/account_import.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def import!
1818
account.entries.create!(
1919
amount: row.amount,
2020
currency: row.currency,
21-
date: Date.current,
22-
name: "Imported account value",
21+
date: 2.years.ago.to_date,
22+
name: Valuation.build_opening_anchor_name(account.accountable_type),
2323
entryable: Valuation.new
2424
)
2525
end

app/models/demo/generator.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ def reconcile_balances!(family)
11761176
@home.entries.create!(
11771177
entryable: Valuation.new,
11781178
amount: 350_000,
1179-
name: "Current Market Value",
1179+
name: Valuation.build_current_anchor_name(@home.accountable_type),
11801180
currency: "USD",
11811181
date: Date.current
11821182
)
@@ -1185,31 +1185,31 @@ def reconcile_balances!(family)
11851185
@honda_accord.entries.create!(
11861186
entryable: Valuation.new,
11871187
amount: 18_000,
1188-
name: "Current Market Value",
1188+
name: Valuation.build_current_anchor_name(@honda_accord.accountable_type),
11891189
currency: "USD",
11901190
date: Date.current
11911191
)
11921192

11931193
@tesla_model3.entries.create!(
11941194
entryable: Valuation.new,
11951195
amount: 4_500,
1196-
name: "Current Market Value",
1196+
name: Valuation.build_current_anchor_name(@tesla_model3.accountable_type),
11971197
currency: "USD",
11981198
date: Date.current
11991199
)
12001200

12011201
@jewelry.entries.create!(
12021202
entryable: Valuation.new,
12031203
amount: 2000,
1204-
name: "Current Market Value",
1204+
name: Valuation.build_reconciliation_name(@jewelry.accountable_type),
12051205
currency: "USD",
12061206
date: 90.days.ago.to_date
12071207
)
12081208

12091209
@personal_loc.entries.create!(
12101210
entryable: Valuation.new,
12111211
amount: 800,
1212-
name: "Owed",
1212+
name: Valuation.build_reconciliation_name(@personal_loc.accountable_type),
12131213
currency: "USD",
12141214
date: 120.days.ago.to_date
12151215
)

app/models/trade.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ class Trade < ApplicationRecord
88
validates :qty, presence: true
99
validates :price, :currency, presence: true
1010

11+
class << self
12+
def build_name(type, qty, ticker)
13+
prefix = type == "buy" ? "Buy" : "Sell"
14+
"#{prefix} #{qty.to_d.abs} shares of #{ticker}"
15+
end
16+
end
17+
1118
def unrealized_gain_loss
1219
return nil if qty.negative?
1320
current_price = security.current_price

app/models/trade/create_form.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,11 @@ def security
2929
end
3030

3131
def create_trade
32-
prefix = type == "sell" ? "Sell " : "Buy "
33-
trade_name = prefix + "#{qty.to_i.abs} shares of #{security.ticker}"
3432
signed_qty = type == "sell" ? -qty.to_d : qty.to_d
3533
signed_amount = signed_qty * price.to_d
3634

3735
trade_entry = account.entries.new(
38-
name: trade_name,
36+
name: Trade.build_name(type, qty, security.ticker),
3937
date: date,
4038
amount: signed_amount,
4139
currency: currency,

app/models/valuation.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
11
class Valuation < ApplicationRecord
22
include Entryable
3+
4+
class << self
5+
def build_reconciliation_name(accountable_type)
6+
Valuation::Name.new("reconciliation", accountable_type).to_s
7+
end
8+
9+
def build_opening_anchor_name(accountable_type)
10+
Valuation::Name.new("opening_anchor", accountable_type).to_s
11+
end
12+
13+
def build_current_anchor_name(accountable_type)
14+
Valuation::Name.new("current_anchor", accountable_type).to_s
15+
end
16+
end
17+
18+
# TODO: Remove this method when `kind` column is added to valuations table
19+
# This is a temporary implementation until the database migration is complete
20+
def kind
21+
"reconciliation"
22+
end
323
end

app/models/valuation/name.rb

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
class Valuation::Name
2+
def initialize(valuation_kind, accountable_type)
3+
@valuation_kind = valuation_kind
4+
@accountable_type = accountable_type
5+
end
6+
7+
def to_s
8+
case valuation_kind
9+
when "opening_anchor"
10+
opening_anchor_name
11+
when "current_anchor"
12+
current_anchor_name
13+
else
14+
recon_name
15+
end
16+
end
17+
18+
private
19+
attr_reader :valuation_kind, :accountable_type
20+
21+
def opening_anchor_name
22+
case accountable_type
23+
when "Property"
24+
"Original purchase price"
25+
when "Loan"
26+
"Original principal"
27+
when "Investment"
28+
"Opening account value"
29+
else
30+
"Opening balance"
31+
end
32+
end
33+
34+
def current_anchor_name
35+
case accountable_type
36+
when "Property"
37+
"Current market value"
38+
when "Loan"
39+
"Current loan balance"
40+
when "Investment"
41+
"Current account value"
42+
else
43+
"Current balance"
44+
end
45+
end
46+
47+
def recon_name
48+
case accountable_type
49+
when "Property", "Investment"
50+
"Manual value update"
51+
when "Loan"
52+
"Manual principal update"
53+
else
54+
"Manual balance update"
55+
end
56+
end
57+
end

0 commit comments

Comments
 (0)