1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 21:29:38 +02:00

Basic trade and holdings view (#1271)

* Add trade view

* Lint fix

* Fix stale placeholder variable

* Add holding view
This commit is contained in:
Zach Gollwitzer 2024-10-09 14:59:18 -04:00 committed by GitHub
parent f5cb13b42f
commit 4bfe47540d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 387 additions and 68 deletions

View file

@ -25,7 +25,7 @@ class Account::EntriesController < ApplicationController
def destroy def destroy
@entry.destroy! @entry.destroy!
@entry.sync_account_later @entry.sync_account_later
redirect_back_or_to account_url(@entry.account), notice: t(".success") redirect_to account_url(@entry.account), notice: t(".success")
end end
private private

View file

@ -2,7 +2,7 @@ class Account::HoldingsController < ApplicationController
layout :with_sidebar layout :with_sidebar
before_action :set_account before_action :set_account
before_action :set_holding, only: :show before_action :set_holding, only: %i[show destroy]
def index def index
@holdings = @account.holdings.current @holdings = @account.holdings.current
@ -11,6 +11,11 @@ class Account::HoldingsController < ApplicationController
def show def show
end end
def destroy
@holding.destroy_holding_and_entries!
redirect_back_or_to account_holdings_path(@account)
end
private private
def set_account def set_account

View file

@ -2,6 +2,7 @@ class Account::TradesController < ApplicationController
layout :with_sidebar layout :with_sidebar
before_action :set_account before_action :set_account
before_action :set_entry, only: :update
def new def new
@entry = @account.entries.account_trades.new(entryable_attributes: {}) @entry = @account.entries.account_trades.new(entryable_attributes: {})
@ -23,15 +24,36 @@ class Account::TradesController < ApplicationController
end end
end end
def update
@entry.update!(entry_params)
respond_to do |format|
format.html { redirect_to account_entry_path(@account, @entry), notice: t(".success") }
format.turbo_stream { render turbo_stream: turbo_stream.replace(@entry) }
end
end
private private
def set_account def set_account
@account = Current.family.accounts.find(params[:account_id]) @account = Current.family.accounts.find(params[:account_id])
end end
def set_entry
@entry = @account.entries.find(params[:id])
end
def entry_params def entry_params
params.require(:account_entry) params.require(:account_entry)
.permit(:type, :date, :qty, :ticker, :price, :amount, :currency, :transfer_account_id) .permit(
:type, :date, :qty, :ticker, :price, :amount, :notes, :excluded, :currency, :transfer_account_id, :entryable_type,
entryable_attributes: [
:id,
:qty,
:ticker,
:price
]
)
.merge(account: @account) .merge(account: @account)
end end
end end

View file

@ -33,11 +33,9 @@ class Account::TransactionsController < ApplicationController
def entry_params def entry_params
params.require(:account_entry) params.require(:account_entry)
.permit( .permit(
:name, :date, :amount, :currency, :entryable_type, :nature, :name, :date, :amount, :currency, :excluded, :notes, :entryable_type, :nature,
entryable_attributes: [ entryable_attributes: [
:id, :id,
:notes,
:excluded,
:category_id, :category_id,
:merchant_id, :merchant_id,
{ tag_ids: [] } { tag_ids: [] }

View file

@ -39,11 +39,11 @@ class StyledFormBuilder < ActionView::Helpers::FormBuilder
build_styled_field(label, field, options, remove_padding_right: true) build_styled_field(label, field, options, remove_padding_right: true)
end end
def money_field(amount_method, currency_method, options = {}) def money_field(amount_method, options = {})
@template.render partial: "shared/money_field", locals: { @template.render partial: "shared/money_field", locals: {
form: self, form: self,
amount_method:, amount_method:,
currency_method:, currency_method: options[:currency_method] || :currency,
**options **options
} }
end end

View file

@ -109,8 +109,8 @@ class Account::Entry < ApplicationRecord
def bulk_update!(bulk_update_params) def bulk_update!(bulk_update_params)
bulk_attributes = { bulk_attributes = {
date: bulk_update_params[:date], date: bulk_update_params[:date],
entryable_attributes: {
notes: bulk_update_params[:notes], notes: bulk_update_params[:notes],
entryable_attributes: {
category_id: bulk_update_params[:category_id], category_id: bulk_update_params[:category_id],
merchant_id: bulk_update_params[:merchant_id] merchant_id: bulk_update_params[:merchant_id]
}.compact_blank }.compact_blank

View file

@ -37,6 +37,19 @@ class Account::Holding < ApplicationRecord
@trend ||= calculate_trend @trend ||= calculate_trend
end end
def trades
account.entries.where(entryable: account.trades.where(security: security)).reverse_chronological
end
def destroy_holding_and_entries!
transaction do
account.entries.where(entryable: account.trades.where(security: security)).destroy_all
destroy
end
account.sync_later
end
private private
def calculate_trend def calculate_trend

View file

@ -25,4 +25,15 @@ class Account::Trade < ApplicationRecord
def buy? def buy?
qty > 0 qty > 0
end end
def unrealized_gain_loss
return nil if sell?
current_price = security.current_price
return nil if current_price.nil?
current_value = current_price * qty.abs
cost_basis = price_money * qty.abs
TimeSeries::Trend.new(current: current_value, previous: cost_basis)
end
end end

View file

@ -34,7 +34,8 @@ class MintImport < Import
amount: row.signed_amount, amount: row.signed_amount,
name: row.name, name: row.name,
currency: row.currency, currency: row.currency,
entryable: Account::Transaction.new(category: category, tags: tags, notes: row.notes), notes: row.notes,
entryable: Account::Transaction.new(category: category, tags: tags),
import: self import: self
entry.save! entry.save!

View file

@ -5,6 +5,12 @@ class Security < ApplicationRecord
validates :ticker, presence: true, uniqueness: { case_sensitive: false } validates :ticker, presence: true, uniqueness: { case_sensitive: false }
def current_price
@current_price ||= Security::Price.find_price(ticker:, date: Date.current)
return nil if @current_price.nil?
Money.new(@current_price.price, @current_price.currency)
end
private private
def upcase_ticker def upcase_ticker

View file

@ -13,7 +13,8 @@ class TransactionImport < Import
amount: row.signed_amount, amount: row.signed_amount,
name: row.name, name: row.name,
currency: row.currency, currency: row.currency,
entryable: Account::Transaction.new(category: category, tags: tags, notes: row.notes), notes: row.notes,
entryable: Account::Transaction.new(category: category, tags: tags),
import: self import: self
entry.save! entry.save!

View file

@ -9,36 +9,103 @@
<%= render "shared/circle_logo", name: @holding.name %> <%= render "shared/circle_logo", name: @holding.name %>
</header> </header>
<details class="group space-y-2"> <details class="group space-y-2" open>
<summary class="flex list-none items-center justify-between rounded-xl px-3 py-2 text-xs font-medium uppercase text-gray-500 bg-gray-25 focus-visible:outline-none"> <summary class="flex list-none items-center justify-between rounded-xl px-3 py-2 text-xs font-medium uppercase text-gray-500 bg-gray-25 focus-visible:outline-none">
<h4><%= t(".overview") %></h4> <h4><%= t(".overview") %></h4>
<%= lucide_icon "chevron-down", class: "group-open:transform group-open:rotate-180 text-gray-500 w-5" %> <%= lucide_icon "chevron-down", class: "group-open:transform group-open:rotate-180 text-gray-500 w-5" %>
</summary> </summary>
<div> <div class="pb-4">
<p class="pl-4 text-gray-500">Coming soon...</p> <dl class="space-y-3 px-3 py-2">
<div class="flex items-center justify-between text-sm">
<dt class="text-gray-500"><%= t(".ticker_label") %></dt>
<dd class="text-gray-900"><%= @holding.ticker %></dd>
</div>
<div class="flex items-center justify-between text-sm">
<dt class="text-gray-500"><%= t(".current_market_price_label") %></dt>
<dd class="text-gray-900"><%= @holding.security.current_price ? format_money(@holding.security.current_price) : t(".unknown") %></dd>
</div>
<div class="flex items-center justify-between text-sm">
<dt class="text-gray-500"><%= t(".portfolio_weight_label") %></dt>
<dd class="text-gray-900"><%= @holding.weight ? number_to_percentage(@holding.weight, precision: 2) : t(".unknown") %></dd>
</div>
<div class="flex items-center justify-between text-sm">
<dt class="text-gray-500"><%= t(".avg_cost_label") %></dt>
<dd class="text-gray-900"><%= @holding.avg_cost ? format_money(@holding.avg_cost) : t(".unknown") %></dd>
</div>
<div class="flex items-center justify-between text-sm">
<dt class="text-gray-500"><%= t(".trend_label") %></dt>
<dd style="color: <%= @holding.trend&.color %>;">
<%= @holding.trend ? render("shared/trend_change", trend: @holding.trend) : t(".unknown") %>
</dd>
</div>
</dl>
</div> </div>
</details> </details>
<details class="group space-y-2"> <details class="group space-y-2" open>
<summary class="flex list-none items-center justify-between rounded-xl px-3 py-2 text-xs font-medium uppercase text-gray-500 bg-gray-25 focus-visible:outline-none"> <summary class="flex list-none items-center justify-between rounded-xl px-3 py-2 text-xs font-medium uppercase text-gray-500 bg-gray-25 focus-visible:outline-none">
<h4><%= t(".history") %></h4> <h4><%= t(".history") %></h4>
<%= lucide_icon "chevron-down", class: "group-open:transform group-open:rotate-180 text-gray-500 w-5" %> <%= lucide_icon "chevron-down", class: "group-open:transform group-open:rotate-180 text-gray-500 w-5" %>
</summary> </summary>
<div class="space-y-2">
<div class="px-3 py-4">
<% if @holding.trades.any? %>
<ul class="space-y-2">
<% @holding.trades.each_with_index do |trade_entry, index| %>
<li class="flex gap-4 text-sm space-y-1">
<div class="flex flex-col items-center gap-1.5 pt-2">
<div class="rounded-full h-1.5 w-1.5 bg-gray-300"></div>
<% unless index == @holding.trades.length - 1 %>
<div class="h-12 w-px bg-alpha-black-200"></div>
<% end %>
</div>
<div> <div>
<p class="pl-4 text-gray-500">Coming soon...</p> <p class="text-gray-500 text-xs uppercase"><%= l(trade_entry.date, format: :long) %></p>
<p><%= t(
".trade_history_entry",
qty: trade_entry.account_trade.qty,
security: trade_entry.account_trade.security.ticker,
price: format_money(trade_entry.account_trade.price)
) %></p>
</div>
</li>
<% end %>
</ul>
<% else %>
<p class="text-gray-500">No trade history available for this holding.</p>
<% end %>
</div>
</div> </div>
</details> </details>
<details class="group space-y-2"> <details class="group space-y-2" open>
<summary class="flex list-none items-center justify-between rounded-xl px-3 py-2 text-xs font-medium uppercase text-gray-500 bg-gray-25 focus-visible:outline-none"> <summary class="flex list-none items-center justify-between rounded-xl px-3 py-2 text-xs font-medium uppercase text-gray-500 bg-gray-25 focus-visible:outline-none">
<h4><%= t(".settings") %></h4> <h4><%= t(".settings") %></h4>
<%= lucide_icon "chevron-down", class: "group-open:transform group-open:rotate-180 text-gray-500 w-5" %> <%= lucide_icon "chevron-down", class: "group-open:transform group-open:rotate-180 text-gray-500 w-5" %>
</summary> </summary>
<div> <div class="pb-4">
<p class="pl-4 text-gray-500">Coming soon...</p> <div class="flex items-center justify-between gap-2 p-3">
<div class="text-sm space-y-1">
<h4 class="text-gray-900"><%= t(".delete_title") %></h4>
<p class="text-gray-500"><%= t(".delete_subtitle") %></p>
</div>
<%= button_to t(".delete"),
account_holding_path(@holding.account, @holding),
method: :delete,
class: "rounded-lg px-3 py-2 text-red-500 text-sm font-medium border border-alpha-black-200",
data: { turbo_confirm: true, turbo_frame: "_top" } %>
</div>
</div> </div>
</details> </details>
</div> </div>

View file

@ -13,7 +13,7 @@
<%= form.date_field :date, label: true %> <%= form.date_field :date, label: true %>
<div data-trade-form-target="amountInput" hidden> <div data-trade-form-target="amountInput" hidden>
<%= form.money_field :amount, :currency, label: t(".amount"), disable_currency: true %> <%= form.money_field :amount, label: t(".amount"), disable_currency: true %>
</div> </div>
<div data-trade-form-target="transferAccountInput" hidden> <div data-trade-form-target="transferAccountInput" hidden>
@ -25,7 +25,7 @@
</div> </div>
<div data-trade-form-target="priceInput"> <div data-trade-form-target="priceInput">
<%= form.money_field :price, :currency, label: t(".price"), disable_currency: true %> <%= form.money_field :price, label: t(".price"), disable_currency: true %>
</div> </div>
</div> </div>

View file

@ -1,29 +1,146 @@
<% entry = @entry %> <% entry, trade, account = @entry, @entry.account_trade, @entry.account %>
<%= drawer do %> <%= drawer do %>
<div>
<header class="mb-4 space-y-1"> <header class="mb-4 space-y-1">
<div class="flex items-center gap-4"> <div class="flex items-center gap-4">
<h3 class="font-medium"> <h3 class="font-medium">
<span class="text-2xl"><%= format_money -entry.amount_money %></span> <span class="text-2xl">
<span class="text-lg text-gray-500"><%= entry.currency %></span> <%= format_money -entry.amount_money %>
</span>
<span class="text-lg text-gray-500">
<%= entry.currency %>
</span>
</h3> </h3>
</div> </div>
<span class="text-sm text-gray-500"><%= entry.date.strftime("%A %d %B") %></span> <span class="text-sm text-gray-500">
<%= I18n.l(entry.date, format: :long) %>
</span>
</header> </header>
<div class="space-y-2"> <div class="space-y-2">
<details class="group space-y-2" open> <!-- Overview Section -->
<summary class="flex list-none items-center justify-between rounded-xl px-3 py-2 text-xs font-medium uppercase text-gray-500 bg-gray-25 focus-visible:outline-none"> <%= disclosure t(".overview") do %>
<h4><%= t(".overview") %></h4> <div class="pb-4">
<%= lucide_icon "chevron-down", class: "group-open:transform group-open:rotate-180 text-gray-500 w-5" %> <dl class="space-y-3 px-3 py-2">
</summary> <div class="flex items-center justify-between text-sm">
<dt class="text-gray-500"><%= t(".symbol_label") %></dt>
<dd class="text-gray-900"><%= trade.security.ticker %></dd>
</div>
<div class="pb-6 pl-4 text-gray-500"> <% if trade.buy? %>
<p>Details coming soon...</p> <div class="flex items-center justify-between text-sm">
<dt class="text-gray-500"><%= t(".purchase_qty_label") %></dt>
<dd class="text-gray-900"><%= trade.qty.abs %></dd>
</div> </div>
</details>
<div class="flex items-center justify-between text-sm">
<dt class="text-gray-500"><%= t(".purchase_price_label") %></dt>
<dd class="text-gray-900"><%= format_money trade.price_money %></dd>
</div> </div>
<% end %>
<div class="flex items-center justify-between text-sm">
<dt class="text-gray-500"><%= t(".current_market_price_label") %></dt>
<dd class="text-gray-900"><%= format_money trade.security.current_price %></dd>
</div>
<% if trade.buy? %>
<div class="flex items-center justify-between text-sm">
<dt class="text-gray-500"><%= t(".total_return_label") %></dt>
<dd style="color: <%= trade.unrealized_gain_loss.color %>;">
<%= render "shared/trend_change", trend: trade.unrealized_gain_loss %>
</dd>
</div>
<% end %>
</dl>
</div>
<% end %>
<!-- Details Section -->
<%= disclosure t(".details") do %>
<div class="pb-4">
<%= styled_form_with model: [account, entry],
url: account_trade_path(account, entry),
class: "space-y-2",
data: { controller: "auto-submit-form" } do |f| %>
<%= f.date_field :date,
label: t(".date_label"),
max: Date.current,
"data-auto-submit-form-target": "auto" %>
<%= f.fields_for :entryable do |ef| %>
<%= ef.number_field :qty,
label: t(".quantity_label"),
step: "any",
"data-auto-submit-form-target": "auto" %>
<%= ef.money_field :price,
label: t(".cost_per_share_label"),
disable_currency: true,
auto_submit: true,
min: 0 %>
<% end %>
<% end %>
</div>
<% end %>
<!-- Additional Section -->
<%= disclosure t(".additional") do %>
<div class="pb-4">
<%= styled_form_with model: [account, entry],
url: account_trade_path(account, entry),
class: "space-y-2",
data: { controller: "auto-submit-form" } do |f| %>
<%= f.text_area :notes,
label: t(".note_label"),
placeholder: t(".note_placeholder"),
rows: 5,
"data-auto-submit-form-target": "auto" %>
<% end %>
</div>
<% end %>
<!-- Settings Section -->
<%= disclosure t(".settings") do %>
<div class="pb-4">
<!-- Exclude Trade Form -->
<%= styled_form_with model: [account, entry],
url: account_trade_path(account, entry),
class: "p-3",
data: { controller: "auto-submit-form" } do |f| %>
<div class="flex cursor-pointer items-center gap-2 justify-between">
<div class="text-sm space-y-1">
<h4 class="text-gray-900"><%= t(".exclude_title") %></h4>
<p class="text-gray-500"><%= t(".exclude_subtitle") %></p>
</div>
<div class="relative inline-block select-none">
<%= f.check_box :excluded,
class: "sr-only peer",
"data-auto-submit-form-target": "auto" %>
<label for="account_entry_excluded"
class="maybe-switch"></label>
</div>
</div>
<% end %>
<!-- Delete Trade Form -->
<div class="flex items-center justify-between gap-2 p-3">
<div class="text-sm space-y-1">
<h4 class="text-gray-900"><%= t(".delete_title") %></h4>
<p class="text-gray-500"><%= t(".delete_subtitle") %></p>
</div>
<%= button_to t(".delete"),
account_entry_path(account, entry),
method: :delete,
class: "rounded-lg px-3 py-2 text-red-500 text-sm
font-medium border border-alpha-black-200",
data: { turbo_confirm: true, turbo_frame: "_top" } %>
</div>
</div>
<% end %>
</div> </div>
<% end %> <% end %>

View file

@ -47,7 +47,7 @@
{ container_class: "w-1/3", label: t(".nature"), selected: entry.amount.negative? ? "income" : "expense" }, { container_class: "w-1/3", label: t(".nature"), selected: entry.amount.negative? ? "income" : "expense" },
{ data: { "auto-submit-form-target": "auto" } } %> { data: { "auto-submit-form-target": "auto" } } %>
<%= f.money_field :amount, :currency, label: t(".amount"), <%= f.money_field :amount, label: t(".amount"),
container_class: "w-2/3", container_class: "w-2/3",
auto_submit: true, auto_submit: true,
min: 0, min: 0,
@ -104,7 +104,13 @@
}, },
{ "data-auto-submit-form-target": "auto" } %> { "data-auto-submit-form-target": "auto" } %>
<%= ef.text_area :notes, <% end %>
<%= styled_form_with model: [account, entry],
url: account_transaction_path(account, entry),
class: "space-y-2",
data: { controller: "auto-submit-form" } do |f| %>
<%= f.text_area :notes,
label: t(".note_label"), label: t(".note_label"),
placeholder: t(".note_placeholder"), placeholder: t(".note_placeholder"),
rows: 5, rows: 5,
@ -122,7 +128,6 @@
url: account_transaction_path(account, entry), url: account_transaction_path(account, entry),
class: "p-3", class: "p-3",
data: { controller: "auto-submit-form" } do |f| %> data: { controller: "auto-submit-form" } do |f| %>
<%= f.fields_for :entryable do |ef| %>
<div class="flex cursor-pointer items-center gap-2 justify-between"> <div class="flex cursor-pointer items-center gap-2 justify-between">
<div class="text-sm space-y-1"> <div class="text-sm space-y-1">
<h4 class="text-gray-900"><%= t(".exclude_title") %></h4> <h4 class="text-gray-900"><%= t(".exclude_title") %></h4>
@ -130,7 +135,7 @@
</div> </div>
<div class="relative inline-block select-none"> <div class="relative inline-block select-none">
<%= ef.check_box :excluded, <%= f.check_box :excluded,
class: "sr-only peer", class: "sr-only peer",
"data-auto-submit-form-target": "auto" %> "data-auto-submit-form-target": "auto" %>
<label for="account_entry_entryable_attributes_excluded" <label for="account_entry_entryable_attributes_excluded"
@ -138,7 +143,6 @@
</div> </div>
</div> </div>
<% end %> <% end %>
<% end %>
<!-- Delete Transaction Form --> <!-- Delete Transaction Form -->
<% unless entry.marked_as_transfer? %> <% unless entry.marked_as_transfer? %>

View file

@ -29,7 +29,7 @@
<%= f.text_field :name, value: transfer.name, label: t(".description"), placeholder: t(".description_placeholder"), required: true %> <%= f.text_field :name, value: transfer.name, label: t(".description"), placeholder: t(".description_placeholder"), required: true %>
<%= f.collection_select :from_account_id, Current.family.accounts.alphabetically, :id, :name, { prompt: t(".select_account"), label: t(".from") }, required: true %> <%= f.collection_select :from_account_id, Current.family.accounts.alphabetically, :id, :name, { prompt: t(".select_account"), label: t(".from") }, required: true %>
<%= f.collection_select :to_account_id, Current.family.accounts.alphabetically, :id, :name, { prompt: t(".select_account"), label: t(".to") }, required: true %> <%= f.collection_select :to_account_id, Current.family.accounts.alphabetically, :id, :name, { prompt: t(".select_account"), label: t(".to") }, required: true %>
<%= f.money_field :amount, :currency, label: t(".amount"), required: true, hide_currency: true %> <%= f.money_field :amount, label: t(".amount"), required: true, hide_currency: true %>
<%= f.date_field :date, value: transfer.date, label: t(".date"), required: true, max: Date.current %> <%= f.date_field :date, value: transfer.date, label: t(".date"), required: true, max: Date.current %>
</section> </section>

View file

@ -5,7 +5,7 @@
<%= f.hidden_field :accountable_type %> <%= f.hidden_field :accountable_type %>
<%= f.text_field :name, placeholder: t(".name_placeholder"), required: "required", label: t(".name_label"), autofocus: true %> <%= f.text_field :name, placeholder: t(".name_placeholder"), required: "required", label: t(".name_label"), autofocus: true %>
<%= f.collection_select :institution_id, Current.family.institutions.alphabetically, :id, :name, { include_blank: t(".ungrouped"), label: t(".institution") } %> <%= f.collection_select :institution_id, Current.family.institutions.alphabetically, :id, :name, { include_blank: t(".ungrouped"), label: t(".institution") } %>
<%= f.money_field :balance, :currency, label: t(".balance"), required: true, default_currency: Current.family.currency %> <%= f.money_field :balance, label: t(".balance"), required: true, default_currency: Current.family.currency %>
<% if account.new_record? %> <% if account.new_record? %>
<div class="flex items-center gap-2 mt-3 mb-6"> <div class="flex items-center gap-2 mt-3 mb-6">

View file

@ -13,7 +13,7 @@
<section class="space-y-2"> <section class="space-y-2">
<%= f.text_field :name, label: t(".description"), placeholder: t(".description_placeholder"), required: true %> <%= f.text_field :name, label: t(".description"), placeholder: t(".description_placeholder"), required: true %>
<%= f.collection_select :account_id, Current.family.accounts.alphabetically, :id, :name, { prompt: t(".account_prompt"), label: t(".account") }, required: true %> <%= f.collection_select :account_id, Current.family.accounts.alphabetically, :id, :name, { prompt: t(".account_prompt"), label: t(".account") }, required: true %>
<%= f.money_field :amount, :currency, label: t(".amount"), required: true %> <%= f.money_field :amount, label: t(".amount"), required: true %>
<%= f.hidden_field :entryable_type, value: "Account::Transaction" %> <%= f.hidden_field :entryable_type, value: "Account::Transaction" %>
<%= f.fields_for :entryable do |ef| %> <%= f.fields_for :entryable do |ef| %>
<%= ef.collection_select :category_id, Current.family.categories.alphabetically, :id, :name, { prompt: t(".category_prompt"), label: t(".category") } %> <%= ef.collection_select :category_id, Current.family.categories.alphabetically, :id, :name, { prompt: t(".category_prompt"), label: t(".category") } %>

View file

@ -20,6 +20,17 @@ en:
its returns or value. its returns or value.
missing_data: Missing data missing_data: Missing data
show: show:
avg_cost_label: Average Cost
current_market_price_label: Current Market Price
delete: Delete
delete_subtitle: This will delete the holding and all your associated trades
on this account. This action cannot be undone.
delete_title: Delete holding
history: History history: History
overview: Overview overview: Overview
portfolio_weight_label: Portfolio Weight
settings: Settings settings: Settings
ticker_label: Ticker
trade_history_entry: "%{qty} shares of %{security} at %{price}"
trend_label: Trend
unknown: Unknown

View file

@ -25,7 +25,25 @@ en:
new: new:
title: New transaction title: New transaction
show: show:
additional: Additional
cost_per_share_label: Cost per Share
current_market_price_label: Current Market Price
date_label: Date
delete: Delete
delete_subtitle: This action cannot be undone
delete_title: Delete Trade
details: Details
exclude_subtitle: This trade will not be included in reports and calculations
exclude_title: Exclude from analytics
note_label: Note
note_placeholder: Add any additional notes here...
overview: Overview overview: Overview
purchase_price_label: Purchase Price
purchase_qty_label: Purchase Quantity
quantity_label: Quantity
settings: Settings
symbol_label: Symbol
total_return_label: Unrealized gain/loss
trade: trade:
buy: Buy buy: Buy
deposit: Deposit deposit: Deposit
@ -33,3 +51,5 @@ en:
outflow: Outflow outflow: Outflow
sell: Sell sell: Sell
withdrawal: Withdrawal withdrawal: Withdrawal
update:
success: Trade updated successfully.

View file

@ -63,12 +63,12 @@ Rails.application.routes.draw do
scope module: :account do scope module: :account do
resource :logo, only: :show resource :logo, only: :show
resources :holdings, only: %i[index new show] resources :holdings, only: %i[index new show destroy]
resources :cashes, only: :index resources :cashes, only: :index
resources :transactions, only: %i[index update] resources :transactions, only: %i[index update]
resources :valuations, only: %i[index new create] resources :valuations, only: %i[index new create]
resources :trades, only: %i[index new create] resources :trades, only: %i[index new create update]
resources :entries, only: %i[edit update show destroy] resources :entries, only: %i[edit update show destroy]
end end

View file

@ -0,0 +1,33 @@
class AddNotesToEntry < ActiveRecord::Migration[7.2]
def change
add_column :account_entries, :notes, :text
add_column :account_entries, :excluded, :boolean, default: false
reversible do |dir|
dir.up do
execute <<-SQL
UPDATE account_entries
SET notes = account_transactions.notes,
excluded = account_transactions.excluded
FROM account_transactions
WHERE account_entries.entryable_type = 'Account::Transaction'
AND account_entries.entryable_id = account_transactions.id
SQL
end
dir.down do
execute <<-SQL
UPDATE account_transactions
SET notes = account_entries.notes,
excluded = account_entries.excluded
FROM account_entries
WHERE account_entries.entryable_type = 'Account::Transaction'
AND account_entries.entryable_id = account_transactions.id
SQL
end
end
remove_column :account_transactions, :notes, :text
remove_column :account_transactions, :excluded, :boolean
end
end

8
db/schema.rb generated
View file

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.2].define(version: 2024_10_08_122449) do ActiveRecord::Schema[7.2].define(version: 2024_10_09_132959) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto" enable_extension "pgcrypto"
enable_extension "plpgsql" enable_extension "plpgsql"
@ -45,6 +45,8 @@ ActiveRecord::Schema[7.2].define(version: 2024_10_08_122449) do
t.uuid "transfer_id" t.uuid "transfer_id"
t.boolean "marked_as_transfer", default: false, null: false t.boolean "marked_as_transfer", default: false, null: false
t.uuid "import_id" t.uuid "import_id"
t.text "notes"
t.boolean "excluded", default: false
t.index ["account_id"], name: "index_account_entries_on_account_id" t.index ["account_id"], name: "index_account_entries_on_account_id"
t.index ["import_id"], name: "index_account_entries_on_import_id" t.index ["import_id"], name: "index_account_entries_on_import_id"
t.index ["transfer_id"], name: "index_account_entries_on_transfer_id" t.index ["transfer_id"], name: "index_account_entries_on_transfer_id"
@ -90,8 +92,6 @@ ActiveRecord::Schema[7.2].define(version: 2024_10_08_122449) do
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.uuid "category_id" t.uuid "category_id"
t.boolean "excluded", default: false
t.text "notes"
t.uuid "merchant_id" t.uuid "merchant_id"
t.index ["category_id"], name: "index_account_transactions_on_category_id" t.index ["category_id"], name: "index_account_transactions_on_category_id"
t.index ["merchant_id"], name: "index_account_transactions_on_merchant_id" t.index ["merchant_id"], name: "index_account_transactions_on_merchant_id"
@ -120,7 +120,7 @@ ActiveRecord::Schema[7.2].define(version: 2024_10_08_122449) do
t.boolean "is_active", default: true, null: false t.boolean "is_active", default: true, null: false
t.date "last_sync_date" t.date "last_sync_date"
t.uuid "institution_id" t.uuid "institution_id"
t.virtual "classification", type: :string, as: "\nCASE\n WHEN ((accountable_type)::text = ANY (ARRAY[('Loan'::character varying)::text, ('CreditCard'::character varying)::text, ('OtherLiability'::character varying)::text])) THEN 'liability'::text\n ELSE 'asset'::text\nEND", stored: true t.virtual "classification", type: :string, as: "\nCASE\n WHEN ((accountable_type)::text = ANY ((ARRAY['Loan'::character varying, 'CreditCard'::character varying, 'OtherLiability'::character varying])::text[])) THEN 'liability'::text\n ELSE 'asset'::text\nEND", stored: true
t.uuid "import_id" t.uuid "import_id"
t.index ["accountable_type"], name: "index_accounts_on_accountable_type" t.index ["accountable_type"], name: "index_accounts_on_accountable_type"
t.index ["family_id"], name: "index_accounts_on_family_id" t.index ["family_id"], name: "index_accounts_on_family_id"

View file

@ -17,4 +17,14 @@ class Account::HoldingsControllerTest < ActionDispatch::IntegrationTest
assert_response :success assert_response :success
end end
test "destroys holding and associated entries" do
assert_difference -> { Account::Holding.count } => -1,
-> { Account::Entry.count } => -1 do
delete account_holding_path(@account, @holding)
end
assert_redirected_to account_holdings_path(@account)
assert_empty @account.entries.where(entryable: @account.trades.where(security: @holding.security))
end
end end

View file

@ -174,7 +174,7 @@ class TransactionsControllerTest < ActionDispatch::IntegrationTest
assert_equal 1.day.ago.to_date, transaction.date assert_equal 1.day.ago.to_date, transaction.date
assert_equal Category.second, transaction.account_transaction.category assert_equal Category.second, transaction.account_transaction.category
assert_equal Merchant.second, transaction.account_transaction.merchant assert_equal Merchant.second, transaction.account_transaction.merchant
assert_equal "Updated note", transaction.account_transaction.notes assert_equal "Updated note", transaction.notes
end end
end end
end end