Skip to content

armgit / maybe

Public Imported from GitHub
0

The personal finance app for everyone

Account:: namespace simplifications and cleanup (#2110)

Zach Gollwitzere657c40d1950
diff --git a/.cursor/rules/project-conventions.mdc b/.cursor/rules/project-conventions.mdc
index 2977dc33..17cee2e0 100644
--- a/.cursor/rules/project-conventions.mdc
+++ b/.cursor/rules/project-conventions.mdc
@@ -71,7 +71,7 @@ Due to the open-source nature of this project, we have chosen Minitest + Fixture
- Always use Minitest and fixtures for testing.
- Keep fixtures to a minimum. Most models should have 2-3 fixtures maximum that represent the "base cases" for that model. "Edge cases" should be created on the fly, within the context of the test which it is needed.
-- For tests that require a large number of fixture records to be created, use Rails helpers such as [entries_test_helper.rb](mdc:test/support/account/entries_test_helper.rb) to act as a "factory" for creating these. For a great example of this, check out [forward_calculator_test.rb](mdc:test/models/account/balance/forward_calculator_test.rb)
+- For tests that require a large number of fixture records to be created, use Rails helpers such as [entries_test_helper.rb](mdc:test/support/entries_test_helper.rb) to act as a "factory" for creating these. For a great example of this, check out [forward_calculator_test.rb](mdc:test/models/account/balance/forward_calculator_test.rb)
- Take a minimal approach to testing—only test the absolutely critical code paths that will significantly increase developer confidence
#### Convention 5a: Write minimal, effective tests
@@ -87,26 +87,26 @@ Below are examples of necessary vs. unnecessary tests:
# GOOD!!
# Necessary test - in this case, we're testing critical domain business logic
test "syncs balances" do
- Account::Holding::Syncer.any_instance.expects(:sync_holdings).returns([]).once
+ Holding::Syncer.any_instance.expects(:sync_holdings).returns([]).once
@account.expects(:start_date).returns(2.days.ago.to_date)
- Account::Balance::ForwardCalculator.any_instance.expects(:calculate).returns(
+ Balance::ForwardCalculator.any_instance.expects(:calculate).returns(
[
- Account::Balance.new(date: 1.day.ago.to_date, balance: 1000, cash_balance: 1000, currency: "USD"),
- Account::Balance.new(date: Date.current, balance: 1000, cash_balance: 1000, currency: "USD")
+ Balance.new(date: 1.day.ago.to_date, balance: 1000, cash_balance: 1000, currency: "USD"),
+ Balance.new(date: Date.current, balance: 1000, cash_balance: 1000, currency: "USD")
]
)
assert_difference "@account.balances.count", 2 do
- Account::Balance::Syncer.new(@account, strategy: :forward).sync_balances
+ Balance::Syncer.new(@account, strategy: :forward).sync_balances
end
end
# BAD!!
# Unnecessary test - in this case, this is simply testing ActiveRecord's functionality
test "saves balance" do
- balance_record = Account::Balance.new(balance: 100, currency: "USD")
+ balance_record = Balance.new(balance: 100, currency: "USD")
assert balance_record.save
end
diff --git a/.cursor/rules/project-design.mdc b/.cursor/rules/project-design.mdc
index 41fa2210..b2d13e9f 100644
--- a/.cursor/rules/project-design.mdc
+++ b/.cursor/rules/project-design.mdc
@@ -55,29 +55,29 @@ All balances are calculated daily by [balance_calculator.rb](mdc:app/models/acco
### Account Holdings
-An account [holding.rb](mdc:app/models/account/holding.rb) applies to [investment.rb](mdc:app/models/investment.rb) type accounts and represents a `qty` of a certain [security.rb](mdc:app/models/security.rb) at a specific `price` on a specific `date`.
+An account [holding.rb](mdc:app/models/holding.rb) applies to [investment.rb](mdc:app/models/investment.rb) type accounts and represents a `qty` of a certain [security.rb](mdc:app/models/security.rb) at a specific `price` on a specific `date`.
-For investment accounts with holdings, [holding_calculator.rb](mdc:app/models/account/holding_calculator.rb) is used to calculate the daily historical holding quantities and prices, which are then rolled up into a final "Balance" for the account in [balance_calculator.rb](mdc:app/models/account/balance_calculator.rb).
+For investment accounts with holdings, [base_calculator.rb](mdc:app/models/holding/base_calculator.rb) is used to calculate the daily historical holding quantities and prices, which are then rolled up into a final "Balance" for the account in [base_calculator.rb](mdc:app/models/account/balance/base_calculator.rb).
### Account Entries
-An account [entry.rb](mdc:app/models/account/entry.rb) is also a Rails "delegated type". `Account::Entry` represents any record that _modifies_ an `Account` [balance.rb](mdc:app/models/account/balance.rb) and/or [holding.rb](mdc:app/models/account/holding.rb). Therefore, every entry must have a `date`, `amount`, and `currency`.
+An account [entry.rb](mdc:app/models/entry.rb) is also a Rails "delegated type". `Entry` represents any record that _modifies_ an `Account` [balance.rb](mdc:app/models/account/balance.rb) and/or [holding.rb](mdc:app/models/holding.rb). Therefore, every entry must have a `date`, `amount`, and `currency`.
-The `amount` of an [entry.rb](mdc:app/models/account/entry.rb) is a signed value. A _negative_ amount is an "inflow" of money to that account. A _positive_ value is an "outflow" of money from that account. For example:
+The `amount` of an [entry.rb](mdc:app/models/entry.rb) is a signed value. A _negative_ amount is an "inflow" of money to that account. A _positive_ value is an "outflow" of money from that account. For example:
- A negative amount for a credit card account represents a "payment" to that account, which _reduces_ its balance (since it is a `liability`)
- A negative amount for a checking account represents an "income" to that account, which _increases_ its balance (since it is an `asset`)
- A negative amount for an investment/brokerage trade represents a "sell" transaction, which _increases_ the cash balance of the account
-There are 3 entry types, defined as [entryable.rb](mdc:app/models/account/entryable.rb) records:
+There are 3 entry types, defined as [entryable.rb](mdc:app/models/entryable.rb) records:
-- `Account::Valuation` - an account [valuation.rb](mdc:app/models/account/valuation.rb) is an entry that says, "here is the value of this account on this date". It is an absolute measure of an account value / debt. If there is an `Account::Valuation` of 5,000 for today's date, that means that the account balance will be 5,000 today.
-- `Account::Transaction` - an account [transaction.rb](mdc:app/models/account/transaction.rb) is an entry that alters the account balance by the `amount`. This is the most common type of entry and can be thought of as an "income" or "expense".
-- `Account::Trade` - an account [trade.rb](mdc:app/models/account/trade.rb) is an entry that only applies to an investment account. This represents a "buy" or "sell" of a holding and has a `qty` and `price`.
+- `Valuation` - an account [valuation.rb](mdc:app/models/valuation.rb) is an entry that says, "here is the value of this account on this date". It is an absolute measure of an account value / debt. If there is an `Valuation` of 5,000 for today's date, that means that the account balance will be 5,000 today.
+- `Transaction` - an account [transaction.rb](mdc:app/models/transaction.rb) is an entry that alters the account balance by the `amount`. This is the most common type of entry and can be thought of as an "income" or "expense".
+- `Trade` - an account [trade.rb](mdc:app/models/trade.rb) is an entry that only applies to an investment account. This represents a "buy" or "sell" of a holding and has a `qty` and `price`.
### Account Transfers
-A [transfer.rb](mdc:app/models/transfer.rb) represents a movement of money between two accounts. A transfer has an inflow [transaction.rb](mdc:app/models/account/transaction.rb) and an outflow [transaction.rb](mdc:app/models/account/transaction.rb). The Maybe system auto-matches transfers based on the following criteria:
+A [transfer.rb](mdc:app/models/transfer.rb) represents a movement of money between two accounts. A transfer has an inflow [transaction.rb](mdc:app/models/transaction.rb) and an outflow [transaction.rb](mdc:app/models/transaction.rb). The Maybe system auto-matches transfers based on the following criteria:
- Must be from different accounts
- Must be within 4 days of each other
@@ -115,10 +115,10 @@ The most important type of sync is the account sync. It is orchestrated by the
- Auto-matches transfer records for the account
- Calculates daily [balance.rb](mdc:app/models/account/balance.rb) records for the account from `account.start_date` to `Date.current` using [base_calculator.rb](mdc:app/models/account/balance/base_calculator.rb)
- - Balances are dependent on the calculation of [holding.rb](mdc:app/models/account/holding.rb), which uses [base_calculator.rb](mdc:app/models/account/holding/base_calculator.rb)
+ - Balances are dependent on the calculation of [holding.rb](mdc:app/models/holding.rb), which uses [base_calculator.rb](mdc:app/models/account/holding/base_calculator.rb)
- Enriches transaction data if enabled by user
-An account sync happens every time an [entry.rb](mdc:app/models/account/entry.rb) is updated.
+An account sync happens every time an [entry.rb](mdc:app/models/entry.rb) is updated.
### Plaid Item Syncs
@@ -126,7 +126,7 @@ A Plaid Item sync is an ETL (extract, transform, load) operation:
1. [plaid_item.rb](mdc:app/models/plaid_item.rb) fetches data from the external Plaid API
2. [plaid_item.rb](mdc:app/models/plaid_item.rb) creates and loads this data to [plaid_account.rb](mdc:app/models/plaid_account.rb) records
-3. [plaid_item.rb](mdc:app/models/plaid_item.rb) and [plaid_account.rb](mdc:app/models/plaid_account.rb) transform and load data to [account.rb](mdc:app/models/account.rb) and [entry.rb](mdc:app/models/account/entry.rb), the internal Maybe representations of the data.
+3. [plaid_item.rb](mdc:app/models/plaid_item.rb) and [plaid_account.rb](mdc:app/models/plaid_account.rb) transform and load data to [account.rb](mdc:app/models/account.rb) and [entry.rb](mdc:app/models/entry.rb), the internal Maybe representations of the data.
### Family Syncs
diff --git a/app/controllers/account/trades_controller.rb b/app/controllers/account/trades_controller.rb
deleted file mode 100644
index fd9b7d48..00000000
--- a/app/controllers/account/trades_controller.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-class Account::TradesController < ApplicationController
- include EntryableResource
-
- permitted_entryable_attributes :id, :qty, :price
-
- private
- def build_entry
- Account::TradeBuilder.new(create_entry_params)
- end
-
- def create_entry_params
- params.require(:account_entry).permit(
- :account_id, :date, :amount, :currency, :qty, :price, :ticker, :manual_ticker, :type, :transfer_account_id
- ).tap do |params|
- account_id = params.delete(:account_id)
- params[:account] = Current.family.accounts.find(account_id)
- end
- end
-
- def update_entry_params
- return entry_params unless entry_params[:entryable_attributes].present?
-
- update_params = entry_params
- update_params = update_params.merge(entryable_type: "Account::Trade")
-
- qty = update_params[:entryable_attributes][:qty]
- price = update_params[:entryable_attributes][:price]
-
- if qty.present? && price.present?
- qty = update_params[:nature] == "inflow" ? -qty.to_d : qty.to_d
- update_params[:entryable_attributes][:qty] = qty
- update_params[:amount] = qty * price.to_d
- end
-
- update_params.except(:nature)
- end
-end
diff --git a/app/controllers/account/transaction_categories_controller.rb b/app/controllers/account/transaction_categories_controller.rb
deleted file mode 100644
index 5920a0b3..00000000
--- a/app/controllers/account/transaction_categories_controller.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-class Account::TransactionCategoriesController < ApplicationController
- def update
- @entry = Current.family.entries.account_transactions.find(params[:transaction_id])
- @entry.update!(entry_params)
-
- respond_to do |format|
- format.html { redirect_back_or_to account_transaction_path(@entry) }
- format.turbo_stream do
- render turbo_stream: turbo_stream.replace(
- "category_menu_account_transaction_#{@entry.account_transaction_id}",
- partial: "categories/menu",
- locals: { transaction: @entry.account_transaction }
- )
- end
- end
- end
-
- private
- def entry_params
- params.require(:account_entry).permit(:entryable_type, entryable_attributes: [ :id, :category_id ])
- end
-end
diff --git a/app/controllers/account/transactions_controller.rb b/app/controllers/account/transactions_controller.rb
deleted file mode 100644
index 8125565c..00000000
--- a/app/controllers/account/transactions_controller.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-class Account::TransactionsController < ApplicationController
- include EntryableResource
-
- permitted_entryable_attributes :id, :category_id, :merchant_id, { tag_ids: [] }
-
- def bulk_delete
- destroyed = Current.family.entries.destroy_by(id: bulk_delete_params[:entry_ids])
- destroyed.map(&:account).uniq.each(&:sync_later)
- redirect_back_or_to transactions_url, notice: t(".success", count: destroyed.count)
- end
-
- def bulk_edit
- end
-
- def bulk_update
- updated = Current.family
- .entries
- .where(id: bulk_update_params[:entry_ids])
- .bulk_update!(bulk_update_params)
-
- redirect_back_or_to transactions_url, notice: t(".success", count: updated)
- end
-
- private
- def bulk_delete_params
- params.require(:bulk_delete).permit(entry_ids: [])
- end
-
- def bulk_update_params
- params.require(:bulk_update).permit(:date, :notes, :category_id, :merchant_id, entry_ids: [], tag_ids: [])
- end
-
- def search_params
- params.fetch(:q, {})
- .permit(:start_date, :end_date, :search, :amount, :amount_operator, accounts: [], account_ids: [], categories: [], merchants: [], types: [], tags: [])
- end
-end
diff --git a/app/controllers/account/valuations_controller.rb b/app/controllers/account/valuations_controller.rb
deleted file mode 100644
index 08f566f3..00000000
--- a/app/controllers/account/valuations_controller.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-class Account::ValuationsController < ApplicationController
- include EntryableResource
-end
diff --git a/app/controllers/budget_categories_controller.rb b/app/controllers/budget_categories_controller.rb
index dcd96262..e8cc83e6 100644
--- a/app/controllers/budget_categories_controller.rb
+++ b/app/controllers/budget_categories_controller.rb
@@ -11,14 +11,14 @@ class BudgetCategoriesController < ApplicationController
if params[:id] == BudgetCategory.uncategorized.id
@budget_category = @budget.uncategorized_budget_category
- @recent_transactions = @recent_transactions.where(account_transactions: { category_id: nil })
+ @recent_transactions = @recent_transactions.where(transactions: { category_id: nil })
else
@budget_category = Current.family.budget_categories.find(params[:id])
- @recent_transactions = @recent_transactions.joins("LEFT JOIN categories ON categories.id = account_transactions.category_id")
+ @recent_transactions = @recent_transactions.joins("LEFT JOIN categories ON categories.id = transactions.category_id")
.where("categories.id = ? OR categories.parent_id = ?", @budget_category.category.id, @budget_category.category.id)
end
- @recent_transactions = @recent_transactions.order("account_entries.date DESC, ABS(account_entries.amount) DESC").take(3)
+ @recent_transactions = @recent_transactions.order("entries.date DESC, ABS(entries.amount) DESC").take(3)
end
def update
diff --git a/app/controllers/concerns/entryable_resource.rb b/app/controllers/concerns/entryable_resource.rb
index 58519725..443b0483 100644
--- a/app/controllers/concerns/entryable_resource.rb
+++ b/app/controllers/concerns/entryable_resource.rb
@@ -2,14 +2,9 @@ module EntryableResource
extend ActiveSupport::Concern
included do
- before_action :set_entry, only: %i[show update destroy]
- end
+ include StreamExtensions, ActionView::RecordIdentifier
- class_methods do
- def permitted_entryable_attributes(*attrs)
- @permitted_entryable_attributes = attrs if attrs.any?
- @permitted_entryable_attributes ||= [ :id ]
- end
+ before_action :set_entry, only: %i[show update destroy]
end
def show
@@ -21,49 +16,16 @@ module EntryableResource
@entry = Current.family.entries.new(
account: account,
currency: account ? account.currency : Current.family.currency,
- entryable: entryable_type.new
+ entryable: entryable
)
end
def create
- @entry = build_entry
-
- if @entry.save
- @entry.sync_account_later
-
- flash[:notice] = t("account.entries.create.success")
-
- respond_to do |format|
- format.html { redirect_back_or_to account_path(@entry.account) }
-
- redirect_target_url = request.referer || account_path(@entry.account)
- format.turbo_stream { render turbo_stream: turbo_stream.action(:redirect, redirect_target_url) }
- end
- else
- render :new, status: :unprocessable_entity
- end
+ raise NotImplementedError, "Entryable resources must implement #create"
end
def update
- if @entry.update(update_entry_params)
- @entry.sync_account_later
-
- respond_to do |format|
- format.html { redirect_back_or_to account_path(@entry.account), notice: t("account.entries.update.success") }
- format.turbo_stream do
- render turbo_stream: [
- turbo_stream.replace(
- "header_account_entry_#{@entry.id}",
- partial: "#{entryable_type.name.underscore.pluralize}/header",
- locals: { entry: @entry }
- ),
- turbo_stream.replace("account_entry_#{@entry.id}", partial: "account/entries/entry", locals: { entry: @entry })
- ]
- end
- end
- else
- render :show, status: :unprocessable_entity
- end
+ raise NotImplementedError, "Entryable resources must implement #update"
end
def destroy
@@ -71,58 +33,15 @@ module EntryableResource
@entry.destroy!
@entry.sync_account_later
- flash[:notice] = t("account.entries.destroy.success")
-
- respond_to do |format|
- format.html { redirect_back_or_to account_path(account) }
-
- redirect_target_url = request.referer || account_path(@entry.account)
- format.turbo_stream { render turbo_stream: turbo_stream.action(:redirect, redirect_target_url) }
- end
+ redirect_back_or_to account_path(account), notice: t("account.entries.destroy.success")
end
private
- def entryable_type
- permitted_entryable_types = %w[Account::Transaction Account::Valuation Account::Trade]
- klass = params[:entryable_type] || "Account::#{controller_name.classify}"
- klass.constantize if permitted_entryable_types.include?(klass)
+ def entryable
+ controller_name.classify.constantize.new
end
def set_entry
@entry = Current.family.entries.find(params[:id])
end
-
- def build_entry
- Current.family.entries.new(create_entry_params)
- end
-
- def update_entry_params
- prepared_entry_params
- end
-
- def create_entry_params
- prepared_entry_params.merge({
- entryable_type: entryable_type.name,
- entryable_attributes: entry_params[:entryable_attributes] || {}
- })
- end
-
- def prepared_entry_params
- default_params = entry_params.except(:nature)
- default_params = default_params.merge(entryable_type: entryable_type.name) if entry_params[:entryable_attributes].present?
-
- if entry_params[:nature].present? && entry_params[:amount].present?
- signed_amount = entry_params[:nature] == "inflow" ? -entry_params[:amount].to_d : entry_params[:amount].to_d
- default_params = default_params.merge(amount: signed_amount)
- end
-
- default_params
- end
-
- def entry_params
- params.require(:account_entry).permit(
- :account_id, :name, :enriched_name, :date, :amount, :currency, :excluded, :notes, :nature,
- entryable_attributes: self.class.permitted_entryable_attributes
- )
- end
end
diff --git a/app/controllers/concerns/stream_extensions.rb b/app/controllers/concerns/stream_extensions.rb
new file mode 100644
index 00000000..978d5bfb
--- /dev/null
+++ b/app/controllers/concerns/stream_extensions.rb
@@ -0,0 +1,20 @@
+module StreamExtensions
+ extend ActiveSupport::Concern
+
+ def stream_redirect_to(path, notice: nil, alert: nil)
+ custom_stream_redirect(path, notice: notice, alert: alert)
+ end
+
+ def stream_redirect_back_or_to(path, notice: nil, alert: nil)
+ custom_stream_redirect(path, redirect_back: true, notice: notice, alert: alert)
+ end
+
+ private
+ def custom_stream_redirect(path, redirect_back: false, notice: nil, alert: nil)
+ flash[:notice] = notice if notice.present?
+ flash[:alert] = alert if alert.present?
+
+ redirect_target_url = redirect_back ? request.referer : path
+ render turbo_stream: turbo_stream.action(:redirect, redirect_target_url)
+ end
+end
diff --git a/app/controllers/account/holdings_controller.rb b/app/controllers/holdings_controller.rb
similarity index 92%
rename from app/controllers/account/holdings_controller.rb
rename to app/controllers/holdings_controller.rb
index 9ded4165..db9d59b4 100644
--- a/app/controllers/account/holdings_controller.rb
+++ b/app/controllers/holdings_controller.rb
@@ -1,4 +1,4 @@
-class Account::HoldingsController < ApplicationController
+class HoldingsController < ApplicationController
before_action :set_holding, only: %i[show destroy]
def index
diff --git a/app/controllers/trades_controller.rb b/app/controllers/trades_controller.rb
new file mode 100644
index 00000000..151d62c6
--- /dev/null
+++ b/app/controllers/trades_controller.rb
@@ -0,0 +1,79 @@
+class TradesController < ApplicationController
+ include EntryableResource
+
+ def create
+ @entry = build_entry
+
+ if @entry.save
+ @entry.sync_account_later
+
+ flash[:notice] = t("entries.create.success")
+
+ respond_to do |format|
+ format.html { redirect_back_or_to account_path(@entry.account) }
+ format.turbo_stream { stream_redirect_back_or_to account_path(@entry.account) }
+ end
+ else
+ render :new, status: :unprocessable_entity
+ end
+ end
+
+ def update
+ if @entry.update(update_entry_params)
+ @entry.sync_account_later
+
+ respond_to do |format|
+ format.html { redirect_back_or_to account_path(@entry.account), notice: t("entries.update.success") }
+ format.turbo_stream do
+ render turbo_stream: [
+ turbo_stream.replace(
+ "header_entry_#{@entry.id}",
+ partial: "trades/header",
+ locals: { entry: @entry }
+ ),
+ turbo_stream.replace("entry_#{@entry.id}", partial: "entries/entry", locals: { entry: @entry })
+ ]
+ end
+ end
+ else
+ render :show, status: :unprocessable_entity
+ end
+ end
+
+ private
+ def build_entry
+ account = Current.family.accounts.find(params.dig(:entry, :account_id))
+ TradeBuilder.new(create_entry_params.merge(account: account))
+ end
+
+ def entry_params
+ params.require(:entry).permit(
+ :name, :enriched_name, :date, :amount, :currency, :excluded, :notes, :nature,
+ entryable_attributes: [ :id, :qty, :price ]
+ )
+ end
+
+ def create_entry_params
+ params.require(:entry).permit(
+ :date, :amount, :currency, :qty, :price, :ticker, :manual_ticker, :type, :transfer_account_id
+ )
+ end
+
+ def update_entry_params
+ return entry_params unless entry_params[:entryable_attributes].present?
+
+ update_params = entry_params
+ update_params = update_params.merge(entryable_type: "Trade")
+
+ qty = update_params[:entryable_attributes][:qty]
+ price = update_params[:entryable_attributes][:price]
+
+ if qty.present? && price.present?
+ qty = update_params[:nature] == "inflow" ? -qty.to_d : qty.to_d
+ update_params[:entryable_attributes][:qty] = qty
+ update_params[:amount] = qty * price.to_d
+ end
+
+ update_params.except(:nature)
+ end
+end
diff --git a/app/controllers/transaction_categories_controller.rb b/app/controllers/transaction_categories_controller.rb
new file mode 100644
index 00000000..f70e0aa9
--- /dev/null
+++ b/app/controllers/transaction_categories_controller.rb
@@ -0,0 +1,22 @@
+class TransactionCategoriesController < ApplicationController
+ def update
+ @entry = Current.family.entries.transactions.find(params[:transaction_id])
+ @entry.update!(entry_params)
+
+ respond_to do |format|
+ format.html { redirect_back_or_to transaction_path(@entry) }
+ format.turbo_stream do
+ render turbo_stream: turbo_stream.replace(
+ "category_menu_transaction_#{@entry.transaction_id}",
+ partial: "categories/menu",
+ locals: { transaction: @entry.transaction }
+ )
+ end
+ end
+ end
+
+ private
+ def entry_params
+ params.require(:entry).permit(:entryable_type, entryable_attributes: [ :id, :category_id ])
+ end
+end
diff --git a/app/controllers/transactions/bulk_deletions_controller.rb b/app/controllers/transactions/bulk_deletions_controller.rb
new file mode 100644
index 00000000..fefaf389
--- /dev/null
+++ b/app/controllers/transactions/bulk_deletions_controller.rb
@@ -0,0 +1,12 @@
+class Transactions::BulkDeletionsController < ApplicationController
+ def create
+ destroyed = Current.family.entries.destroy_by(id: bulk_delete_params[:entry_ids])
+ destroyed.map(&:account).uniq.each(&:sync_later)
+ redirect_back_or_to transactions_url, notice: "#{destroyed.count} transaction#{destroyed.count == 1 ? "" : "s"} deleted"
+ end
+
+ private
+ def bulk_delete_params
+ params.require(:bulk_delete).permit(entry_ids: [])
+ end
+end
diff --git a/app/controllers/transactions/bulk_updates_controller.rb b/app/controllers/transactions/bulk_updates_controller.rb
new file mode 100644
index 00000000..08c4befe
--- /dev/null
+++ b/app/controllers/transactions/bulk_updates_controller.rb
@@ -0,0 +1,19 @@
+class Transactions::BulkUpdatesController < ApplicationController
+ def new
+ end
+
+ def create
+ updated = Current.family
+ .entries
+ .where(id: bulk_update_params[:entry_ids])
+ .bulk_update!(bulk_update_params)
+
+ redirect_back_or_to transactions_path, notice: "#{updated} transactions updated"
+ end
+
+ private
+ def bulk_update_params
+ params.require(:bulk_update)
+ .permit(:date, :notes, :category_id, :merchant_id, entry_ids: [], tag_ids: [])
+ end
+end
diff --git a/app/controllers/transactions_controller.rb b/app/controllers/transactions_controller.rb
index 484c53a0..e4407ee3 100644
--- a/app/controllers/transactions_controller.rb
+++ b/app/controllers/transactions_controller.rb
@@ -1,5 +1,5 @@
class TransactionsController < ApplicationController
- include ScrollFocusable
+ include ScrollFocusable, EntryableResource
before_action :store_params!, only: :index
@@ -48,7 +48,62 @@ class TransactionsController < ApplicationController
redirect_to transactions_path(updated_params)
end
+ def create
+ account = Current.family.accounts.find(params.dig(:entry, :account_id))
+ @entry = account.entries.new(entry_params)
+
+ if @entry.save
+ @entry.sync_account_later
+
+ flash[:notice] = "Transaction created"
+
+ respond_to do |format|
+ format.html { redirect_back_or_to account_path(@entry.account) }
+ format.turbo_stream { stream_redirect_back_or_to(account_path(@entry.account)) }
+ end
+ else
+ render :new, status: :unprocessable_entity
+ end
+ end
+
+ def update
+ if @entry.update(entry_params)
+ @entry.sync_account_later
+
+ respond_to do |format|
+ format.html { redirect_back_or_to account_path(@entry.account), notice: "Transaction updated" }
+ format.turbo_stream do
+ render turbo_stream: [
+ turbo_stream.replace(
+ dom_id(@entry, :header),
+ partial: "transactions/header",
+ locals: { entry: @entry }
+ ),
+ turbo_stream.replace(@entry)
+ ]
+ end
+ end
+ else
+ render :show, status: :unprocessable_entity
+ end
+ end
+
private
+ def entry_params
+ entry_params = params.require(:entry).permit(
+ :name, :enriched_name, :date, :amount, :currency, :excluded, :notes, :nature, :entryable_type,
+ entryable_attributes: [ :id, :category_id, :merchant_id, { tag_ids: [] } ]
+ )
+
+ nature = entry_params.delete(:nature)
+
+ if nature.present? && entry_params[:amount].present?
+ signed_amount = nature == "inflow" ? -entry_params[:amount].to_d : entry_params[:amount].to_d
+ entry_params = entry_params.merge(amount: signed_amount)
+ end
+
+ entry_params
+ end
def search_params
cleaned_params = params.fetch(:q, {})
diff --git a/app/controllers/account/transfer_matches_controller.rb b/app/controllers/transfer_matches_controller.rb
similarity index 73%
rename from app/controllers/account/transfer_matches_controller.rb
rename to app/controllers/transfer_matches_controller.rb
index 851f3ac3..415d9377 100644
--- a/app/controllers/account/transfer_matches_controller.rb
+++ b/app/controllers/transfer_matches_controller.rb
@@ -1,9 +1,9 @@
-class Account::TransferMatchesController < ApplicationController
+class TransferMatchesController < ApplicationController
before_action :set_entry
def new
@accounts = Current.family.accounts.alphabetically.where.not(id: @entry.account_id)
- @transfer_match_candidates = @entry.account_transaction.transfer_match_candidates
+ @transfer_match_candidates = @entry.transaction.transfer_match_candidates
end
def create
@@ -11,7 +11,7 @@ class Account::TransferMatchesController < ApplicationController
@transfer.save!
@transfer.sync_account_later
- redirect_back_or_to transactions_path, notice: t(".success")
+ redirect_back_or_to transactions_path, notice: "Transfer created"
end
private
@@ -27,7 +27,7 @@ class Account::TransferMatchesController < ApplicationController
if transfer_match_params[:method] == "new"
target_account = Current.family.accounts.find(transfer_match_params[:target_account_id])
- missing_transaction = Account::Transaction.new(
+ missing_transaction = Transaction.new(
entry: target_account.entries.build(
amount: @entry.amount * -1,
currency: @entry.currency,
@@ -37,8 +37,8 @@ class Account::TransferMatchesController < ApplicationController
)
transfer = Transfer.find_or_initialize_by(
- inflow_transaction: @entry.amount.positive? ? missing_transaction : @entry.account_transaction,
- outflow_transaction: @entry.amount.positive? ? @entry.account_transaction : missing_transaction
+ inflow_transaction: @entry.amount.positive? ? missing_transaction : @entry.transaction,
+ outflow_transaction: @entry.amount.positive? ? @entry.transaction : missing_transaction
)
transfer.status = "confirmed"
transfer
@@ -46,8 +46,8 @@ class Account::TransferMatchesController < ApplicationController
target_transaction = Current.family.entries.find(transfer_match_params[:matched_entry_id])
transfer = Transfer.find_or_initialize_by(
- inflow_transaction: @entry.amount.negative? ? @entry.account_transaction : target_transaction.account_transaction,
- outflow_transaction: @entry.amount.negative? ? target_transaction.account_transaction : @entry.account_transaction
+ inflow_transaction: @entry.amount.negative? ? @entry.transaction : target_transaction.transaction,
+ outflow_transaction: @entry.amount.negative? ? target_transaction.transaction : @entry.transaction
)
transfer.status = "confirmed"
transfer
diff --git a/app/controllers/valuations_controller.rb b/app/controllers/valuations_controller.rb
new file mode 100644
index 00000000..7d91a9a6
--- /dev/null
+++ b/app/controllers/valuations_controller.rb
@@ -0,0 +1,49 @@
+class ValuationsController < ApplicationController
+ include EntryableResource
+
+ def create
+ account = Current.family.accounts.find(params.dig(:entry, :account_id))
+ @entry = account.entries.new(entry_params.merge(entryable: Valuation.new))
+
+ if @entry.save
+ @entry.sync_account_later
+
+ flash[:notice] = "Balance created"
+
+ respond_to do |format|
+ format.html { redirect_back_or_to account_path(@entry.account) }
+ format.turbo_stream { stream_redirect_back_or_to(account_path(@entry.account)) }
+ end
+ else
+ render :new, status: :unprocessable_entity
+ end
+ end
+
+ def update
+ if @entry.update(entry_params)
+ @entry.sync_account_later
+
+ respond_to do |format|
+ format.html { redirect_back_or_to account_path(@entry.account), notice: "Balance updated" }
+ format.turbo_stream do
+ render turbo_stream: [
+ turbo_stream.replace(
+ dom_id(@entry, :header),
+ partial: "valuations/header",
+ locals: { entry: @entry }
+ ),
+ turbo_stream.replace(@entry)
+ ]
+ end
+ end
+ else
+ render :show, status: :unprocessable_entity
+ end
+ end
+
+ private
+ def entry_params
+ params.require(:entry)
+ .permit(:name, :enriched_name, :date, :amount, :currency, :notes)
+ end
+end
diff --git a/app/helpers/account/entries_helper.rb b/app/helpers/entries_helper.rb
similarity index 78%
rename from app/helpers/account/entries_helper.rb
rename to app/helpers/entries_helper.rb
index 5fac75cc..e198e6ee 100644
--- a/app/helpers/account/entries_helper.rb
+++ b/app/helpers/entries_helper.rb
@@ -1,8 +1,8 @@
-module Account::EntriesHelper
+module EntriesHelper
def entries_by_date(entries, totals: false)
transfer_groups = entries.group_by do |entry|
# Only check for transfer if it's a transaction
- next nil unless entry.entryable_type == "Account::Transaction"
+ next nil unless entry.entryable_type == "Transaction"
entry.entryable.transfer&.id
end
@@ -12,7 +12,7 @@ module Account::EntriesHelper
grouped_entries
else
grouped_entries.reject do |e|
- e.entryable_type == "Account::Transaction" &&
+ e.entryable_type == "Transaction" &&
e.entryable.transfer_as_inflow.present?
end
end
@@ -25,7 +25,7 @@ module Account::EntriesHelper
next if content.blank?
- render partial: "account/entries/entry_group", locals: { date:, entries: grouped_entries, content:, totals: }
+ render partial: "entries/entry_group", locals: { date:, entries: grouped_entries, content:, totals: }
end.compact.join.html_safe
end
diff --git a/app/models/account.rb b/app/models/account.rb
index b93a13e1..42a9d67f 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -7,11 +7,11 @@ class Account < ApplicationRecord
belongs_to :import, optional: true
has_many :import_mappings, as: :mappable, dependent: :destroy, class_name: "Import::Mapping"
- has_many :entries, dependent: :destroy, class_name: "Account::Entry"
- has_many :transactions, through: :entries, source: :entryable, source_type: "Account::Transaction"
- has_many :valuations, through: :entries, source: :entryable, source_type: "Account::Valuation"
- has_many :trades, through: :entries, source: :entryable, source_type: "Account::Trade"
- has_many :holdings, dependent: :destroy, class_name: "Account::Holding"
+ has_many :entries, dependent: :destroy
+ has_many :transactions, through: :entries, source: :entryable, source_type: "Transaction"
+ has_many :valuations, through: :entries, source: :entryable, source_type: "Valuation"
+ has_many :trades, through: :entries, source: :entryable, source_type: "Trade"
+ has_many :holdings, dependent: :destroy
has_many :balances, dependent: :destroy
monetize :balance, :cash_balance
@@ -43,14 +43,14 @@ class Account < ApplicationRecord
date: Date.current,
amount: account.balance,
currency: account.currency,
- entryable: Account::Valuation.new
+ entryable: Valuation.new
)
account.entries.build(
name: "Initial Balance",
date: 1.day.ago.to_date,
amount: initial_balance,
currency: account.currency,
- entryable: Account::Valuation.new
+ entryable: Valuation.new
)
account.save!
@@ -113,7 +113,7 @@ class Account < ApplicationRecord
end
def update_balance!(balance)
- valuation = entries.account_valuations.find_by(date: Date.current)
+ valuation = entries.valuations.find_by(date: Date.current)
if valuation
valuation.update! amount: balance
@@ -123,7 +123,7 @@ class Account < ApplicationRecord
name: "Balance update",
amount: balance,
currency: currency,
- entryable: Account::Valuation.new
+ entryable: Valuation.new
end
end
@@ -148,7 +148,7 @@ class Account < ApplicationRecord
end
def first_valuation
- entries.account_valuations.order(:date).first
+ entries.valuations.order(:date).first
end
def first_valuation_amount
diff --git a/app/models/account/chartable.rb b/app/models/account/chartable.rb
index bac6a50e..d9a6c44b 100644
--- a/app/models/account/chartable.rb
+++ b/app/models/account/chartable.rb
@@ -7,7 +7,7 @@ module Account::Chartable
series_interval = interval || period.interval
- balances = Account::Balance.find_by_sql([
+ balances = Balance.find_by_sql([
balance_series_query,
{
start_date: period.start_date,
@@ -61,7 +61,7 @@ module Account::Chartable
COUNT(CASE WHEN accounts.currency <> :target_currency AND er.rate IS NULL THEN 1 END) as missing_rates
FROM dates d
LEFT JOIN accounts ON accounts.id IN (#{all.select(:id).to_sql})
- LEFT JOIN account_balances ab ON (
+ LEFT JOIN balances ab ON (
ab.date = d.date AND
ab.currency = accounts.currency AND
ab.account_id = accounts.id
diff --git a/app/models/account/enrichable.rb b/app/models/account/enrichable.rb
index 260aec5a..f5f175b4 100644
--- a/app/models/account/enrichable.rb
+++ b/app/models/account/enrichable.rb
@@ -2,9 +2,9 @@ module Account::Enrichable
extend ActiveSupport::Concern
def enrich_data
- total_unenriched = entries.account_transactions
- .joins("JOIN account_transactions at ON at.id = account_entries.entryable_id AND account_entries.entryable_type = 'Account::Transaction'")
- .where("account_entries.enriched_at IS NULL OR at.merchant_id IS NULL OR at.category_id IS NULL")
+ total_unenriched = entries.transactions
+ .joins("JOIN transactions at ON at.id = entries.entryable_id AND entries.entryable_type = 'Transaction'")
+ .where("entries.enriched_at IS NULL OR at.merchant_id IS NULL OR at.category_id IS NULL")
.count
if total_unenriched > 0
@@ -63,7 +63,7 @@ module Account::Enrichable
transactions.active
.includes(:merchant, :category)
.where(
- "account_entries.enriched_at IS NULL",
+ "entries.enriched_at IS NULL",
"OR merchant_id IS NULL",
"OR category_id IS NULL"
)
diff --git a/app/models/account/valuation.rb b/app/models/account/valuation.rb
deleted file mode 100644
index 219ecd90..00000000
--- a/app/models/account/valuation.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-class Account::Valuation < ApplicationRecord
- include Account::Entryable
-end
diff --git a/app/models/account_import.rb b/app/models/account_import.rb
index 98e7e0d0..96fdfd47 100644
--- a/app/models/account_import.rb
+++ b/app/models/account_import.rb
@@ -20,7 +20,7 @@ class AccountImport < Import
currency: row.currency,
date: Date.current,
name: "Imported account value",
- entryable: Account::Valuation.new
+ entryable: Valuation.new
)
end
end
diff --git a/app/models/account/balance.rb b/app/models/balance.rb
similarity index 85%
rename from app/models/account/balance.rb
rename to app/models/balance.rb
index 5d4e3710..90c4df41 100644
--- a/app/models/account/balance.rb
+++ b/app/models/balance.rb
@@ -1,4 +1,4 @@
-class Account::Balance < ApplicationRecord
+class Balance < ApplicationRecord
include Monetizable
belongs_to :account
diff --git a/app/models/account/balance/base_calculator.rb b/app/models/balance/base_calculator.rb
similarity index 84%
rename from app/models/account/balance/base_calculator.rb
rename to app/models/balance/base_calculator.rb
index 7acb51e8..2d01dfe7 100644
--- a/app/models/account/balance/base_calculator.rb
+++ b/app/models/balance/base_calculator.rb
@@ -1,4 +1,4 @@
-class Account::Balance::BaseCalculator
+class Balance::BaseCalculator
attr_reader :account
def initialize(account)
@@ -13,11 +13,11 @@ class Account::Balance::BaseCalculator
private
def sync_cache
- @sync_cache ||= Account::Balance::SyncCache.new(account)
+ @sync_cache ||= Balance::SyncCache.new(account)
end
def build_balance(date, cash_balance, holdings_value)
- Account::Balance.new(
+ Balance.new(
account_id: account.id,
date: date,
balance: holdings_value + cash_balance,
diff --git a/app/models/account/balance/forward_calculator.rb b/app/models/balance/forward_calculator.rb
similarity index 90%
rename from app/models/account/balance/forward_calculator.rb
rename to app/models/balance/forward_calculator.rb
index 503e5b79..d024d2c6 100644
--- a/app/models/account/balance/forward_calculator.rb
+++ b/app/models/balance/forward_calculator.rb
@@ -1,4 +1,4 @@
-class Account::Balance::ForwardCalculator < Account::Balance::BaseCalculator
+class Balance::ForwardCalculator < Balance::BaseCalculator
private
def calculate_balances
current_cash_balance = 0
diff --git a/app/models/account/balance/reverse_calculator.rb b/app/models/balance/reverse_calculator.rb
similarity index 92%
rename from app/models/account/balance/reverse_calculator.rb
rename to app/models/balance/reverse_calculator.rb
index 151f4036..4c124ced 100644
--- a/app/models/account/balance/reverse_calculator.rb
+++ b/app/models/balance/reverse_calculator.rb
@@ -1,4 +1,4 @@
-class Account::Balance::ReverseCalculator < Account::Balance::BaseCalculator
+class Balance::ReverseCalculator < Balance::BaseCalculator
private
def calculate_balances
current_cash_balance = account.cash_balance
diff --git a/app/models/account/balance/sync_cache.rb b/app/models/balance/sync_cache.rb
similarity index 83%
rename from app/models/account/balance/sync_cache.rb
rename to app/models/balance/sync_cache.rb
index 1fb7ea7f..aed2b64e 100644
--- a/app/models/account/balance/sync_cache.rb
+++ b/app/models/balance/sync_cache.rb
@@ -1,10 +1,10 @@
-class Account::Balance::SyncCache
+class Balance::SyncCache
def initialize(account)
@account = account
end
def get_valuation(date)
- converted_entries.find { |e| e.date == date && e.account_valuation? }
+ converted_entries.find { |e| e.date == date && e.valuation? }
end
def get_holdings(date)
@@ -12,7 +12,7 @@ class Account::Balance::SyncCache
end
def get_entries(date)
- converted_entries.select { |e| e.date == date && (e.account_transaction? || e.account_trade?) }
+ converted_entries.select { |e| e.date == date && (e.transaction? || e.trade?) }
end
private
diff --git a/app/models/account/balance/syncer.rb b/app/models/balance/syncer.rb
similarity index 86%
rename from app/models/account/balance/syncer.rb
rename to app/models/balance/syncer.rb
index 7aeaebda..362b87aa 100644
--- a/app/models/account/balance/syncer.rb
+++ b/app/models/balance/syncer.rb
@@ -1,4 +1,4 @@
-class Account::Balance::Syncer
+class Balance::Syncer
attr_reader :account, :strategy
def initialize(account, strategy:)
@@ -7,7 +7,7 @@ class Account::Balance::Syncer
end
def sync_balances
- Account::Balance.transaction do
+ Balance.transaction do
sync_holdings
calculate_balances
@@ -26,7 +26,7 @@ class Account::Balance::Syncer
private
def sync_holdings
- @holdings = Account::Holding::Syncer.new(account, strategy: strategy).sync_holdings
+ @holdings = Holding::Syncer.new(account, strategy: strategy).sync_holdings
end
def update_account_info
@@ -63,9 +63,9 @@ class Account::Balance::Syncer
def calculator
if strategy == :reverse
- Account::Balance::ReverseCalculator.new(account)
+ Balance::ReverseCalculator.new(account)
else
- Account::Balance::ForwardCalculator.new(account)
+ Balance::ForwardCalculator.new(account)
end
end
end
diff --git a/app/models/account/balance_trend_calculator.rb b/app/models/balance/trend_calculator.rb
similarity index 95%
rename from app/models/account/balance_trend_calculator.rb
rename to app/models/balance/trend_calculator.rb
index a9bfeb30..5fb8b406 100644
--- a/app/models/account/balance_trend_calculator.rb
+++ b/app/models/balance/trend_calculator.rb
@@ -2,7 +2,7 @@
# In most cases, this is sufficient. However, for the "Activity View", we need to show intraday balances
# to show users how each entry affects their balances. This class calculates intraday balances by
# interpolating between end-of-day balances.
-class Account::BalanceTrendCalculator
+class Balance::TrendCalculator
BalanceTrend = Struct.new(:trend, :cash, keyword_init: true)
class << self
@@ -48,12 +48,12 @@ class Account::BalanceTrendCalculator
todays_entries = entries.select { |e| e.date == entry.date }
todays_entries.each_with_index do |e, idx|
- if e.account_valuation?
+ if e.valuation?
current_balance = e.amount
current_cash_balance = e.amount
else
multiplier = e.account.liability? ? 1 : -1
- balance_change = e.account_trade? ? 0 : multiplier * e.amount
+ balance_change = e.trade? ? 0 : multiplier * e.amount
cash_change = multiplier * e.amount
current_balance = prior_balance + balance_change
diff --git a/app/models/category.rb b/app/models/category.rb
index 2adc7788..56fd3a63 100644
--- a/app/models/category.rb
+++ b/app/models/category.rb
@@ -1,5 +1,5 @@
class Category < ApplicationRecord
- has_many :transactions, dependent: :nullify, class_name: "Account::Transaction"
+ has_many :transactions, dependent: :nullify, class_name: "Transaction"
has_many :import_mappings, as: :mappable, dependent: :destroy, class_name: "Import::Mapping"
belongs_to :family
diff --git a/app/models/demo/generator.rb b/app/models/demo/generator.rb
index 9d62e684..181b9806 100644
--- a/app/models/demo/generator.rb
+++ b/app/models/demo/generator.rb
@@ -361,7 +361,7 @@ class Demo::Generator
unknown = Security.find_by(ticker: "UNKNOWN")
# Buy 20 shares of the unknown stock to simulate a stock where we can't fetch security prices
- account.entries.create! date: 10.days.ago.to_date, amount: 100, currency: "USD", name: "Buy unknown stock", entryable: Account::Trade.new(qty: 20, price: 5, security: unknown, currency: "USD")
+ account.entries.create! date: 10.days.ago.to_date, amount: 100, currency: "USD", name: "Buy unknown stock", entryable: Trade.new(qty: 20, price: 5, security: unknown, currency: "USD")
trades = [
{ security: aapl, qty: 20 }, { security: msft, qty: 10 }, { security: aapl, qty: -5 },
@@ -382,7 +382,7 @@ class Demo::Generator
amount: qty * price,
currency: "USD",
name: name_prefix + "#{qty} shares of #{security.ticker}",
- entryable: Account::Trade.new(qty: qty, price: price, currency: "USD", security: security)
+ entryable: Trade.new(qty: qty, price: price, currency: "USD", security: security)
end
end
@@ -450,20 +450,20 @@ class Demo::Generator
entry_defaults = {
date: Faker::Number.between(from: 0, to: 730).days.ago.to_date,
currency: "USD",
- entryable: Account::Transaction.new(transaction_attributes)
+ entryable: Transaction.new(transaction_attributes)
}
- Account::Entry.create! entry_defaults.merge(entry_attributes)
+ Entry.create! entry_defaults.merge(entry_attributes)
end
def create_valuation!(account, date, amount)
- Account::Entry.create! \
+ Entry.create! \
account: account,
date: date,
amount: amount,
currency: "USD",
name: "Balance update",
- entryable: Account::Valuation.new
+ entryable: Valuation.new
end
def random_family_record(model, family)
diff --git a/app/models/account/entry.rb b/app/models/entry.rb
similarity index 78%
rename from app/models/account/entry.rb
rename to app/models/entry.rb
index 4e6292a1..0f35cd39 100644
--- a/app/models/account/entry.rb
+++ b/app/models/entry.rb
@@ -1,4 +1,4 @@
-class Account::Entry < ApplicationRecord
+class Entry < ApplicationRecord
include Monetizable
monetize :amount
@@ -7,11 +7,11 @@ class Account::Entry < ApplicationRecord
belongs_to :transfer, optional: true
belongs_to :import, optional: true
- delegated_type :entryable, types: Account::Entryable::TYPES, dependent: :destroy
+ delegated_type :entryable, types: Entryable::TYPES, dependent: :destroy
accepts_nested_attributes_for :entryable
validates :date, :name, :amount, :currency, presence: true
- validates :date, uniqueness: { scope: [ :account_id, :entryable_type ] }, if: -> { account_valuation? }
+ validates :date, uniqueness: { scope: [ :account_id, :entryable_type ] }, if: -> { valuation? }
validates :date, comparison: { greater_than: -> { min_supported_date } }
scope :active, -> {
@@ -21,7 +21,7 @@ class Account::Entry < ApplicationRecord
scope :chronological, -> {
order(
date: :asc,
- Arel.sql("CASE WHEN account_entries.entryable_type = 'Account::Valuation' THEN 1 ELSE 0 END") => :asc,
+ Arel.sql("CASE WHEN entries.entryable_type = 'Valuation' THEN 1 ELSE 0 END") => :asc,
created_at: :asc
)
}
@@ -29,7 +29,7 @@ class Account::Entry < ApplicationRecord
scope :reverse_chronological, -> {
order(
date: :desc,
- Arel.sql("CASE WHEN account_entries.entryable_type = 'Account::Valuation' THEN 1 ELSE 0 END") => :desc,
+ Arel.sql("CASE WHEN entries.entryable_type = 'Valuation' THEN 1 ELSE 0 END") => :desc,
created_at: :desc
)
}
@@ -44,7 +44,7 @@ class Account::Entry < ApplicationRecord
end
def balance_trend(entries, balances)
- Account::BalanceTrendCalculator.new(self, entries, balances).trend
+ Balance::TrendCalculator.new(self, entries, balances).trend
end
def display_name
@@ -53,7 +53,7 @@ class Account::Entry < ApplicationRecord
class << self
def search(params)
- Account::EntrySearch.new(params).build_query(all)
+ EntrySearch.new(params).build_query(all)
end
# arbitrary cutoff date to avoid expensive sync operations
diff --git a/app/models/account/entry_search.rb b/app/models/entry_search.rb
similarity index 74%
rename from app/models/account/entry_search.rb
rename to app/models/entry_search.rb
index b08c338f..bed87613 100644
--- a/app/models/account/entry_search.rb
+++ b/app/models/entry_search.rb
@@ -1,4 +1,4 @@
-class Account::EntrySearch
+class EntrySearch
include ActiveModel::Model
include ActiveModel::Attributes
@@ -16,7 +16,7 @@ class Account::EntrySearch
return scope if search.blank?
query = scope
- query = query.where("account_entries.name ILIKE :search OR account_entries.enriched_name ILIKE :search",
+ query = query.where("entries.name ILIKE :search OR entries.enriched_name ILIKE :search",
search: "%#{ActiveRecord::Base.sanitize_sql_like(search)}%"
)
query
@@ -26,8 +26,8 @@ class Account::EntrySearch
return scope if start_date.blank? && end_date.blank?
query = scope
- query = query.where("account_entries.date >= ?", start_date) if start_date.present?
- query = query.where("account_entries.date <= ?", end_date) if end_date.present?
+ query = query.where("entries.date >= ?", start_date) if start_date.present?
+ query = query.where("entries.date <= ?", end_date) if end_date.present?
query
end
@@ -38,11 +38,11 @@ class Account::EntrySearch
case amount_operator
when "equal"
- query = query.where("ABS(ABS(account_entries.amount) - ?) <= 0.01", amount.to_f.abs)
+ query = query.where("ABS(ABS(entries.amount) - ?) <= 0.01", amount.to_f.abs)
when "less"
- query = query.where("ABS(account_entries.amount) < ?", amount.to_f.abs)
+ query = query.where("ABS(entries.amount) < ?", amount.to_f.abs)
when "greater"
- query = query.where("ABS(account_entries.amount) > ?", amount.to_f.abs)
+ query = query.where("ABS(entries.amount) > ?", amount.to_f.abs)
end
query
diff --git a/app/models/account/entryable.rb b/app/models/entryable.rb
similarity index 50%
rename from app/models/account/entryable.rb
rename to app/models/entryable.rb
index 91df5521..84ab6c12 100644
--- a/app/models/account/entryable.rb
+++ b/app/models/entryable.rb
@@ -1,7 +1,7 @@
-module Account::Entryable
+module Entryable
extend ActiveSupport::Concern
- TYPES = %w[Account::Valuation Account::Transaction Account::Trade]
+ TYPES = %w[Valuation Transaction Trade]
def self.from_type(entryable_type)
entryable_type.presence_in(TYPES).constantize
@@ -12,18 +12,18 @@ module Account::Entryable
scope :with_entry, -> { joins(:entry) }
- scope :active, -> { with_entry.merge(Account::Entry.active) }
+ scope :active, -> { with_entry.merge(Entry.active) }
scope :in_period, ->(period) {
- with_entry.where(account_entries: { date: period.start_date..period.end_date })
+ with_entry.where(entries: { date: period.start_date..period.end_date })
}
scope :reverse_chronological, -> {
- with_entry.merge(Account::Entry.reverse_chronological)
+ with_entry.merge(Entry.reverse_chronological)
}
scope :chronological, -> {
- with_entry.merge(Account::Entry.chronological)
+ with_entry.merge(Entry.chronological)
}
end
end
diff --git a/app/models/family/auto_transfer_matchable.rb b/app/models/family/auto_transfer_matchable.rb
index 32fe94b4..388ba5d6 100644
--- a/app/models/family/auto_transfer_matchable.rb
+++ b/app/models/family/auto_transfer_matchable.rb
@@ -1,12 +1,12 @@
module Family::AutoTransferMatchable
def transfer_match_candidates
- Account::Entry.select([
+ Entry.select([
"inflow_candidates.entryable_id as inflow_transaction_id",
"outflow_candidates.entryable_id as outflow_transaction_id",
"ABS(inflow_candidates.date - outflow_candidates.date) as date_diff"
- ]).from("account_entries inflow_candidates")
+ ]).from("entries inflow_candidates")
.joins("
- JOIN account_entries outflow_candidates ON (
+ JOIN entries outflow_candidates ON (
inflow_candidates.amount < 0 AND
outflow_candidates.amount > 0 AND
inflow_candidates.amount = -outflow_candidates.amount AND
@@ -29,7 +29,7 @@ module Family::AutoTransferMatchable
.where("inflow_accounts.family_id = ? AND outflow_accounts.family_id = ?", self.id, self.id)
.where("inflow_accounts.is_active = true")
.where("outflow_accounts.is_active = true")
- .where("inflow_candidates.entryable_type = 'Account::Transaction' AND outflow_candidates.entryable_type = 'Account::Transaction'")
+ .where("inflow_candidates.entryable_type = 'Transaction' AND outflow_candidates.entryable_type = 'Transaction'")
.where(existing_transfers: { id: nil })
.order("date_diff ASC") # Closest matches first
end
diff --git a/app/models/account/holding.rb b/app/models/holding.rb
similarity index 79%
rename from app/models/account/holding.rb
rename to app/models/holding.rb
index ba7a7e2d..fb9b001e 100644
--- a/app/models/account/holding.rb
+++ b/app/models/holding.rb
@@ -1,4 +1,4 @@
-class Account::Holding < ApplicationRecord
+class Holding < ApplicationRecord
include Monetizable, Gapfillable
monetize :amount
@@ -27,9 +27,9 @@ class Account::Holding < ApplicationRecord
# Basic approximation of cost-basis
def avg_cost
- avg_cost = account.entries.account_trades
- .joins("INNER JOIN account_trades ON account_trades.id = account_entries.entryable_id")
- .where("account_trades.security_id = ? AND account_trades.qty > 0 AND account_entries.date <= ?", security.id, date)
+ avg_cost = account.entries.trades
+ .joins("INNER JOIN trades ON trades.id = entries.entryable_id")
+ .where("trades.security_id = ? AND trades.qty > 0 AND entries.date <= ?", security.id, date)
.average(:price)
Money.new(avg_cost || price, currency)
diff --git a/app/models/account/holding/base_calculator.rb b/app/models/holding/base_calculator.rb
similarity index 88%
rename from app/models/account/holding/base_calculator.rb
rename to app/models/holding/base_calculator.rb
index 4359e9ab..47178d8b 100644
--- a/app/models/account/holding/base_calculator.rb
+++ b/app/models/holding/base_calculator.rb
@@ -1,4 +1,4 @@
-class Account::Holding::BaseCalculator
+class Holding::BaseCalculator
attr_reader :account
def initialize(account)
@@ -8,13 +8,13 @@ class Account::Holding::BaseCalculator
def calculate
Rails.logger.tagged(self.class.name) do
holdings = calculate_holdings
- Account::Holding.gapfill(holdings)
+ Holding.gapfill(holdings)
end
end
private
def portfolio_cache
- @portfolio_cache ||= Account::Holding::PortfolioCache.new(account)
+ @portfolio_cache ||= Holding::PortfolioCache.new(account)
end
def empty_portfolio
@@ -49,7 +49,7 @@ class Account::Holding::BaseCalculator
next
end
- Account::Holding.new(
+ Holding.new(
account_id: account.id,
security_id: security_id,
date: date,
diff --git a/app/models/account/holding/forward_calculator.rb b/app/models/holding/forward_calculator.rb
similarity index 77%
rename from app/models/account/holding/forward_calculator.rb
rename to app/models/holding/forward_calculator.rb
index afb6b71f..d2f2e8d7 100644
--- a/app/models/account/holding/forward_calculator.rb
+++ b/app/models/holding/forward_calculator.rb
@@ -1,7 +1,7 @@
-class Account::Holding::ForwardCalculator < Account::Holding::BaseCalculator
+class Holding::ForwardCalculator < Holding::BaseCalculator
private
def portfolio_cache
- @portfolio_cache ||= Account::Holding::PortfolioCache.new(account)
+ @portfolio_cache ||= Holding::PortfolioCache.new(account)
end
def calculate_holdings
diff --git a/app/models/account/holding/gapfillable.rb b/app/models/holding/gapfillable.rb
similarity index 91%
rename from app/models/account/holding/gapfillable.rb
rename to app/models/holding/gapfillable.rb
index e2462a6f..45c05089 100644
--- a/app/models/account/holding/gapfillable.rb
+++ b/app/models/holding/gapfillable.rb
@@ -1,4 +1,4 @@
-module Account::Holding::Gapfillable
+module Holding::Gapfillable
extend ActiveSupport::Concern
class_methods do
@@ -19,7 +19,7 @@ module Account::Holding::Gapfillable
previous_holding = holding
else
# Create a new holding based on the previous day's data
- filled_holdings << Account::Holding.new(
+ filled_holdings << Holding.new(
account: previous_holding.account,
security: previous_holding.security,
date: date,
diff --git a/app/models/account/holding/portfolio_cache.rb b/app/models/holding/portfolio_cache.rb
similarity index 98%
rename from app/models/account/holding/portfolio_cache.rb
rename to app/models/holding/portfolio_cache.rb
index 224d0b83..e8d3fcec 100644
--- a/app/models/account/holding/portfolio_cache.rb
+++ b/app/models/holding/portfolio_cache.rb
@@ -1,4 +1,4 @@
-class Account::Holding::PortfolioCache
+class Holding::PortfolioCache
attr_reader :account, :use_holdings
class SecurityNotFound < StandardError
@@ -49,7 +49,7 @@ class Account::Holding::PortfolioCache
PriceWithPriority = Data.define(:price, :priority)
def trades
- @trades ||= account.entries.includes(entryable: :security).account_trades.chronological.to_a
+ @trades ||= account.entries.includes(entryable: :security).trades.chronological.to_a
end
def holdings
diff --git a/app/models/account/holding/reverse_calculator.rb b/app/models/holding/reverse_calculator.rb
similarity index 87%
rename from app/models/account/holding/reverse_calculator.rb
rename to app/models/holding/reverse_calculator.rb
index d3677c88..f3996e5f 100644
--- a/app/models/account/holding/reverse_calculator.rb
+++ b/app/models/holding/reverse_calculator.rb
@@ -1,10 +1,10 @@
-class Account::Holding::ReverseCalculator < Account::Holding::BaseCalculator
+class Holding::ReverseCalculator < Holding::BaseCalculator
private
# Reverse calculators will use the existing holdings as a source of security ids and prices
# since it is common for a provider to supply "current day" holdings but not all the historical
# trades that make up those holdings.
def portfolio_cache
- @portfolio_cache ||= Account::Holding::PortfolioCache.new(account, use_holdings: true)
+ @portfolio_cache ||= Holding::PortfolioCache.new(account, use_holdings: true)
end
def calculate_holdings
diff --git a/app/models/account/holding/syncer.rb b/app/models/holding/syncer.rb
similarity index 84%
rename from app/models/account/holding/syncer.rb
rename to app/models/holding/syncer.rb
index bfccd6f0..345f2a3f 100644
--- a/app/models/account/holding/syncer.rb
+++ b/app/models/holding/syncer.rb
@@ -1,4 +1,4 @@
-class Account::Holding::Syncer
+class Holding::Syncer
def initialize(account, strategy:)
@account = account
@strategy = strategy
@@ -36,7 +36,7 @@ class Account::Holding::Syncer
end
def purge_stale_holdings
- portfolio_security_ids = account.entries.account_trades.map { |entry| entry.entryable.security_id }.uniq
+ portfolio_security_ids = account.entries.trades.map { |entry| entry.entryable.security_id }.uniq
# If there are no securities in the portfolio, delete all holdings
if portfolio_security_ids.empty?
@@ -50,9 +50,9 @@ class Account::Holding::Syncer
def calculator
if strategy == :reverse
- Account::Holding::ReverseCalculator.new(account)
+ Holding::ReverseCalculator.new(account)
else
- Account::Holding::ForwardCalculator.new(account)
+ Holding::ForwardCalculator.new(account)
end
end
end
diff --git a/app/models/import.rb b/app/models/import.rb
index 662b4cee..bb367cf9 100644
--- a/app/models/import.rb
+++ b/app/models/import.rb
@@ -34,7 +34,7 @@ class Import < ApplicationRecord
has_many :rows, dependent: :destroy
has_many :mappings, dependent: :destroy
has_many :accounts, dependent: :destroy
- has_many :entries, dependent: :destroy, class_name: "Account::Entry"
+ has_many :entries, dependent: :destroy
class << self
def parse_csv_str(csv_str, col_sep: ",")
diff --git a/app/models/import/row.rb b/app/models/import/row.rb
index 622a9d0a..350d8084 100644
--- a/app/models/import/row.rb
+++ b/app/models/import/row.rb
@@ -63,7 +63,7 @@ class Import::Row < ApplicationRecord
return
end
- min_date = Account::Entry.min_supported_date
+ min_date = Entry.min_supported_date
max_date = Date.current
if parsed_date < min_date || parsed_date > max_date
diff --git a/app/models/income_statement/base_query.rb b/app/models/income_statement/base_query.rb
index d2b17b81..ef1c8a99 100644
--- a/app/models/income_statement/base_query.rb
+++ b/app/models/income_statement/base_query.rb
@@ -11,13 +11,13 @@ module IncomeStatement::BaseQuery
COUNT(ae.id) as transactions_count,
BOOL_OR(ae.currency <> :target_currency AND er.rate IS NULL) as missing_exchange_rates
FROM (#{transactions_scope.to_sql}) at
- JOIN account_entries ae ON ae.entryable_id = at.id AND ae.entryable_type = 'Account::Transaction'
+ JOIN entries ae ON ae.entryable_id = at.id AND ae.entryable_type = 'Transaction'
LEFT JOIN categories c ON c.id = at.category_id
LEFT JOIN (
SELECT t.*, t.id as transfer_id, a.accountable_type
FROM transfers t
- JOIN account_entries ae ON ae.entryable_id = t.inflow_transaction_id
- AND ae.entryable_type = 'Account::Transaction'
+ JOIN entries ae ON ae.entryable_id = t.inflow_transaction_id
+ AND ae.entryable_type = 'Transaction'
JOIN accounts a ON a.id = ae.account_id
) transfer_info ON (
transfer_info.inflow_transaction_id = at.id OR
diff --git a/app/models/merchant.rb b/app/models/merchant.rb
index e363f6aa..030d9409 100644
--- a/app/models/merchant.rb
+++ b/app/models/merchant.rb
@@ -1,5 +1,5 @@
class Merchant < ApplicationRecord
- has_many :transactions, dependent: :nullify, class_name: "Account::Transaction"
+ has_many :transactions, dependent: :nullify, class_name: "Transaction"
belongs_to :family
validates :name, :color, :family, presence: true
diff --git a/app/models/mint_import.rb b/app/models/mint_import.rb
index 66e3bb69..da9ced2a 100644
--- a/app/models/mint_import.rb
+++ b/app/models/mint_import.rb
@@ -35,7 +35,7 @@ class MintImport < Import
name: row.name,
currency: row.currency,
notes: row.notes,
- entryable: Account::Transaction.new(category: category, tags: tags),
+ entryable: Transaction.new(category: category, tags: tags),
import: self
entry.save!
diff --git a/app/models/plaid_account.rb b/app/models/plaid_account.rb
index e0e71f67..4f2b923c 100644
--- a/app/models/plaid_account.rb
+++ b/app/models/plaid_account.rb
@@ -87,7 +87,7 @@ class PlaidAccount < ApplicationRecord
t.amount = plaid_txn.amount
t.currency = plaid_txn.iso_currency_code
t.date = plaid_txn.date
- t.entryable = Account::Transaction.new(
+ t.entryable = Transaction.new(
category: get_category(plaid_txn.personal_finance_category.primary),
merchant: get_merchant(plaid_txn.merchant_name)
)
@@ -120,7 +120,7 @@ class PlaidAccount < ApplicationRecord
e.amount = loan_data.origination_principal_amount
e.currency = account.currency
e.date = loan_data.origination_date
- e.entryable = Account::Valuation.new
+ e.entryable = Valuation.new
end
end
end
diff --git a/app/models/plaid_investment_sync.rb b/app/models/plaid_investment_sync.rb
index bcb1f330..489b0ca1 100644
--- a/app/models/plaid_investment_sync.rb
+++ b/app/models/plaid_investment_sync.rb
@@ -31,7 +31,7 @@ class PlaidInvestmentSync
t.amount = transaction.amount
t.currency = transaction.iso_currency_code
t.date = transaction.date
- t.entryable = Account::Transaction.new
+ t.entryable = Transaction.new
end
else
new_transaction = plaid_account.account.entries.find_or_create_by!(plaid_id: transaction.investment_transaction_id) do |t|
@@ -39,7 +39,7 @@ class PlaidInvestmentSync
t.amount = transaction.quantity * transaction.price
t.currency = transaction.iso_currency_code
t.date = transaction.date
- t.entryable = Account::Trade.new(
+ t.entryable = Trade.new(
security: security,
qty: transaction.quantity,
price: transaction.price,
diff --git a/app/models/property.rb b/app/models/property.rb
index b30a1071..42d2979e 100644
--- a/app/models/property.rb
+++ b/app/models/property.rb
@@ -44,6 +44,6 @@ class Property < ApplicationRecord
private
def first_valuation_amount
- account.entries.account_valuations.order(:date).first&.amount_money || account.balance_money
+ account.entries.valuations.order(:date).first&.amount_money || account.balance_money
end
end
diff --git a/app/models/rejected_transfer.rb b/app/models/rejected_transfer.rb
index 9d1a1ce4..4c66d44d 100644
--- a/app/models/rejected_transfer.rb
+++ b/app/models/rejected_transfer.rb
@@ -1,4 +1,4 @@
class RejectedTransfer < ApplicationRecord
- belongs_to :inflow_transaction, class_name: "Account::Transaction"
- belongs_to :outflow_transaction, class_name: "Account::Transaction"
+ belongs_to :inflow_transaction, class_name: "Transaction"
+ belongs_to :outflow_transaction, class_name: "Transaction"
end
diff --git a/app/models/security.rb b/app/models/security.rb
index 30abbe85..0adabd8a 100644
--- a/app/models/security.rb
+++ b/app/models/security.rb
@@ -3,7 +3,7 @@ class Security < ApplicationRecord
before_save :upcase_ticker
- has_many :trades, dependent: :nullify, class_name: "Account::Trade"
+ has_many :trades, dependent: :nullify, class_name: "Trade"
has_many :prices, dependent: :destroy
validates :ticker, presence: true
diff --git a/app/models/tag.rb b/app/models/tag.rb
index 6b2fb67b..c5bdc0bc 100644
--- a/app/models/tag.rb
+++ b/app/models/tag.rb
@@ -1,7 +1,7 @@
class Tag < ApplicationRecord
belongs_to :family
has_many :taggings, dependent: :destroy
- has_many :transactions, through: :taggings, source: :taggable, source_type: "Account::Transaction"
+ has_many :transactions, through: :taggings, source: :taggable, source_type: "Transaction"
has_many :import_mappings, as: :mappable, dependent: :destroy, class_name: "Import::Mapping"
validates :name, presence: true, uniqueness: { scope: :family }
diff --git a/app/models/account/trade.rb b/app/models/trade.rb
similarity index 83%
rename from app/models/account/trade.rb
rename to app/models/trade.rb
index a683b2ca..5d71d978 100644
--- a/app/models/account/trade.rb
+++ b/app/models/trade.rb
@@ -1,5 +1,5 @@
-class Account::Trade < ApplicationRecord
- include Account::Entryable, Monetizable
+class Trade < ApplicationRecord
+ include Entryable, Monetizable
monetize :price
diff --git a/app/models/account/trade_builder.rb b/app/models/trade_builder.rb
similarity index 94%
rename from app/models/account/trade_builder.rb
rename to app/models/trade_builder.rb
index c632f272..9b7e0471 100644
--- a/app/models/account/trade_builder.rb
+++ b/app/models/trade_builder.rb
@@ -1,4 +1,4 @@
-class Account::TradeBuilder
+class TradeBuilder
include ActiveModel::Model
attr_accessor :account, :date, :amount, :currency, :qty,
@@ -46,7 +46,7 @@ class Account::TradeBuilder
date: date,
amount: signed_amount,
currency: currency,
- entryable: Account::Trade.new(
+ entryable: Trade.new(
qty: signed_qty,
price: price,
currency: currency,
@@ -74,7 +74,7 @@ class Account::TradeBuilder
date: date,
amount: signed_amount,
currency: currency,
- entryable: Account::Transaction.new
+ entryable: Transaction.new
)
end
end
@@ -85,7 +85,7 @@ class Account::TradeBuilder
date: date,
amount: signed_amount,
currency: currency,
- entryable: Account::Transaction.new
+ entryable: Transaction.new
)
end
diff --git a/app/models/trade_import.rb b/app/models/trade_import.rb
index db917f04..d126fec0 100644
--- a/app/models/trade_import.rb
+++ b/app/models/trade_import.rb
@@ -16,12 +16,12 @@ class TradeImport < Import
exchange_operating_mic: row.exchange_operating_mic
)
- Account::Trade.new(
+ Trade.new(
security: security,
qty: row.qty,
currency: row.currency.presence || mapped_account.currency,
price: row.price,
- entry: Account::Entry.new(
+ entry: Entry.new(
account: mapped_account,
date: row.date_iso,
amount: row.signed_amount,
@@ -31,7 +31,7 @@ class TradeImport < Import
),
)
end
- Account::Trade.import!(trades, recursive: true)
+ Trade.import!(trades, recursive: true)
end
end
diff --git a/app/models/account/transaction.rb b/app/models/transaction.rb
similarity index 64%
rename from app/models/account/transaction.rb
rename to app/models/transaction.rb
index e31a5607..fb5fb0df 100644
--- a/app/models/account/transaction.rb
+++ b/app/models/transaction.rb
@@ -1,5 +1,5 @@
-class Account::Transaction < ApplicationRecord
- include Account::Entryable, Transferable, Provided
+class Transaction < ApplicationRecord
+ include Entryable, Transferable, Provided
belongs_to :category, optional: true
belongs_to :merchant, optional: true
@@ -11,7 +11,7 @@ class Account::Transaction < ApplicationRecord
class << self
def search(params)
- Account::TransactionSearch.new(params).build_query(all)
+ Search.new(params).build_query(all)
end
end
end
diff --git a/app/models/account/transaction/provided.rb b/app/models/transaction/provided.rb
similarity index 89%
rename from app/models/account/transaction/provided.rb
rename to app/models/transaction/provided.rb
index 4bae0ab4..b4210e0a 100644
--- a/app/models/account/transaction/provided.rb
+++ b/app/models/transaction/provided.rb
@@ -1,4 +1,4 @@
-module Account::Transaction::Provided
+module Transaction::Provided
extend ActiveSupport::Concern
def fetch_enrichment_info
diff --git a/app/models/account/transaction_search.rb b/app/models/transaction/search.rb
similarity index 77%
rename from app/models/account/transaction_search.rb
rename to app/models/transaction/search.rb
index 215c6a98..067050f4 100644
--- a/app/models/account/transaction_search.rb
+++ b/app/models/transaction/search.rb
@@ -1,4 +1,4 @@
-class Account::TransactionSearch
+class Transaction::Search
include ActiveModel::Model
include ActiveModel::Attributes
@@ -22,10 +22,10 @@ class Account::TransactionSearch
query = apply_type_filter(query, types)
query = apply_merchant_filter(query, merchants)
query = apply_tag_filter(query, tags)
- query = Account::EntrySearch.apply_search_filter(query, search)
- query = Account::EntrySearch.apply_date_filters(query, start_date, end_date)
- query = Account::EntrySearch.apply_amount_filter(query, amount, amount_operator)
- query = Account::EntrySearch.apply_accounts_filter(query, accounts, account_ids)
+ query = EntrySearch.apply_search_filter(query, search)
+ query = EntrySearch.apply_date_filters(query, start_date, end_date)
+ query = EntrySearch.apply_amount_filter(query, amount, amount_operator)
+ query = EntrySearch.apply_accounts_filter(query, accounts, account_ids)
query
end
@@ -36,12 +36,12 @@ class Account::TransactionSearch
LEFT JOIN (
SELECT t.*, t.id as transfer_id, a.accountable_type
FROM transfers t
- JOIN account_entries ae ON ae.entryable_id = t.inflow_transaction_id
- AND ae.entryable_type = 'Account::Transaction'
+ JOIN entries ae ON ae.entryable_id = t.inflow_transaction_id
+ AND ae.entryable_type = 'Transaction'
JOIN accounts a ON a.id = ae.account_id
) transfer_info ON (
- transfer_info.inflow_transaction_id = account_transactions.id OR
- transfer_info.outflow_transaction_id = account_transactions.id
+ transfer_info.inflow_transaction_id = transactions.id OR
+ transfer_info.outflow_transaction_id = transactions.id
)
SQL
end
@@ -68,8 +68,8 @@ class Account::TransactionSearch
return query if types.sort == [ "expense", "income", "transfer" ]
transfer_condition = "transfer_info.transfer_id IS NOT NULL"
- expense_condition = "account_entries.amount >= 0"
- income_condition = "account_entries.amount <= 0"
+ expense_condition = "entries.amount >= 0"
+ income_condition = "entries.amount <= 0"
condition = case types.sort
when [ "transfer" ]
diff --git a/app/models/account/transaction/transferable.rb b/app/models/transaction/transferable.rb
similarity index 96%
rename from app/models/account/transaction/transferable.rb
rename to app/models/transaction/transferable.rb
index de0b70cb..d839047a 100644
--- a/app/models/account/transaction/transferable.rb
+++ b/app/models/transaction/transferable.rb
@@ -1,4 +1,4 @@
-module Account::Transaction::Transferable
+module Transaction::Transferable
extend ActiveSupport::Concern
included do
diff --git a/app/models/transaction_import.rb b/app/models/transaction_import.rb
index cf3f6e12..dd44cca4 100644
--- a/app/models/transaction_import.rb
+++ b/app/models/transaction_import.rb
@@ -13,10 +13,10 @@ class TransactionImport < Import
category = mappings.categories.mappable_for(row.category)
tags = row.tags_list.map { |tag| mappings.tags.mappable_for(tag) }.compact
- Account::Transaction.new(
+ Transaction.new(
category: category,
tags: tags,
- entry: Account::Entry.new(
+ entry: Entry.new(
account: mapped_account,
date: row.date_iso,
amount: row.signed_amount,
@@ -28,7 +28,7 @@ class TransactionImport < Import
)
end
- Account::Transaction.import!(transactions, recursive: true)
+ Transaction.import!(transactions, recursive: true)
end
end
diff --git a/app/models/transfer.rb b/app/models/transfer.rb
index 3cb1f07b..d681d581 100644
--- a/app/models/transfer.rb
+++ b/app/models/transfer.rb
@@ -1,6 +1,6 @@
class Transfer < ApplicationRecord
- belongs_to :inflow_transaction, class_name: "Account::Transaction"
- belongs_to :outflow_transaction, class_name: "Account::Transaction"
+ belongs_to :inflow_transaction, class_name: "Transaction"
+ belongs_to :outflow_transaction, class_name: "Transaction"
enum :status, { pending: "pending", confirmed: "confirmed" }
@@ -23,22 +23,22 @@ class Transfer < ApplicationRecord
end
new(
- inflow_transaction: Account::Transaction.new(
+ inflow_transaction: Transaction.new(
entry: to_account.entries.build(
amount: converted_amount.amount.abs * -1,
currency: converted_amount.currency.iso_code,
date: date,
name: "Transfer from #{from_account.name}",
- entryable: Account::Transaction.new
+ entryable: Transaction.new
)
),
- outflow_transaction: Account::Transaction.new(
+ outflow_transaction: Transaction.new(
entry: from_account.entries.build(
amount: amount.abs,
currency: from_account.currency,
date: date,
name: "Transfer to #{to_account.name}",
- entryable: Account::Transaction.new
+ entryable: Transaction.new
)
),
status: "confirmed"
diff --git a/app/models/valuation.rb b/app/models/valuation.rb
new file mode 100644
index 00000000..6d1d2b4b
--- /dev/null
+++ b/app/models/valuation.rb
@@ -0,0 +1,3 @@
+class Valuation < ApplicationRecord
+ include Entryable
+end
diff --git a/app/models/vehicle.rb b/app/models/vehicle.rb
index 6ba19540..255e11d6 100644
--- a/app/models/vehicle.rb
+++ b/app/models/vehicle.rb
@@ -31,6 +31,6 @@ class Vehicle < ApplicationRecord
private
def first_valuation_amount
- account.entries.account_valuations.order(:date).first&.amount_money || account.balance_money
+ account.entries.valuations.order(:date).first&.amount_money || account.balance_money
end
end
diff --git a/app/views/account/transactions/_header.html.erb b/app/views/account/transactions/_header.html.erb
deleted file mode 100644
index 83f9d1b6..00000000
--- a/app/views/account/transactions/_header.html.erb
+++ /dev/null
@@ -1,23 +0,0 @@
-<%# locals: (entry:) %>
-
-<%= tag.header class: "mb-4 space-y-1", id: dom_id(entry, :header) do %>
- <div class="flex items-center gap-4">
- <h3 class="font-medium">
- <span class="text-2xl">
- <%= format_money -entry.amount_money %>
- </span>
-
- <span class="text-lg text-secondary">
- <%= entry.currency %>
- </span>
- </h3>
-
- <% if entry.account_transaction.transfer? %>
- <%= lucide_icon "arrow-left-right", class: "text-secondary mt-1 w-5 h-5" %>
- <% end %>
- </div>
-
- <span class="text-sm text-secondary">
- <%= I18n.l(entry.date, format: :long) %>
- </span>
-<% end %>
diff --git a/app/views/account/transactions/new.html.erb b/app/views/account/transactions/new.html.erb
deleted file mode 100644
index 12c8f2f2..00000000
--- a/app/views/account/transactions/new.html.erb
+++ /dev/null
@@ -1,3 +0,0 @@
-<%= modal_form_wrapper title: t(".new_transaction") do %>
- <%= render "form", entry: @entry %>
-<% end %>
diff --git a/app/views/accounts/show/_activity.html.erb b/app/views/accounts/show/_activity.html.erb
index 88d9f78c..db399472 100644
--- a/app/views/accounts/show/_activity.html.erb
+++ b/app/views/accounts/show/_activity.html.erb
@@ -11,13 +11,13 @@
<%= tag.span t(".new") %>
</button>
<div data-menu-target="content" class="z-10 hidden bg-container rounded-lg border border-alpha-black-25 shadow-xs p-1">
- <%= link_to new_account_valuation_path(account_id: @account.id), data: { turbo_frame: :modal }, class: "block p-2 rounded-lg hover:bg-gray-50 flex items-center gap-2" do %>
+ <%= link_to new_valuation_path(account_id: @account.id), data: { turbo_frame: :modal }, class: "block p-2 rounded-lg hover:bg-gray-50 flex items-center gap-2" do %>
<%= lucide_icon("circle-dollar-sign", class: "text-secondary w-5 h-5") %>
<%= tag.span t(".new_balance"), class: "text-sm" %>
<% end %>
<% unless @account.crypto? %>
- <%= link_to @account.investment? ? new_account_trade_path(account_id: @account.id) : new_account_transaction_path(account_id: @account.id), data: { turbo_frame: :modal }, class: "block p-2 rounded-lg hover:bg-gray-50 flex items-center gap-2" do %>
+ <%= link_to @account.investment? ? new_trade_path(account_id: @account.id) : new_transaction_path(account_id: @account.id), data: { turbo_frame: :modal }, class: "block p-2 rounded-lg hover:bg-gray-50 flex items-center gap-2" do %>
<%= lucide_icon("credit-card", class: "text-secondary w-5 h-5") %>
<%= tag.span t(".new_transaction"), class: "text-sm" %>
<% end %>
@@ -59,7 +59,7 @@
bulk_select_plural_label_value: t(".entries")
} do %>
<div id="entry-selection-bar" data-bulk-select-target="selectionBar" class="flex justify-center hidden">
- <%= render "account/entries/selection_bar" %>
+ <%= render "entries/selection_bar" %>
</div>
<div class="grid bg-container-inset rounded-xl grid-cols-12 items-center uppercase text-xs font-medium text-secondary px-5 py-3 mb-4">
@@ -76,7 +76,7 @@
<div>
<div class="rounded-tl-lg rounded-tr-lg bg-container border-alpha-black-25 shadow-xs">
<div class="space-y-4">
- <% calculator = Account::BalanceTrendCalculator.for(@entries) %>
+ <% calculator = Balance::TrendCalculator.for(@entries) %>
<%= entries_by_date(@entries) do |entries| %>
<% entries.each do |entry| %>
<%= render entry, balance_trend: calculator&.trend_for(entry), view_ctx: "account" %>
diff --git a/app/views/category/dropdowns/_row.html.erb b/app/views/category/dropdowns/_row.html.erb
index 5501c137..c4e0affc 100644
--- a/app/views/category/dropdowns/_row.html.erb
+++ b/app/views/category/dropdowns/_row.html.erb
@@ -5,10 +5,10 @@
class: ["filterable-item flex justify-between items-center border-none rounded-lg px-2 py-1 group w-full hover:bg-gray-25 focus-within:bg-gray-25",
{ "bg-gray-25": is_selected }],
data: { filter_name: category.name } do %>
- <%= button_to account_transaction_category_path(
+ <%= button_to transaction_category_path(
@transaction.entry,
- account_entry: {
- entryable_type: "Account::Transaction",
+ entry: {
+ entryable_type: "Transaction",
entryable_attributes: { id: @transaction.id, category_id: category.id }
}
),
diff --git a/app/views/category/dropdowns/show.html.erb b/app/views/category/dropdowns/show.html.erb
index f7ef3114..b2cefd40 100644
--- a/app/views/category/dropdowns/show.html.erb
+++ b/app/views/category/dropdowns/show.html.erb
@@ -30,10 +30,10 @@
<hr>
<div class="relative p-1.5 w-full">
<% if @transaction.category %>
- <%= button_to account_transaction_path(@transaction.entry),
+ <%= button_to transaction_path(@transaction.entry),
method: :patch,
data: { turbo_frame: dom_id(@transaction.entry) },
- params: { account_entry: { entryable_type: "Account::Transaction", entryable_attributes: { id: @transaction.id, category_id: nil } } },
+ params: { entry: { entryable_type: "Transaction", entryable_attributes: { id: @transaction.id, category_id: nil } } },
class: "flex text-sm font-medium items-center gap-2 text-secondary w-full rounded-lg p-2 hover:bg-gray-100" do %>
<%= lucide_icon "minus", class: "w-5 h-5" %>
@@ -42,7 +42,7 @@
<% end %>
<% unless @transaction.transfer? %>
- <%= link_to new_account_transaction_transfer_match_path(@transaction.entry),
+ <%= link_to new_transaction_transfer_match_path(@transaction.entry),
class: "flex text-sm font-medium items-center gap-2 text-secondary w-full rounded-lg p-2 hover:bg-gray-100",
data: { turbo_frame: "modal" } do %>
<%= lucide_icon "refresh-cw", class: "w-5 h-5" %>
@@ -53,11 +53,11 @@
<div class="flex text-sm font-medium items-center gap-2 text-secondary w-full rounded-lg p-2">
<div class="flex items-center gap-2">
- <%= form_with url: account_transaction_path(@transaction.entry),
+ <%= form_with url: transaction_path(@transaction.entry),
method: :patch,
data: { controller: "auto-submit-form" } do |f| %>
- <%= f.hidden_field "account_entry[excluded]", value: [email protected] %>
- <%= f.check_box "account_entry[excluded]",
+ <%= f.hidden_field "entry[excluded]", value: [email protected] %>
+ <%= f.check_box "entry[excluded]",
checked: @transaction.entry.excluded,
class: "checkbox checkbox--light",
data: { auto_submit_form_target: "auto", autosubmit_trigger_event: "change" } %>
diff --git a/app/views/account/entries/_empty.html.erb b/app/views/entries/_empty.html.erb
similarity index 100%
rename from app/views/account/entries/_empty.html.erb
rename to app/views/entries/_empty.html.erb
diff --git a/app/views/account/entries/_entry.html.erb b/app/views/entries/_entry.html.erb
similarity index 100%
rename from app/views/account/entries/_entry.html.erb
rename to app/views/entries/_entry.html.erb
diff --git a/app/views/account/entries/_entry_group.html.erb b/app/views/entries/_entry_group.html.erb
similarity index 100%
rename from app/views/account/entries/_entry_group.html.erb
rename to app/views/entries/_entry_group.html.erb
diff --git a/app/views/account/entries/_loading.html.erb b/app/views/entries/_loading.html.erb
similarity index 100%
rename from app/views/account/entries/_loading.html.erb
rename to app/views/entries/_loading.html.erb
diff --git a/app/views/account/entries/_ruler.html.erb b/app/views/entries/_ruler.html.erb
similarity index 100%
rename from app/views/account/entries/_ruler.html.erb
rename to app/views/entries/_ruler.html.erb
diff --git a/app/views/account/entries/_selection_bar.html.erb b/app/views/entries/_selection_bar.html.erb
similarity index 86%
rename from app/views/account/entries/_selection_bar.html.erb
rename to app/views/entries/_selection_bar.html.erb
index 78d69c45..8f0a98f3 100644
--- a/app/views/account/entries/_selection_bar.html.erb
+++ b/app/views/entries/_selection_bar.html.erb
@@ -6,7 +6,7 @@
</div>
<div class="flex items-center gap-1 text-secondary">
- <%= form_with url: bulk_delete_account_transactions_path, data: { turbo_confirm: true, turbo_frame: "_top" } do %>
+ <%= form_with url: transactions_bulk_deletion_path, data: { turbo_confirm: true, turbo_frame: "_top" } do %>
<button type="button" data-bulk-select-scope-param="bulk_delete" data-action="bulk-select#submitBulkRequest" class="p-1.5 group hover:bg-gray-700 flex items-center justify-center rounded-md" title="Delete">
<%= lucide_icon "trash-2", class: "w-5 group-hover:text-white" %>
</button>
diff --git a/app/views/account/holdings/_cash.html.erb b/app/views/holdings/_cash.html.erb
similarity index 100%
rename from app/views/account/holdings/_cash.html.erb
rename to app/views/holdings/_cash.html.erb
diff --git a/app/views/account/holdings/_holding.html.erb b/app/views/holdings/_holding.html.erb
similarity index 93%
rename from app/views/account/holdings/_holding.html.erb
rename to app/views/holdings/_holding.html.erb
index e0aca801..5fe0e4c9 100644
--- a/app/views/account/holdings/_holding.html.erb
+++ b/app/views/holdings/_holding.html.erb
@@ -6,7 +6,7 @@
<%= image_tag "https://logo.synthfinance.com/ticker/#{holding.ticker}", class: "w-9 h-9 rounded-full", loading: "lazy" %>
<div class="space-y-0.5">
- <%= link_to holding.name, account_holding_path(holding), data: { turbo_frame: :drawer }, class: "hover:underline" %>
+ <%= link_to holding.name, holding_path(holding), data: { turbo_frame: :drawer }, class: "hover:underline" %>
<% if holding.amount %>
<%= tag.p holding.ticker, class: "text-secondary text-xs uppercase" %>
diff --git a/app/views/account/holdings/_missing_price_tooltip.html.erb b/app/views/holdings/_missing_price_tooltip.html.erb
similarity index 100%
rename from app/views/account/holdings/_missing_price_tooltip.html.erb
rename to app/views/holdings/_missing_price_tooltip.html.erb
diff --git a/app/views/account/holdings/_ruler.html.erb b/app/views/holdings/_ruler.html.erb
similarity index 100%
rename from app/views/account/holdings/_ruler.html.erb
rename to app/views/holdings/_ruler.html.erb
diff --git a/app/views/account/holdings/index.html.erb b/app/views/holdings/index.html.erb
similarity index 80%
rename from app/views/account/holdings/index.html.erb
rename to app/views/holdings/index.html.erb
index 5afacc32..0b6eb62d 100644
--- a/app/views/account/holdings/index.html.erb
+++ b/app/views/holdings/index.html.erb
@@ -2,7 +2,7 @@
<div class="bg-container space-y-4 p-5 rounded-xl shadow-border-xs">
<div class="flex items-center justify-between">
<%= tag.h2 t(".holdings"), class: "font-medium text-lg" %>
- <%= link_to new_account_trade_path(account_id: @account.id),
+ <%= link_to new_trade_path(account_id: @account.id),
id: dom_id(@account, "new_trade"),
data: { turbo_frame: :modal },
class: "flex gap-1 font-medium items-center bg-gray-50 text-primary p-2 rounded-lg" do %>
@@ -21,12 +21,12 @@
</div>
<div class="rounded-lg bg-container shadow-border-xs">
- <%= render "account/holdings/cash", account: @account %>
+ <%= render "holdings/cash", account: @account %>
- <%= render "account/holdings/ruler" %>
+ <%= render "holdings/ruler" %>
<% if @account.current_holdings.any? %>
- <%= render partial: "account/holdings/holding", collection: @account.current_holdings, spacer_template: "ruler" %>
+ <%= render partial: "holdings/holding", collection: @account.current_holdings, spacer_template: "ruler" %>
<% end %>
</div>
</div>
diff --git a/app/views/account/holdings/new.html.erb b/app/views/holdings/new.html.erb
similarity index 100%
rename from app/views/account/holdings/new.html.erb
rename to app/views/holdings/new.html.erb
diff --git a/app/views/account/holdings/show.html.erb b/app/views/holdings/show.html.erb
similarity index 95%
rename from app/views/account/holdings/show.html.erb
rename to app/views/holdings/show.html.erb
index 12199512..195aba63 100644
--- a/app/views/account/holdings/show.html.erb
+++ b/app/views/holdings/show.html.erb
@@ -71,9 +71,9 @@
<p><%= t(
".trade_history_entry",
- qty: trade_entry.account_trade.qty,
- security: trade_entry.account_trade.security.ticker,
- price: trade_entry.account_trade.price_money.format
+ qty: trade_entry.trade.qty,
+ security: trade_entry.trade.security.ticker,
+ price: trade_entry.trade.price_money.format
) %></p>
</div>
</li>
@@ -102,7 +102,7 @@
</div>
<%= button_to t(".delete"),
- account_holding_path(@holding),
+ holding_path(@holding),
method: :delete,
class: "rounded-lg px-3 py-2 text-red-500 text-sm font-medium border border-secondary",
data: { turbo_confirm: true } %>
diff --git a/app/views/investments/_holdings_tab.html.erb b/app/views/investments/_holdings_tab.html.erb
index 9b68eb66..8c53933e 100644
--- a/app/views/investments/_holdings_tab.html.erb
+++ b/app/views/investments/_holdings_tab.html.erb
@@ -1,5 +1,5 @@
<%# locals: (account:) %>
-<%= turbo_frame_tag dom_id(account, :holdings), src: account_holdings_path(account_id: account.id) do %>
- <%= render "account/entries/loading" %>
+<%= turbo_frame_tag dom_id(account, :holdings), src: holdings_path(account_id: account.id) do %>
+ <%= render "entries/loading" %>
<% end %>
diff --git a/app/views/account/trades/_form.html.erb b/app/views/trades/_form.html.erb
similarity index 87%
rename from app/views/account/trades/_form.html.erb
rename to app/views/trades/_form.html.erb
index 25f4cf0a..6c00f615 100644
--- a/app/views/account/trades/_form.html.erb
+++ b/app/views/trades/_form.html.erb
@@ -2,7 +2,7 @@
<% type = params[:type] || "buy" %>
-<%= styled_form_with model: entry, url: account_trades_path, data: { controller: "trade-form" } do |form| %>
+<%= styled_form_with model: entry, url: trades_path, data: { controller: "trade-form" } do |form| %>
<%= form.hidden_field :account_id %>
@@ -22,7 +22,7 @@
{ label: t(".type"), selected: type },
{ data: {
action: "trade-form#changeType",
- trade_form_url_param: new_account_trade_path(account_id: entry.account&.id || entry.account_id),
+ trade_form_url_param: new_trade_path(account_id: entry.account&.id || entry.account_id),
trade_form_key_param: "type",
}} %>
@@ -31,7 +31,7 @@
<div class="form-field combobox">
<%= form.combobox :ticker,
securities_path(country_code: Current.family.country),
- name_when_new: "account_entry[manual_ticker]",
+ name_when_new: "entry[manual_ticker]",
label: t(".holding"),
placeholder: t(".ticker_placeholder"),
required: true %>
diff --git a/app/views/account/trades/_header.html.erb b/app/views/trades/_header.html.erb
similarity index 98%
rename from app/views/account/trades/_header.html.erb
rename to app/views/trades/_header.html.erb
index 7556790e..a649ebf5 100644
--- a/app/views/account/trades/_header.html.erb
+++ b/app/views/trades/_header.html.erb
@@ -23,7 +23,7 @@
</span>
<% end %>
- <% trade = entry.account_trade %>
+ <% trade = entry.trade %>
<div class="mb-2">
<%= disclosure t(".overview") do %>
diff --git a/app/views/account/trades/_trade.html.erb b/app/views/trades/_trade.html.erb
similarity index 97%
rename from app/views/account/trades/_trade.html.erb
rename to app/views/trades/_trade.html.erb
index 3397dfa7..9d8bed5f 100644
--- a/app/views/account/trades/_trade.html.erb
+++ b/app/views/trades/_trade.html.erb
@@ -18,7 +18,7 @@
<div class="truncate">
<%= link_to entry.display_name,
- account_entry_path(entry),
+ entry_path(entry),
data: { turbo_frame: "drawer", turbo_prefetch: false },
class: "hover:underline hover:text-gray-800" %>
</div>
diff --git a/app/views/account/trades/new.html.erb b/app/views/trades/new.html.erb
similarity index 52%
rename from app/views/account/trades/new.html.erb
rename to app/views/trades/new.html.erb
index 795e49d0..d3df030f 100644
--- a/app/views/account/trades/new.html.erb
+++ b/app/views/trades/new.html.erb
@@ -1,3 +1,3 @@
<%= modal_form_wrapper title: t(".title") do %>
- <%= render "account/trades/form", entry: @entry %>
+ <%= render "trades/form", entry: @entry %>
<% end %>
diff --git a/app/views/account/trades/show.html.erb b/app/views/trades/show.html.erb
similarity index 91%
rename from app/views/account/trades/show.html.erb
rename to app/views/trades/show.html.erb
index b45b55af..38cb890b 100644
--- a/app/views/account/trades/show.html.erb
+++ b/app/views/trades/show.html.erb
@@ -1,14 +1,14 @@
<%= drawer(reload_on_close: true) do %>
- <%= render "account/trades/header", entry: @entry %>
+ <%= render "trades/header", entry: @entry %>
- <% trade = @entry.account_trade %>
+ <% trade = @entry.trade %>
<div class="space-y-2">
<!-- Details Section -->
<%= disclosure t(".details") do %>
<div class="pb-4">
<%= styled_form_with model: @entry,
- url: account_trade_path(@entry),
+ url: trade_path(@entry),
class: "space-y-2",
data: { controller: "auto-submit-form" } do |f| %>
<%= f.date_field :date,
@@ -46,7 +46,7 @@
<%= disclosure t(".additional") do %>
<div class="pb-4">
<%= styled_form_with model: @entry,
- url: account_trade_path(@entry),
+ url: trade_path(@entry),
class: "space-y-2",
data: { controller: "auto-submit-form" } do |f| %>
<%= f.text_area :notes,
@@ -63,7 +63,7 @@
<div class="pb-4">
<!-- Exclude Trade Form -->
<%= styled_form_with model: @entry,
- url: account_trade_path(@entry),
+ url: trade_path(@entry),
class: "p-3",
data: { controller: "auto-submit-form" } do |f| %>
<div class="flex cursor-pointer items-center gap-2 justify-between">
@@ -76,7 +76,7 @@
<%= f.check_box :excluded,
class: "sr-only peer",
"data-auto-submit-form-target": "auto" %>
- <label for="account_entry_excluded"
+ <label for="entry_excluded"
class="switch"></label>
</div>
</div>
@@ -90,7 +90,7 @@
</div>
<%= button_to t(".delete"),
- account_entry_path(@entry),
+ entry_path(@entry),
method: :delete,
class: "rounded-lg px-3 py-2 text-red-500 text-sm
font-medium border border-secondary",
diff --git a/app/views/account/transactions/_form.html.erb b/app/views/transactions/_form.html.erb
similarity index 91%
rename from app/views/account/transactions/_form.html.erb
rename to app/views/transactions/_form.html.erb
index 211738c5..af3c64a4 100644
--- a/app/views/account/transactions/_form.html.erb
+++ b/app/views/transactions/_form.html.erb
@@ -1,4 +1,4 @@
-<%= styled_form_with model: @entry, url: account_transactions_path, class: "space-y-4" do |f| %>
+<%= styled_form_with model: @entry, url: transactions_path, class: "space-y-4" do |f| %>
<% if entry.errors.any? %>
<%= render "shared/form_errors", model: entry %>
@@ -18,6 +18,8 @@
<section class="space-y-2 overflow-hidden">
<%= f.text_field :name, label: t(".description"), placeholder: t(".description_placeholder"), required: true %>
+ <%= f.hidden_field :entryable_type, value: "Transaction" %>
+
<% if @entry.account_id %>
<%= f.hidden_field :account_id %>
<% else %>
@@ -28,7 +30,7 @@
<%= f.fields_for :entryable do |ef| %>
<%= ef.collection_select :category_id, Current.family.categories.alphabetically, :id, :name, { prompt: t(".category_prompt"), label: t(".category") } %>
<% end %>
- <%= f.date_field :date, label: t(".date"), required: true, min: Account::Entry.min_supported_date, max: Date.current, value: Date.current %>
+ <%= f.date_field :date, label: t(".date"), required: true, min: Entry.min_supported_date, max: Date.current, value: Date.current %>
</section>
<%= disclosure t(".details"), default_open: false do %>
diff --git a/app/views/transactions/_header.html.erb b/app/views/transactions/_header.html.erb
index cbb77fb2..5b3e75b8 100644
--- a/app/views/transactions/_header.html.erb
+++ b/app/views/transactions/_header.html.erb
@@ -1,23 +1,23 @@
-<header class="flex justify-between items-center text-primary font-medium">
- <h1 class="text-xl">Transactions</h1>
- <div class="flex items-center gap-5">
- <div class="flex items-center gap-2">
- <%= contextual_menu do %>
- <%= contextual_menu_modal_action_item t(".edit_categories"), categories_path, icon: "shapes", turbo_frame: :_top %>
- <%= contextual_menu_modal_action_item t(".edit_tags"), tags_path, icon: "tags", turbo_frame: :_top %>
- <%= contextual_menu_modal_action_item t(".edit_merchants"), merchants_path, icon: "store", turbo_frame: :_top %>
- <%= contextual_menu_modal_action_item t(".edit_imports"), imports_path, icon: "hard-drive-upload", turbo_frame: :_top %>
- <% end %>
+<%# locals: (entry:) %>
- <%= link_to new_import_path, class: "btn btn--outline flex items-center gap-2", data: { turbo_frame: "modal" } do %>
- <%= lucide_icon("download", class: "text-secondary w-4 h-4") %>
- <p class="text-sm font-medium text-primary"><%= t(".import") %></p>
- <% end %>
+<%= tag.header class: "mb-4 space-y-1", id: dom_id(entry, :header) do %>
+ <div class="flex items-center gap-4">
+ <h3 class="font-medium">
+ <span class="text-2xl">
+ <%= format_money -entry.amount_money %>
+ </span>
- <%= link_to new_account_transaction_path, class: "btn btn--primary flex items-center gap-2", data: { turbo_frame: :modal } do %>
- <%= lucide_icon("plus", class: "w-5 h-5") %>
- <p class="text-sm font-medium">New transaction</p>
- <% end %>
- </div>
+ <span class="text-lg text-secondary">
+ <%= entry.currency %>
+ </span>
+ </h3>
+
+ <% if entry.transaction.transfer? %>
+ <%= lucide_icon "arrow-left-right", class: "text-secondary mt-1 w-5 h-5" %>
+ <% end %>
</div>
-</header>
+
+ <span class="text-sm text-secondary">
+ <%= I18n.l(entry.date, format: :long) %>
+ </span>
+<% end %>
diff --git a/app/views/account/transactions/_selection_bar.html.erb b/app/views/transactions/_selection_bar.html.erb
similarity index 86%
rename from app/views/account/transactions/_selection_bar.html.erb
rename to app/views/transactions/_selection_bar.html.erb
index 5f8007af..a9f1e792 100644
--- a/app/views/account/transactions/_selection_bar.html.erb
+++ b/app/views/transactions/_selection_bar.html.erb
@@ -7,15 +7,14 @@
<div class="flex items-center gap-1 text-secondary">
<%= turbo_frame_tag "bulk_transaction_edit_drawer" %>
-
- <%= link_to bulk_edit_account_transactions_path,
+ <%= link_to new_transactions_bulk_update_path,
class: "p-1.5 group hover:bg-gray-700 flex items-center justify-center rounded-md",
title: "Edit",
data: { turbo_frame: "bulk_transaction_edit_drawer" } do %>
<%= lucide_icon "pencil-line", class: "w-5 group-hover:text-white" %>
<% end %>
- <%= form_with url: bulk_delete_account_transactions_path, data: { turbo_confirm: true, turbo_frame: "_top" } do %>
+ <%= form_with url: transactions_bulk_deletion_path, data: { turbo_confirm: true, turbo_frame: "_top" } do %>
<button type="button" data-bulk-select-scope-param="bulk_delete" data-action="bulk-select#submitBulkRequest" class="p-1.5 group hover:bg-gray-700 flex items-center justify-center rounded-md" title="Delete">
<%= lucide_icon "trash-2", class: "w-5 group-hover:text-white" %>
</button>
diff --git a/app/views/account/transactions/_transaction.html.erb b/app/views/transactions/_transaction.html.erb
similarity index 94%
rename from app/views/account/transactions/_transaction.html.erb
rename to app/views/transactions/_transaction.html.erb
index 8d589733..f9cebf03 100644
--- a/app/views/account/transactions/_transaction.html.erb
+++ b/app/views/transactions/_transaction.html.erb
@@ -36,7 +36,7 @@
<div class="flex items-center gap-1">
<%= link_to(
transaction.transfer? ? transaction.transfer.name : entry.display_name,
- transaction.transfer? ? transfer_path(transaction.transfer) : account_entry_path(entry),
+ transaction.transfer? ? transfer_path(transaction.transfer) : entry_path(entry),
data: {
turbo_frame: "drawer",
turbo_prefetch: false
@@ -51,7 +51,7 @@
<% end %>
<% if transaction.transfer? %>
- <%= render "account/transactions/transfer_match", transaction: transaction %>
+ <%= render "transactions/transfer_match", transaction: transaction %>
<% end %>
</div>
@@ -74,7 +74,7 @@
</div>
<div class="flex items-center gap-1 col-span-2">
- <%= render "account/transactions/transaction_category", transaction: transaction %>
+ <%= render "transactions/transaction_category", transaction: transaction %>
</div>
<div class="col-span-2 ml-auto">
diff --git a/app/views/account/transactions/_transaction_category.html.erb b/app/views/transactions/_transaction_category.html.erb
similarity index 100%
rename from app/views/account/transactions/_transaction_category.html.erb
rename to app/views/transactions/_transaction_category.html.erb
diff --git a/app/views/account/transactions/_transfer_match.html.erb b/app/views/transactions/_transfer_match.html.erb
similarity index 100%
rename from app/views/account/transactions/_transfer_match.html.erb
rename to app/views/transactions/_transfer_match.html.erb
diff --git a/app/views/account/transactions/bulk_edit.html.erb b/app/views/transactions/bulk_updates/new.html.erb
similarity index 71%
rename from app/views/account/transactions/bulk_edit.html.erb
rename to app/views/transactions/bulk_updates/new.html.erb
index 7c0a7e0f..80c04526 100644
--- a/app/views/account/transactions/bulk_edit.html.erb
+++ b/app/views/transactions/bulk_updates/new.html.erb
@@ -2,7 +2,7 @@
<dialog data-controller="modal"
data-action="mousedown->modal#clickOutside"
class="bg-container shadow-border-xs rounded-2xl max-h-[calc(100vh-32px)] h-full max-w-[480px] w-full mt-4 mr-4 ml-auto">
- <%= styled_form_with url: bulk_update_account_transactions_path, scope: "bulk_update", class: "h-full", data: { turbo_frame: "_top" } do |form| %>
+ <%= styled_form_with url: transactions_bulk_update_path, scope: "bulk_update", class: "h-full", data: { turbo_frame: "_top" } do |form| %>
<div class="flex h-full flex-col justify-between p-4 gap-4">
<div>
<div class="flex h-9 items-center justify-end">
@@ -22,26 +22,26 @@
<div class="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-secondary bg-gray-25 focus-visible:outline-hidden">
- <h4><%= t(".overview") %></h4>
+ <h4>Overview</h4>
<%= lucide_icon "chevron-down", class: "group-open:transform group-open:rotate-180 text-secondary w-5" %>
</summary>
<div class="pb-6 space-y-2">
- <%= form.date_field :date, label: t(".date_label"), max: Date.current %>
+ <%= form.date_field :date, label: "Date", max: Date.current %>
</div>
</details>
<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-secondary bg-gray-25 focus-visible:outline-hidden">
- <h4><%= t(".details") %></h4>
+ <h4>Details</h4>
<%= lucide_icon "chevron-down", class: "group-open:transform group-open:rotate-180 text-secondary w-5" %>
</summary>
<div class="space-y-2">
- <%= form.collection_select :category_id, Current.family.categories.alphabetically, :id, :name, { prompt: t(".category_placeholder"), label: t(".category_label"), class: "text-subdued" } %>
- <%= form.collection_select :merchant_id, Current.family.merchants.alphabetically, :id, :name, { prompt: t(".merchant_placeholder"), label: t(".merchant_label"), class: "text-subdued" } %>
- <%= form.select :tag_ids, Current.family.tags.alphabetically.pluck(:name, :id), { include_blank: t(".none"), multiple: true, label: t(".tag_label"), container_class: "h-40" } %>
- <%= form.text_area :notes, label: t(".note_label"), placeholder: t(".note_placeholder"), rows: 5 %>
+ <%= form.collection_select :category_id, Current.family.categories.alphabetically, :id, :name, { prompt: "Select a category", label: "Category", class: "text-subdued" } %>
+ <%= form.collection_select :merchant_id, Current.family.merchants.alphabetically, :id, :name, { prompt: "Select a merchant", label: "Merchant", class: "text-subdued" } %>
+ <%= form.select :tag_ids, Current.family.tags.alphabetically.pluck(:name, :id), { include_blank: "None", multiple: true, label: "Tags", container_class: "h-40" } %>
+ <%= form.text_area :notes, label: "Notes", placeholder: "Enter a note that will be applied to selected transactions", rows: 5 %>
</div>
</details>
</div>
@@ -50,9 +50,9 @@
</div>
<div class="flex justify-end items-center gap-2">
- <%= link_to t(".cancel"), transactions_path, class: "btn btn--ghost" %>
+ <%= link_to "Cancel", transactions_path, class: "btn btn--ghost" %>
- <%= tag.button t(".save"),
+ <%= tag.button "Save",
type: "button",
data: { "bulk-select-scope-param": "bulk_update", action: "bulk-select#submitBulkRequest" },
class: "btn btn--primary" %>
diff --git a/app/views/transactions/index.html.erb b/app/views/transactions/index.html.erb
index f04c877c..bc2c371a 100644
--- a/app/views/transactions/index.html.erb
+++ b/app/views/transactions/index.html.erb
@@ -1,5 +1,27 @@
<div class="space-y-4 pb-20 flex flex-col" data-controller="focus-record" data-focus-record-id-value="<%= @focused_record ? dom_id(@focused_record) : nil %>">
- <%= render "header" %>
+ <header class="flex justify-between items-center text-primary font-medium">
+ <h1 class="text-xl">Transactions</h1>
+ <div class="flex items-center gap-5">
+ <div class="flex items-center gap-2">
+ <%= contextual_menu do %>
+ <%= contextual_menu_modal_action_item t(".edit_categories"), categories_path, icon: "shapes", turbo_frame: :_top %>
+ <%= contextual_menu_modal_action_item t(".edit_tags"), tags_path, icon: "tags", turbo_frame: :_top %>
+ <%= contextual_menu_modal_action_item t(".edit_merchants"), merchants_path, icon: "store", turbo_frame: :_top %>
+ <%= contextual_menu_modal_action_item t(".edit_imports"), imports_path, icon: "hard-drive-upload", turbo_frame: :_top %>
+ <% end %>
+
+ <%= link_to new_import_path, class: "btn btn--outline flex items-center gap-2", data: { turbo_frame: "modal" } do %>
+ <%= lucide_icon("download", class: "text-secondary w-4 h-4") %>
+ <p class="text-sm font-medium text-primary"><%= t(".import") %></p>
+ <% end %>
+
+ <%= link_to new_transaction_path, class: "btn btn--primary flex items-center gap-2", data: { turbo_frame: :modal } do %>
+ <%= lucide_icon("plus", class: "w-5 h-5") %>
+ <p class="text-sm font-medium">New transaction</p>
+ <% end %>
+ </div>
+ </div>
+ </header>
<%= render "summary", totals: @totals %>
@@ -11,7 +33,7 @@
<%= render "transactions/searches/search" %>
<div id="entry-selection-bar" data-bulk-select-target="selectionBar" class="flex justify-center hidden">
- <%= render "account/transactions/selection_bar" %>
+ <%= render "transactions/selection_bar" %>
</div>
<% if @pagy.count > 0 %>
@@ -34,7 +56,7 @@
</div>
</div>
<% else %>
- <%= render "account/entries/empty" %>
+ <%= render "entries/empty" %>
<% end %>
<div class="pt-4">
diff --git a/app/views/transactions/new.html.erb b/app/views/transactions/new.html.erb
new file mode 100644
index 00000000..3ad75f36
--- /dev/null
+++ b/app/views/transactions/new.html.erb
@@ -0,0 +1,3 @@
+<%= modal_form_wrapper title: "New transaction" do %>
+ <%= render "form", entry: @entry %>
+<% end %>
diff --git a/app/views/account/transactions/show.html.erb b/app/views/transactions/show.html.erb
similarity index 90%
rename from app/views/account/transactions/show.html.erb
rename to app/views/transactions/show.html.erb
index e101e8cf..bf078dd3 100644
--- a/app/views/account/transactions/show.html.erb
+++ b/app/views/transactions/show.html.erb
@@ -1,12 +1,12 @@
<%= drawer(reload_on_close: true) do %>
- <%= render "account/transactions/header", entry: @entry %>
+ <%= render "transactions/header", entry: @entry %>
<div class="space-y-2">
<!-- Overview Section -->
<%= disclosure t(".overview") do %>
<div class="pb-4">
<%= styled_form_with model: @entry,
- url: account_transaction_path(@entry),
+ url: transaction_path(@entry),
class: "space-y-2",
data: { controller: "auto-submit-form" } do |f| %>
@@ -19,7 +19,7 @@
max: Date.current,
"data-auto-submit-form-target": "auto" %>
- <% unless @entry.account_transaction.transfer? %>
+ <% unless @entry.transaction.transfer? %>
<div class="flex items-center gap-2">
<%= f.select :nature,
[["Expense", "outflow"], ["Income", "inflow"]],
@@ -51,10 +51,10 @@
<%= disclosure t(".details"), default_open: false do %>
<div class="pb-4">
<%= styled_form_with model: @entry,
- url: account_transaction_path(@entry),
+ url: transaction_path(@entry),
class: "space-y-2",
data: { controller: "auto-submit-form" } do |f| %>
- <% unless @entry.account_transaction.transfer? %>
+ <% unless @entry.transaction.transfer? %>
<%= f.select :account,
options_for_select(
Current.family.accounts.alphabetically.pluck(:name, :id),
@@ -100,7 +100,7 @@
<div class="pb-4">
<%= styled_form_with model: @entry,
- url: account_transaction_path(@entry),
+ url: transaction_path(@entry),
class: "p-3",
data: { controller: "auto-submit-form" } do |f| %>
<div class="flex cursor-pointer items-center gap-4 justify-between">
@@ -113,7 +113,7 @@
<%= f.check_box :excluded,
class: "sr-only peer",
"data-auto-submit-form-target": "auto" %>
- <label for="account_entry_excluded"
+ <label for="entry_excluded"
class="switch"></label>
</div>
</div>
@@ -125,7 +125,7 @@
<p class="text-secondary">Transfers and payments are special types of transactions that indicate money movement between 2 accounts.</p>
</div>
- <%= link_to new_account_transaction_transfer_match_path(@entry), class: "btn btn--outline flex items-center gap-2", data: { turbo_frame: :modal } do %>
+ <%= link_to new_transaction_transfer_match_path(@entry), class: "btn btn--outline flex items-center gap-2", data: { turbo_frame: :modal } do %>
<%= lucide_icon "arrow-left-right", class: "w-4 h-4 shrink-0" %>
<span class="whitespace-nowrap">Open matcher</span>
<% end %>
@@ -139,7 +139,7 @@
</div>
<%= button_to t(".delete"),
- account_entry_path(@entry),
+ entry_path(@entry),
method: :delete,
class: "rounded-lg px-3 py-2 text-red-500 text-sm
font-medium border border-secondary",
diff --git a/app/views/account/transfer_matches/_matching_fields.html.erb b/app/views/transfer_matches/_matching_fields.html.erb
similarity index 100%
rename from app/views/account/transfer_matches/_matching_fields.html.erb
rename to app/views/transfer_matches/_matching_fields.html.erb
diff --git a/app/views/account/transfer_matches/new.html.erb b/app/views/transfer_matches/new.html.erb
similarity index 91%
rename from app/views/account/transfer_matches/new.html.erb
rename to app/views/transfer_matches/new.html.erb
index 237c4d0e..d8a7e3f4 100644
--- a/app/views/account/transfer_matches/new.html.erb
+++ b/app/views/transfer_matches/new.html.erb
@@ -1,6 +1,6 @@
<%= modal_form_wrapper title: "Match transfer or payment" do %>
<%= styled_form_with(
- url: account_transaction_transfer_match_path(@entry),
+ url: transaction_transfer_match_path(@entry),
scope: :transfer_match,
class: "space-y-8",
data: { turbo_frame: :_top }
@@ -22,7 +22,7 @@
disabled: true
) %>
<% else %>
- <%= render "account/transfer_matches/matching_fields",
+ <%= render "transfer_matches/matching_fields",
form: f, entry: @entry, candidates: @transfer_match_candidates.map { |pm| pm.outflow_transaction.entry }, accounts: @accounts %>
<% end %>
</div>
@@ -49,7 +49,7 @@
disabled: true
) %>
<% else %>
- <%= render "account/transfer_matches/matching_fields",
+ <%= render "transfer_matches/matching_fields",
form: f, entry: @entry, candidates: @transfer_match_candidates.map { |pm| pm.inflow_transaction.entry }, accounts: @accounts %>
<% end %>
</div>
diff --git a/app/views/transfers/_form.html.erb b/app/views/transfers/_form.html.erb
index 9f05a104..f929882a 100644
--- a/app/views/transfers/_form.html.erb
+++ b/app/views/transfers/_form.html.erb
@@ -8,12 +8,12 @@
<section>
<fieldset class="bg-gray-50 rounded-lg p-1 grid grid-flow-col justify-stretch gap-x-2">
- <%= link_to new_account_transaction_path(nature: "expense"), data: { turbo_frame: :modal }, class: "flex px-4 py-1 rounded-lg items-center space-x-2 justify-center text-subdued" do %>
+ <%= link_to new_transaction_path(nature: "expense"), data: { turbo_frame: :modal }, class: "flex px-4 py-1 rounded-lg items-center space-x-2 justify-center text-subdued" do %>
<%= lucide_icon "minus-circle", class: "w-5 h-5" %>
<%= tag.span t(".expense") %>
<% end %>
- <%= link_to new_account_transaction_path(nature: "income"), data: { turbo_frame: :modal }, class: "flex px-4 py-1 rounded-lg items-center space-x-2 justify-center text-subdued" do %>
+ <%= link_to new_transaction_path(nature: "income"), data: { turbo_frame: :modal }, class: "flex px-4 py-1 rounded-lg items-center space-x-2 justify-center text-subdued" do %>
<%= lucide_icon "plus-circle", class: "w-5 h-5" %>
<%= tag.span t(".income") %>
<% end %>
diff --git a/app/views/transfers/update.turbo_stream.erb b/app/views/transfers/update.turbo_stream.erb
index 2b1dd499..82a503d0 100644
--- a/app/views/transfers/update.turbo_stream.erb
+++ b/app/views/transfers/update.turbo_stream.erb
@@ -3,18 +3,18 @@
<%= turbo_stream.replace @transfer.outflow_transaction.entry %>
<%= turbo_stream.replace dom_id(@transfer.inflow_transaction, "category_menu"),
- partial: "account/transactions/transaction_category",
+ partial: "transactions/transaction_category",
locals: { transaction: @transfer.inflow_transaction } %>
<%= turbo_stream.replace dom_id(@transfer.outflow_transaction, "category_menu"),
- partial: "account/transactions/transaction_category",
+ partial: "transactions/transaction_category",
locals: { transaction: @transfer.outflow_transaction } %>
<%= turbo_stream.replace dom_id(@transfer.inflow_transaction, "transfer_match"),
- partial: "account/transactions/transfer_match",
+ partial: "transactions/transfer_match",
locals: { transaction: @transfer.inflow_transaction } %>
<%= turbo_stream.replace dom_id(@transfer.outflow_transaction, "transfer_match"),
- partial: "account/transactions/transfer_match",
+ partial: "transactions/transfer_match",
locals: { transaction: @transfer.outflow_transaction } %>
<% end %>
diff --git a/app/views/account/valuations/_form.html.erb b/app/views/valuations/_form.html.erb
similarity index 71%
rename from app/views/account/valuations/_form.html.erb
rename to app/views/valuations/_form.html.erb
index f3f0aa5f..287d057f 100644
--- a/app/views/account/valuations/_form.html.erb
+++ b/app/views/valuations/_form.html.erb
@@ -1,6 +1,6 @@
<%# locals: (entry:) %>
-<%= styled_form_with model: entry, url: account_valuations_path, class: "space-y-4" do |form| %>
+<%= styled_form_with model: entry, url: valuations_path, class: "space-y-4" do |form| %>
<%= form.hidden_field :account_id %>
<% if entry.errors.any? %>
@@ -9,7 +9,7 @@
<div class="space-y-3">
<%= form.hidden_field :name, value: "Balance update" %>
- <%= form.date_field :date, label: true, required: true, value: Date.current, min: Account::Entry.min_supported_date, max: Date.current %>
+ <%= form.date_field :date, label: true, required: true, value: Date.current, min: Entry.min_supported_date, max: Date.current %>
<%= form.money_field :amount, label: t(".amount"), required: true %>
</div>
diff --git a/app/views/account/valuations/_header.html.erb b/app/views/valuations/_header.html.erb
similarity index 100%
rename from app/views/account/valuations/_header.html.erb
rename to app/views/valuations/_header.html.erb
diff --git a/app/views/account/valuations/_valuation.html.erb b/app/views/valuations/_valuation.html.erb
similarity index 97%
rename from app/views/account/valuations/_valuation.html.erb
rename to app/views/valuations/_valuation.html.erb
index 39e4e0d1..09694b34 100644
--- a/app/views/account/valuations/_valuation.html.erb
+++ b/app/views/valuations/_valuation.html.erb
@@ -20,7 +20,7 @@
<div class="truncate text-primary">
<%= link_to entry.display_name,
- account_entry_path(entry),
+ entry_path(entry),
data: { turbo_frame: "drawer", turbo_prefetch: false },
class: "hover:underline hover:text-gray-800" %>
</div>
diff --git a/app/views/account/valuations/index.html.erb b/app/views/valuations/index.html.erb
similarity index 82%
rename from app/views/account/valuations/index.html.erb
rename to app/views/valuations/index.html.erb
index 1100431c..7487fa46 100644
--- a/app/views/account/valuations/index.html.erb
+++ b/app/views/valuations/index.html.erb
@@ -2,8 +2,8 @@
<div class="bg-container space-y-4 p-5 shadow-border-xs rounded-xl">
<div class="flex items-center justify-between">
<%= tag.h2 t(".valuations"), class: "font-medium text-lg" %>
- <%= link_to new_account_valuation_path(@account),
- data: { turbo_frame: dom_id(@account.entries.account_valuations.new) },
+ <%= link_to new_valuation_path(@account),
+ data: { turbo_frame: dom_id(@account.entries.valuations.new) },
class: "flex gap-1 font-medium items-center bg-gray-50 text-primary p-2 rounded-lg" do %>
<%= lucide_icon("plus", class: "w-5 h-5 text-primary") %>
<%= tag.span t(".new_entry"), class: "text-sm" %>
@@ -19,13 +19,13 @@
</div>
<div class="rounded-lg bg-container shadow-border-xs">
- <%= turbo_frame_tag dom_id(@account.entries.account_valuations.new) %>
+ <%= turbo_frame_tag dom_id(@account.entries.valuations.new) %>
<% if @entries.any? %>
- <%= render partial: "account/valuations/valuation",
+ <%= render partial: "valuations/valuation",
collection: @entries,
as: :entry,
- spacer_template: "account/entries/ruler" %>
+ spacer_template: "entries/ruler" %>
<% else %>
<p class="text-secondary text-sm p-4"><%= t(".no_valuations") %></p>
<% end %>
diff --git a/app/views/account/valuations/new.html.erb b/app/views/valuations/new.html.erb
similarity index 100%
rename from app/views/account/valuations/new.html.erb
rename to app/views/valuations/new.html.erb
diff --git a/app/views/account/valuations/show.html.erb b/app/views/valuations/show.html.erb
similarity index 91%
rename from app/views/account/valuations/show.html.erb
rename to app/views/valuations/show.html.erb
index 4deec8a6..94d01569 100644
--- a/app/views/account/valuations/show.html.erb
+++ b/app/views/valuations/show.html.erb
@@ -1,14 +1,14 @@
<% entry, account = @entry, @entry.account %>
<%= drawer(reload_on_close: true) do %>
- <%= render "account/valuations/header", entry: %>
+ <%= render "valuations/header", entry: %>
<div class="space-y-2">
<!-- Overview Section -->
<%= disclosure t(".overview") do %>
<div class="pb-4">
<%= styled_form_with model: entry,
- url: account_entry_path(entry),
+ url: entry_path(entry),
class: "space-y-2",
data: { controller: "auto-submit-form" } do |f| %>
<%= f.text_field :name,
@@ -33,7 +33,7 @@
<%= disclosure t(".details") do %>
<div class="pb-4">
<%= styled_form_with model: entry,
- url: account_entry_path(entry),
+ url: entry_path(entry),
class: "space-y-2",
data: { controller: "auto-submit-form" } do |f| %>
<%= f.text_area :notes,
@@ -56,7 +56,7 @@
</div>
<%= button_to t(".delete"),
- account_entry_path(entry),
+ entry_path(entry),
method: :delete,
class: "rounded-lg px-3 py-2 text-red-500 text-sm font-medium border border-secondary",
data: { turbo_confirm: true, turbo_frame: "_top" } %>
diff --git a/config/brakeman.ignore b/config/brakeman.ignore
index 0040f4b9..7e906eb4 100644
--- a/config/brakeman.ignore
+++ b/config/brakeman.ignore
@@ -1,28 +1,5 @@
{
"ignored_warnings": [
- {
- "warning_type": "Mass Assignment",
- "warning_code": 105,
- "fingerprint": "5bfdb129316655dc4e02f3a599156660414a6562212a5f61057d376f6888f078",
- "check_name": "PermitAttributes",
- "message": "Potentially dangerous key allowed for mass assignment",
- "file": "app/controllers/concerns/entryable_resource.rb",
- "line": 124,
- "link": "https://brakemanscanner.org/docs/warning_types/mass_assignment/",
- "code": "params.require(:account_entry).permit(:account_id, :name, :enriched_name, :date, :amount, :currency, :excluded, :notes, :nature, :entryable_attributes => self.class.permitted_entryable_attributes)",
- "render_path": null,
- "location": {
- "type": "method",
- "class": "EntryableResource",
- "method": "entry_params"
- },
- "user_input": ":account_id",
- "confidence": "High",
- "cwe_id": [
- 915
- ],
- "note": ""
- },
{
"warning_type": "Mass Assignment",
"warning_code": 105,
@@ -46,40 +23,6 @@
],
"note": ""
},
- {
- "warning_type": "Cross-Site Scripting",
- "warning_code": 2,
- "fingerprint": "b1f821a5c03b8aa348fb21b9297081a3bf9e954244290e7e511c67213d35f3dc",
- "check_name": "CrossSiteScripting",
- "message": "Unescaped model attribute",
- "file": "app/views/pages/changelog.html.erb",
- "line": 18,
- "link": "https://brakemanscanner.org/docs/warning_types/cross_site_scripting",
- "code": "Provider::Github.new.fetch_latest_release_notes[:body]",
- "render_path": [
- {
- "type": "controller",
- "class": "PagesController",
- "method": "changelog",
- "line": 15,
- "file": "app/controllers/pages_controller.rb",
- "rendered": {
- "name": "pages/changelog",
- "file": "app/views/pages/changelog.html.erb"
- }
- }
- ],
- "location": {
- "type": "template",
- "template": "pages/changelog"
- },
- "user_input": null,
- "confidence": "High",
- "cwe_id": [
- 79
- ],
- "note": ""
- },
{
"warning_type": "Dangerous Eval",
"warning_code": 13,
@@ -139,5 +82,5 @@
"note": ""
}
],
- "brakeman_version": "7.0.0"
+ "brakeman_version": "7.0.2"
}
diff --git a/config/locales/models/account/entry/en.yml b/config/locales/models/entry/en.yml
similarity index 90%
rename from config/locales/models/account/entry/en.yml
rename to config/locales/models/entry/en.yml
index e1e0605e..18bfda25 100644
--- a/config/locales/models/account/entry/en.yml
+++ b/config/locales/models/entry/en.yml
@@ -3,7 +3,7 @@ en:
activerecord:
errors:
models:
- account/entry:
+ entry:
attributes:
base:
invalid_sell_quantity: cannot sell %{sell_qty} shares of %{ticker} because
diff --git a/config/locales/views/account/entries/en.yml b/config/locales/views/account/entries/en.yml
deleted file mode 100644
index 10b2acdb..00000000
--- a/config/locales/views/account/entries/en.yml
+++ /dev/null
@@ -1,15 +0,0 @@
----
-en:
- account:
- entries:
- create:
- success: Entry created
- destroy:
- success: Entry deleted
- empty:
- description: Try adding an entry, editing filters or refining your search
- title: No entries found
- loading:
- loading: Loading entries...
- update:
- success: Entry updated
diff --git a/config/locales/views/account/holdings/en.yml b/config/locales/views/account/holdings/en.yml
deleted file mode 100644
index 08a1baf3..00000000
--- a/config/locales/views/account/holdings/en.yml
+++ /dev/null
@@ -1,38 +0,0 @@
----
-en:
- account:
- holdings:
- cash:
- brokerage_cash: Brokerage cash
- destroy:
- success: Holding deleted
- holding:
- per_share: per share
- shares: "%{qty} shares"
- index:
- cost: cost
- holdings: Holdings
- name: name
- new_holding: New transaction
- no_holdings: No holdings to show.
- return: total return
- weight: weight
- missing_price_tooltip:
- description: This investment has missing values and we could not calculate
- its returns or value.
- missing_data: Missing data
- 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
- overview: Overview
- portfolio_weight_label: Portfolio Weight
- settings: Settings
- ticker_label: Ticker
- trade_history_entry: "%{qty} shares of %{security} at %{price}"
- trend_label: Trend
- unknown: Unknown
diff --git a/config/locales/views/account/trades/en.yml b/config/locales/views/account/trades/en.yml
deleted file mode 100644
index 5aa3f857..00000000
--- a/config/locales/views/account/trades/en.yml
+++ /dev/null
@@ -1,39 +0,0 @@
----
-en:
- account:
- trades:
- form:
- account: Transfer account (optional)
- account_prompt: Search account
- amount: Amount
- holding: Ticker symbol
- price: Price per share
- qty: Quantity
- submit: Add transaction
- ticker_placeholder: AAPL
- type: Type
- header:
- buy: Buy
- current_market_price_label: Current Market Price
- overview: Overview
- purchase_price_label: Purchase Price
- purchase_qty_label: Purchase Quantity
- sell: Sell
- symbol_label: Symbol
- total_return_label: Unrealized gain/loss
- new:
- title: New transaction
- show:
- additional: Additional
- cost_per_share_label: Cost per Share
- 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...
- quantity_label: Quantity
- settings: Settings
diff --git a/config/locales/views/account/transactions/en.yml b/config/locales/views/account/transactions/en.yml
deleted file mode 100644
index a5f979e3..00000000
--- a/config/locales/views/account/transactions/en.yml
+++ /dev/null
@@ -1,64 +0,0 @@
----
-en:
- account:
- transactions:
- bulk_delete:
- success: "%{count} transactions deleted"
- bulk_edit:
- cancel: Cancel
- category_label: Category
- category_placeholder: Select a category
- date_label: Date
- details: Details
- merchant_label: Merchant
- merchant_placeholder: Select a merchant
- none: (none)
- note_label: Notes
- note_placeholder: Enter a note that will be applied to selected transactions
- overview: Overview
- save: Save
- tag_label: Tags
- bulk_update:
- success: "%{count} transactions updated"
- form:
- account: Account
- account_prompt: Select an Account
- amount: Amount
- category: Category
- category_prompt: Select a Category
- date: Date
- description: Description
- description_placeholder: Describe transaction
- expense: Expense
- income: Income
- none: (none)
- note_label: Notes
- note_placeholder: Enter a note
- submit: Add transaction
- tags_label: Tags
- transfer: Transfer
- new:
- new_transaction: New transaction
- show:
- account_label: Account
- amount: Amount
- category_label: Category
- date_label: Date
- delete: Delete
- delete_subtitle: This permanently deletes the transaction, affects your historical
- balances, and cannot be undone.
- delete_title: Delete transaction
- details: Details
- merchant_label: Merchant
- name_label: Name
- nature: Type
- none: "(none)"
- note_label: Notes
- note_placeholder: Enter a note
- overview: Overview
- settings: Settings
- tags_label: Tags
- uncategorized: "(uncategorized)"
- transfer_matches:
- create:
- success: Transfer created
diff --git a/config/locales/views/account/valuations/en.yml b/config/locales/views/account/valuations/en.yml
deleted file mode 100644
index c157b6d6..00000000
--- a/config/locales/views/account/valuations/en.yml
+++ /dev/null
@@ -1,31 +0,0 @@
----
-en:
- account:
- valuations:
- form:
- amount: Amount
- submit: Add balance update
- header:
- balance: Balance
- index:
- change: change
- date: date
- new_entry: New entry
- no_valuations: No valuations for this account yet
- valuations: Value
- value: value
- new:
- title: New balance
- show:
- amount: Amount
- date_label: Date
- delete: Delete
- delete_subtitle: This action cannot be undone
- delete_title: Delete Entry
- details: Details
- name_label: Name
- name_placeholder: Enter a name for this entry
- note_label: Notes
- note_placeholder: Add any additional details about this entry
- overview: Overview
- settings: Settings
diff --git a/config/locales/views/entries/en.yml b/config/locales/views/entries/en.yml
new file mode 100644
index 00000000..4303d73f
--- /dev/null
+++ b/config/locales/views/entries/en.yml
@@ -0,0 +1,14 @@
+---
+en:
+ entries:
+ create:
+ success: Entry created
+ destroy:
+ success: Entry deleted
+ empty:
+ description: Try adding an entry, editing filters or refining your search
+ title: No entries found
+ loading:
+ loading: Loading entries...
+ update:
+ success: Entry updated
diff --git a/config/locales/views/holdings/en.yml b/config/locales/views/holdings/en.yml
new file mode 100644
index 00000000..3003d629
--- /dev/null
+++ b/config/locales/views/holdings/en.yml
@@ -0,0 +1,37 @@
+---
+en:
+ holdings:
+ cash:
+ brokerage_cash: Brokerage cash
+ destroy:
+ success: Holding deleted
+ holding:
+ per_share: per share
+ shares: "%{qty} shares"
+ index:
+ cost: cost
+ holdings: Holdings
+ name: name
+ new_holding: New transaction
+ no_holdings: No holdings to show.
+ return: total return
+ weight: weight
+ missing_price_tooltip:
+ description: This investment has missing values and we could not calculate
+ its returns or value.
+ missing_data: Missing data
+ 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
+ overview: Overview
+ portfolio_weight_label: Portfolio Weight
+ settings: Settings
+ ticker_label: Ticker
+ trade_history_entry: "%{qty} shares of %{security} at %{price}"
+ trend_label: Trend
+ unknown: Unknown
diff --git a/config/locales/views/trades/en.yml b/config/locales/views/trades/en.yml
new file mode 100644
index 00000000..95955865
--- /dev/null
+++ b/config/locales/views/trades/en.yml
@@ -0,0 +1,38 @@
+---
+en:
+ trades:
+ form:
+ account: Transfer account (optional)
+ account_prompt: Search account
+ amount: Amount
+ holding: Ticker symbol
+ price: Price per share
+ qty: Quantity
+ submit: Add transaction
+ ticker_placeholder: AAPL
+ type: Type
+ header:
+ buy: Buy
+ current_market_price_label: Current Market Price
+ overview: Overview
+ purchase_price_label: Purchase Price
+ purchase_qty_label: Purchase Quantity
+ sell: Sell
+ symbol_label: Symbol
+ total_return_label: Unrealized gain/loss
+ new:
+ title: New transaction
+ show:
+ additional: Additional
+ cost_per_share_label: Cost per Share
+ 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...
+ quantity_label: Quantity
+ settings: Settings
diff --git a/config/locales/views/transactions/en.yml b/config/locales/views/transactions/en.yml
index 5e6ab631..0655145f 100644
--- a/config/locales/views/transactions/en.yml
+++ b/config/locales/views/transactions/en.yml
@@ -1,6 +1,45 @@
---
en:
transactions:
+ form:
+ account: Account
+ account_prompt: Select an Account
+ amount: Amount
+ category: Category
+ category_prompt: Select a Category
+ date: Date
+ description: Description
+ description_placeholder: Describe transaction
+ expense: Expense
+ income: Income
+ none: (none)
+ note_label: Notes
+ note_placeholder: Enter a note
+ submit: Add transaction
+ tags_label: Tags
+ transfer: Transfer
+ new:
+ new_transaction: New transaction
+ show:
+ account_label: Account
+ amount: Amount
+ category_label: Category
+ date_label: Date
+ delete: Delete
+ delete_subtitle: This permanently deletes the transaction, affects your historical
+ balances, and cannot be undone.
+ delete_title: Delete transaction
+ details: Details
+ merchant_label: Merchant
+ name_label: Name
+ nature: Type
+ none: "(none)"
+ note_label: Notes
+ note_placeholder: Enter a note
+ overview: Overview
+ settings: Settings
+ tags_label: Tags
+ uncategorized: "(uncategorized)"
header:
edit_categories: Edit categories
edit_imports: Edit imports
diff --git a/config/locales/views/valuations/en.yml b/config/locales/views/valuations/en.yml
new file mode 100644
index 00000000..7b4ede9d
--- /dev/null
+++ b/config/locales/views/valuations/en.yml
@@ -0,0 +1,30 @@
+---
+en:
+ valuations:
+ form:
+ amount: Amount
+ submit: Add balance update
+ header:
+ balance: Balance
+ index:
+ change: change
+ date: date
+ new_entry: New entry
+ no_valuations: No valuations for this account yet
+ valuations: Value
+ value: value
+ new:
+ title: New balance
+ show:
+ amount: Amount
+ date_label: Date
+ delete: Delete
+ delete_subtitle: This action cannot be undone
+ delete_title: Delete Entry
+ details: Details
+ name_label: Name
+ name_placeholder: Enter a name for this entry
+ note_label: Notes
+ note_placeholder: Add any additional details about this entry
+ overview: Overview
+ settings: Settings
diff --git a/config/routes.rb b/config/routes.rb
index e8e072ae..b4767b46 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -95,7 +95,7 @@ Rails.application.routes.draw do
resources :mappings, only: :update, module: :import
end
- resources :accounts, only: %i[index new] do
+ resources :accounts, only: %i[index new], shallow: true do
collection do
post :sync_all
end
@@ -107,42 +107,34 @@ Rails.application.routes.draw do
end
end
- resources :accountable_sparklines, only: :show, param: :accountable_type
+ resources :holdings, only: %i[index new show destroy]
+ resources :trades, only: %i[show new create update destroy]
+ resources :valuations, only: %i[show new create update destroy]
- namespace :account do
- resources :holdings, only: %i[index new show destroy]
+ namespace :transactions do
+ resource :bulk_deletion, only: :create
+ resource :bulk_update, only: %i[new create]
+ end
- resources :transactions, only: %i[show new create update destroy] do
- resource :transfer_match, only: %i[new create]
- resource :category, only: :update, controller: :transaction_categories
+ resources :transactions, only: %i[index new create show update destroy] do
+ resource :transfer_match, only: %i[new create]
+ resource :category, only: :update, controller: :transaction_categories
- collection do
- post "bulk_delete"
- get "bulk_edit"
- post "bulk_update"
- post "mark_transfers"
- post "unmark_transfers"
- end
+ collection do
+ delete :clear_filter
end
-
- resources :valuations, only: %i[show new create update destroy]
- resources :trades, only: %i[show new create update destroy]
end
- direct :account_entry do |entry, options|
+ resources :accountable_sparklines, only: :show, param: :accountable_type
+
+ direct :entry do |entry, options|
if entry.new_record?
- route_for "account_#{entry.entryable_name.pluralize}", options
+ route_for entry.entryable_name.pluralize, options
else
route_for entry.entryable_name, entry, options
end
end
- resources :transactions, only: :index do
- collection do
- delete :clear_filter
- end
- end
-
# Convenience routes for polymorphic paths
# Example: account_path(Account.new(accountable: Depository.new)) => /depositories/123
direct :account do |model, options|
diff --git a/db/migrate/20250413141446_table_renames.rb b/db/migrate/20250413141446_table_renames.rb
new file mode 100644
index 00000000..08f3f8e7
--- /dev/null
+++ b/db/migrate/20250413141446_table_renames.rb
@@ -0,0 +1,50 @@
+class TableRenames < ActiveRecord::Migration[7.2]
+ def change
+ # Entryables
+ rename_table :account_entries, :entries
+ rename_table :account_trades, :trades
+ rename_table :account_valuations, :valuations
+ rename_table :account_transactions, :transactions
+
+ rename_table :account_balances, :balances
+ rename_table :account_holdings, :holdings
+
+ reversible do |dir|
+ dir.up do
+ execute <<~SQL
+ UPDATE entries
+ SET entryable_type = CASE
+ WHEN entryable_type = 'Account::Transaction' THEN 'Transaction'
+ WHEN entryable_type = 'Account::Trade' THEN 'Trade'
+ WHEN entryable_type = 'Account::Valuation' THEN 'Valuation'
+ END
+ SQL
+
+ execute <<~SQL
+ UPDATE taggings
+ SET taggable_type = CASE
+ WHEN taggable_type = 'Account::Transaction' THEN 'Transaction'
+ END
+ SQL
+ end
+
+ dir.down do
+ execute <<~SQL
+ UPDATE entries
+ SET entryable_type = CASE
+ WHEN entryable_type = 'Transaction' THEN 'Account::Transaction'
+ WHEN entryable_type = 'Trade' THEN 'Account::Trade'
+ WHEN entryable_type = 'Valuation' THEN 'Account::Valuation'
+ END
+ SQL
+
+ execute <<~SQL
+ UPDATE taggings
+ SET taggable_type = CASE
+ WHEN taggable_type = 'Transaction' THEN 'Account::Transaction'
+ END
+ SQL
+ end
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index a4252e7e..a5a5b2b5 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema[7.2].define(version: 2025_04_11_140604) do
+ActiveRecord::Schema[7.2].define(version: 2025_04_13_141446) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"
@@ -19,77 +19,6 @@ ActiveRecord::Schema[7.2].define(version: 2025_04_11_140604) do
# Note that some types may not work with other database engines. Be careful if changing database.
create_enum "account_status", ["ok", "syncing", "error"]
- create_table "account_balances", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
- t.uuid "account_id", null: false
- t.date "date", null: false
- t.decimal "balance", precision: 19, scale: 4, null: false
- t.string "currency", default: "USD", null: false
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.decimal "cash_balance", precision: 19, scale: 4, default: "0.0"
- t.index ["account_id", "date", "currency"], name: "index_account_balances_on_account_id_date_currency_unique", unique: true
- t.index ["account_id"], name: "index_account_balances_on_account_id"
- end
-
- create_table "account_entries", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
- t.uuid "account_id", null: false
- t.string "entryable_type"
- t.uuid "entryable_id"
- t.decimal "amount", precision: 19, scale: 4
- t.string "currency"
- t.date "date"
- t.string "name", null: false
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.uuid "import_id"
- t.text "notes"
- t.boolean "excluded", default: false
- t.string "plaid_id"
- t.datetime "enriched_at"
- t.string "enriched_name"
- t.index ["account_id"], name: "index_account_entries_on_account_id"
- t.index ["import_id"], name: "index_account_entries_on_import_id"
- end
-
- create_table "account_holdings", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
- t.uuid "account_id", null: false
- t.uuid "security_id", null: false
- t.date "date", null: false
- t.decimal "qty", precision: 19, scale: 4, null: false
- t.decimal "price", precision: 19, scale: 4, null: false
- t.decimal "amount", precision: 19, scale: 4, null: false
- t.string "currency", null: false
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.index ["account_id", "security_id", "date", "currency"], name: "idx_on_account_id_security_id_date_currency_234024c8e3", unique: true
- t.index ["account_id"], name: "index_account_holdings_on_account_id"
- t.index ["security_id"], name: "index_account_holdings_on_security_id"
- end
-
- create_table "account_trades", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
- t.uuid "security_id", null: false
- t.decimal "qty", precision: 19, scale: 4
- t.decimal "price", precision: 19, scale: 4
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.string "currency"
- t.index ["security_id"], name: "index_account_trades_on_security_id"
- end
-
- create_table "account_transactions", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.uuid "category_id"
- t.uuid "merchant_id"
- t.index ["category_id"], name: "index_account_transactions_on_category_id"
- t.index ["merchant_id"], name: "index_account_transactions_on_merchant_id"
- end
-
- create_table "account_valuations", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- end
-
create_table "accounts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.string "subtype"
t.uuid "family_id", null: false
@@ -159,6 +88,18 @@ ActiveRecord::Schema[7.2].define(version: 2025_04_11_140604) do
t.index ["addressable_type", "addressable_id"], name: "index_addresses_on_addressable"
end
+ create_table "balances", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
+ t.uuid "account_id", null: false
+ t.date "date", null: false
+ t.decimal "balance", precision: 19, scale: 4, null: false
+ t.string "currency", default: "USD", null: false
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.decimal "cash_balance", precision: 19, scale: 4, default: "0.0"
+ t.index ["account_id", "date", "currency"], name: "index_account_balances_on_account_id_date_currency_unique", unique: true
+ t.index ["account_id"], name: "index_balances_on_account_id"
+ end
+
create_table "budget_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.uuid "budget_id", null: false
t.uuid "category_id", null: false
@@ -227,6 +168,26 @@ ActiveRecord::Schema[7.2].define(version: 2025_04_11_140604) do
t.datetime "updated_at", null: false
end
+ create_table "entries", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
+ t.uuid "account_id", null: false
+ t.string "entryable_type"
+ t.uuid "entryable_id"
+ t.decimal "amount", precision: 19, scale: 4
+ t.string "currency"
+ t.date "date"
+ t.string "name", null: false
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.uuid "import_id"
+ t.text "notes"
+ t.boolean "excluded", default: false
+ t.string "plaid_id"
+ t.datetime "enriched_at"
+ t.string "enriched_name"
+ t.index ["account_id"], name: "index_entries_on_account_id"
+ t.index ["import_id"], name: "index_entries_on_import_id"
+ end
+
create_table "exchange_rates", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.string "from_currency", null: false
t.string "to_currency", null: false
@@ -255,6 +216,21 @@ ActiveRecord::Schema[7.2].define(version: 2025_04_11_140604) do
t.boolean "data_enrichment_enabled", default: false
end
+ create_table "holdings", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
+ t.uuid "account_id", null: false
+ t.uuid "security_id", null: false
+ t.date "date", null: false
+ t.decimal "qty", precision: 19, scale: 4, null: false
+ t.decimal "price", precision: 19, scale: 4, null: false
+ t.decimal "amount", precision: 19, scale: 4, null: false
+ t.string "currency", null: false
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.index ["account_id", "security_id", "date", "currency"], name: "idx_on_account_id_security_id_date_currency_5323e39f8b", unique: true
+ t.index ["account_id"], name: "index_holdings_on_account_id"
+ t.index ["security_id"], name: "index_holdings_on_security_id"
+ end
+
create_table "impersonation_session_logs", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.uuid "impersonation_session_id", null: false
t.string "controller"
@@ -585,6 +561,25 @@ ActiveRecord::Schema[7.2].define(version: 2025_04_11_140604) do
t.index ["message_id"], name: "index_tool_calls_on_message_id"
end
+ create_table "trades", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
+ t.uuid "security_id", null: false
+ t.decimal "qty", precision: 19, scale: 4
+ t.decimal "price", precision: 19, scale: 4
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.string "currency"
+ t.index ["security_id"], name: "index_trades_on_security_id"
+ end
+
+ create_table "transactions", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.uuid "category_id"
+ t.uuid "merchant_id"
+ t.index ["category_id"], name: "index_transactions_on_category_id"
+ t.index ["merchant_id"], name: "index_transactions_on_merchant_id"
+ end
+
create_table "transfers", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.uuid "inflow_transaction_id", null: false
t.uuid "outflow_transaction_id", null: false
@@ -624,6 +619,11 @@ ActiveRecord::Schema[7.2].define(version: 2025_04_11_140604) do
t.index ["otp_secret"], name: "index_users_on_otp_secret", unique: true, where: "(otp_secret IS NOT NULL)"
end
+ create_table "valuations", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
create_table "vehicles", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
@@ -634,24 +634,21 @@ ActiveRecord::Schema[7.2].define(version: 2025_04_11_140604) do
t.string "model"
end
- add_foreign_key "account_balances", "accounts", on_delete: :cascade
- add_foreign_key "account_entries", "accounts"
- add_foreign_key "account_entries", "imports"
- add_foreign_key "account_holdings", "accounts"
- add_foreign_key "account_holdings", "securities"
- add_foreign_key "account_trades", "securities"
- add_foreign_key "account_transactions", "categories", on_delete: :nullify
- add_foreign_key "account_transactions", "merchants"
add_foreign_key "accounts", "families"
add_foreign_key "accounts", "imports"
add_foreign_key "accounts", "plaid_accounts"
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
+ add_foreign_key "balances", "accounts", on_delete: :cascade
add_foreign_key "budget_categories", "budgets"
add_foreign_key "budget_categories", "categories"
add_foreign_key "budgets", "families"
add_foreign_key "categories", "families"
add_foreign_key "chats", "users"
+ add_foreign_key "entries", "accounts"
+ add_foreign_key "entries", "imports"
+ add_foreign_key "holdings", "accounts"
+ add_foreign_key "holdings", "securities"
add_foreign_key "impersonation_session_logs", "impersonation_sessions"
add_foreign_key "impersonation_sessions", "users", column: "impersonated_id"
add_foreign_key "impersonation_sessions", "users", column: "impersonator_id"
@@ -663,8 +660,8 @@ ActiveRecord::Schema[7.2].define(version: 2025_04_11_140604) do
add_foreign_key "messages", "chats"
add_foreign_key "plaid_accounts", "plaid_items"
add_foreign_key "plaid_items", "families"
- add_foreign_key "rejected_transfers", "account_transactions", column: "inflow_transaction_id"
- add_foreign_key "rejected_transfers", "account_transactions", column: "outflow_transaction_id"
+ add_foreign_key "rejected_transfers", "transactions", column: "inflow_transaction_id"
+ add_foreign_key "rejected_transfers", "transactions", column: "outflow_transaction_id"
add_foreign_key "security_prices", "securities"
add_foreign_key "sessions", "impersonation_sessions", column: "active_impersonator_session_id"
add_foreign_key "sessions", "users"
@@ -672,8 +669,11 @@ ActiveRecord::Schema[7.2].define(version: 2025_04_11_140604) do
add_foreign_key "taggings", "tags"
add_foreign_key "tags", "families"
add_foreign_key "tool_calls", "messages"
- add_foreign_key "transfers", "account_transactions", column: "inflow_transaction_id", on_delete: :cascade
- add_foreign_key "transfers", "account_transactions", column: "outflow_transaction_id", on_delete: :cascade
+ add_foreign_key "trades", "securities"
+ add_foreign_key "transactions", "categories", on_delete: :nullify
+ add_foreign_key "transactions", "merchants"
+ add_foreign_key "transfers", "transactions", column: "inflow_transaction_id", on_delete: :cascade
+ add_foreign_key "transfers", "transactions", column: "outflow_transaction_id", on_delete: :cascade
add_foreign_key "users", "chats", column: "last_viewed_chat_id"
add_foreign_key "users", "families"
end
diff --git a/lib/tasks/securities.rake b/lib/tasks/securities.rake
index 57ec28f6..4254b8c6 100644
--- a/lib/tasks/securities.rake
+++ b/lib/tasks/securities.rake
@@ -81,8 +81,8 @@ namespace :securities do
puts " Duplicate without MIC: #{security.id}"
# Count affected records
- holdings_count = Account::Holding.where(security_id: security.id).count
- trades_count = Account::Trade.where(security_id: security.id).count
+ holdings_count = Holding.where(security_id: security.id).count
+ trades_count = Trade.where(security_id: security.id).count
prices_count = Security::Price.where(security_id: security.id).count
puts " Would update:"
@@ -94,8 +94,8 @@ namespace :securities do
begin
ActiveRecord::Base.transaction do
# Update all references to point to the canonical security
- Account::Holding.where(security_id: security.id).update_all(security_id: canonical.id)
- Account::Trade.where(security_id: security.id).update_all(security_id: canonical.id)
+ Holding.where(security_id: security.id).update_all(security_id: canonical.id)
+ Trade.where(security_id: security.id).update_all(security_id: canonical.id)
Security::Price.where(security_id: security.id).update_all(security_id: canonical.id)
# Delete the duplicate
@@ -134,8 +134,8 @@ namespace :securities do
puts " Duplicates: #{duplicates.map(&:id).join(', ')}"
# Count affected records
- holdings_count = Account::Holding.where(security_id: duplicates).count
- trades_count = Account::Trade.where(security_id: duplicates).count
+ holdings_count = Holding.where(security_id: duplicates).count
+ trades_count = Trade.where(security_id: duplicates).count
prices_count = Security::Price.where(security_id: duplicates).count
total_holdings += holdings_count
@@ -151,8 +151,8 @@ namespace :securities do
begin
ActiveRecord::Base.transaction do
# Update all references to point to the canonical security
- Account::Holding.where(security_id: duplicates).update_all(security_id: canonical.id)
- Account::Trade.where(security_id: duplicates).update_all(security_id: canonical.id)
+ Holding.where(security_id: duplicates).update_all(security_id: canonical.id)
+ Trade.where(security_id: duplicates).update_all(security_id: canonical.id)
Security::Price.where(security_id: duplicates).update_all(security_id: canonical.id)
# Delete the duplicates
diff --git a/test/controllers/account/transactions_controller_test.rb b/test/controllers/account/transactions_controller_test.rb
deleted file mode 100644
index bb1d9b83..00000000
--- a/test/controllers/account/transactions_controller_test.rb
+++ /dev/null
@@ -1,119 +0,0 @@
-require "test_helper"
-
-class Account::TransactionsControllerTest < ActionDispatch::IntegrationTest
- include EntryableResourceInterfaceTest
-
- setup do
- sign_in @user = users(:family_admin)
- @entry = account_entries(:transaction)
- end
-
- test "creates with transaction details" do
- assert_difference [ "Account::Entry.count", "Account::Transaction.count" ], 1 do
- post account_transactions_url, params: {
- account_entry: {
- account_id: @entry.account_id,
- name: "New transaction",
- date: Date.current,
- currency: "USD",
- amount: 100,
- nature: "inflow",
- entryable_attributes: {
- tag_ids: [ Tag.first.id, Tag.second.id ],
- category_id: Category.first.id,
- merchant_id: Merchant.first.id
- }
- }
- }
- end
-
- created_entry = Account::Entry.order(:created_at).last
-
- assert_redirected_to account_url(created_entry.account)
- assert_equal "Entry created", flash[:notice]
- assert_enqueued_with(job: SyncJob)
- end
-
- test "updates with transaction details" do
- assert_no_difference [ "Account::Entry.count", "Account::Transaction.count" ] do
- patch account_transaction_url(@entry), params: {
- account_entry: {
- name: "Updated name",
- date: Date.current,
- currency: "USD",
- amount: 100,
- nature: "inflow",
- entryable_type: @entry.entryable_type,
- notes: "test notes",
- excluded: false,
- entryable_attributes: {
- id: @entry.entryable_id,
- tag_ids: [ Tag.first.id, Tag.second.id ],
- category_id: Category.first.id,
- merchant_id: Merchant.first.id
- }
- }
- }
- end
-
- @entry.reload
-
- assert_equal "Updated name", @entry.name
- assert_equal Date.current, @entry.date
- assert_equal "USD", @entry.currency
- assert_equal -100, @entry.amount
- assert_equal [ Tag.first.id, Tag.second.id ], @entry.entryable.tag_ids.sort
- assert_equal Category.first.id, @entry.entryable.category_id
- assert_equal Merchant.first.id, @entry.entryable.merchant_id
- assert_equal "test notes", @entry.notes
- assert_equal false, @entry.excluded
-
- assert_equal "Entry updated", flash[:notice]
- assert_redirected_to account_url(@entry.account)
- assert_enqueued_with(job: SyncJob)
- end
-
- test "can destroy many transactions at once" do
- transactions = @user.family.entries.account_transactions
- delete_count = transactions.size
-
- assert_difference([ "Account::Transaction.count", "Account::Entry.count" ], -delete_count) do
- post bulk_delete_account_transactions_url, params: {
- bulk_delete: {
- entry_ids: transactions.pluck(:id)
- }
- }
- end
-
- assert_redirected_to transactions_url
- assert_equal "#{delete_count} transactions deleted", flash[:notice]
- end
-
- test "can update many transactions at once" do
- transactions = @user.family.entries.account_transactions
-
- assert_difference [ "Account::Entry.count", "Account::Transaction.count" ], 0 do
- post bulk_update_account_transactions_url, params: {
- bulk_update: {
- entry_ids: transactions.map(&:id),
- date: 1.day.ago.to_date,
- category_id: Category.second.id,
- merchant_id: Merchant.second.id,
- tag_ids: [ Tag.first.id, Tag.second.id ],
- notes: "Updated note"
- }
- }
- end
-
- assert_redirected_to transactions_url
- assert_equal "#{transactions.count} transactions updated", flash[:notice]
-
- transactions.reload.each do |transaction|
- assert_equal 1.day.ago.to_date, transaction.date
- assert_equal Category.second, transaction.account_transaction.category
- assert_equal Merchant.second, transaction.account_transaction.merchant
- assert_equal "Updated note", transaction.notes
- assert_equal [ Tag.first.id, Tag.second.id ], transaction.entryable.tag_ids.sort
- end
- end
-end
diff --git a/test/controllers/categories_controller_test.rb b/test/controllers/categories_controller_test.rb
index 07f45b6a..5ec08b41 100644
--- a/test/controllers/categories_controller_test.rb
+++ b/test/controllers/categories_controller_test.rb
@@ -3,7 +3,7 @@ require "test_helper"
class CategoriesControllerTest < ActionDispatch::IntegrationTest
setup do
sign_in users(:family_admin)
- @transaction = account_transactions :one
+ @transaction = transactions :one
end
test "index" do
diff --git a/test/controllers/category/deletions_controller_test.rb b/test/controllers/category/deletions_controller_test.rb
index 51900fc4..c8bd3d37 100644
--- a/test/controllers/category/deletions_controller_test.rb
+++ b/test/controllers/category/deletions_controller_test.rb
@@ -30,7 +30,7 @@ class Category::DeletionsControllerTest < ActionDispatch::IntegrationTest
assert_not_empty @category.transactions
assert_difference "Category.count", -1 do
- assert_difference "Account::Transaction.where(category: nil).count", @category.transactions.count do
+ assert_difference "Transaction.where(category: nil).count", @category.transactions.count do
post category_deletions_url(@category)
end
end
diff --git a/test/controllers/credit_cards_controller_test.rb b/test/controllers/credit_cards_controller_test.rb
index 6d475a73..6a270156 100644
--- a/test/controllers/credit_cards_controller_test.rb
+++ b/test/controllers/credit_cards_controller_test.rb
@@ -11,8 +11,8 @@ class CreditCardsControllerTest < ActionDispatch::IntegrationTest
test "creates with credit card details" do
assert_difference -> { Account.count } => 1,
-> { CreditCard.count } => 1,
- -> { Account::Valuation.count } => 2,
- -> { Account::Entry.count } => 2 do
+ -> { Valuation.count } => 2,
+ -> { Entry.count } => 2 do
post credit_cards_path, params: {
account: {
name: "New Credit Card",
diff --git a/test/controllers/account/holdings_controller_test.rb b/test/controllers/holdings_controller_test.rb
similarity index 61%
rename from test/controllers/account/holdings_controller_test.rb
rename to test/controllers/holdings_controller_test.rb
index b355c061..2e03b9f4 100644
--- a/test/controllers/account/holdings_controller_test.rb
+++ b/test/controllers/holdings_controller_test.rb
@@ -1,6 +1,6 @@
require "test_helper"
-class Account::HoldingsControllerTest < ActionDispatch::IntegrationTest
+class HoldingsControllerTest < ActionDispatch::IntegrationTest
setup do
sign_in users(:family_admin)
@account = accounts(:investment)
@@ -8,20 +8,20 @@ class Account::HoldingsControllerTest < ActionDispatch::IntegrationTest
end
test "gets holdings" do
- get account_holdings_url(account_id: @account.id)
+ get holdings_url(account_id: @account.id)
assert_response :success
end
test "gets holding" do
- get account_holding_path(@holding)
+ get holding_path(@holding)
assert_response :success
end
test "destroys holding and associated entries" do
- assert_difference -> { Account::Holding.count } => -1,
- -> { Account::Entry.count } => -1 do
- delete account_holding_path(@holding)
+ assert_difference -> { Holding.count } => -1,
+ -> { Entry.count } => -1 do
+ delete holding_path(@holding)
end
assert_redirected_to account_path(@holding.account)
diff --git a/test/controllers/loans_controller_test.rb b/test/controllers/loans_controller_test.rb
index 774c5d1a..ec590363 100644
--- a/test/controllers/loans_controller_test.rb
+++ b/test/controllers/loans_controller_test.rb
@@ -11,8 +11,8 @@ class LoansControllerTest < ActionDispatch::IntegrationTest
test "creates with loan details" do
assert_difference -> { Account.count } => 1,
-> { Loan.count } => 1,
- -> { Account::Valuation.count } => 2,
- -> { Account::Entry.count } => 2 do
+ -> { Valuation.count } => 2,
+ -> { Entry.count } => 2 do
post loans_path, params: {
account: {
name: "New Loan",
diff --git a/test/controllers/properties_controller_test.rb b/test/controllers/properties_controller_test.rb
index 9eaf63e8..43053373 100644
--- a/test/controllers/properties_controller_test.rb
+++ b/test/controllers/properties_controller_test.rb
@@ -11,8 +11,8 @@ class PropertiesControllerTest < ActionDispatch::IntegrationTest
test "creates with property details" do
assert_difference -> { Account.count } => 1,
-> { Property.count } => 1,
- -> { Account::Valuation.count } => 2,
- -> { Account::Entry.count } => 2 do
+ -> { Valuation.count } => 2,
+ -> { Entry.count } => 2 do
post properties_path, params: {
account: {
name: "Property",
diff --git a/test/controllers/settings/hostings_controller_test.rb b/test/controllers/settings/hostings_controller_test.rb
index 32bcaab2..4e10e901 100644
--- a/test/controllers/settings/hostings_controller_test.rb
+++ b/test/controllers/settings/hostings_controller_test.rb
@@ -64,8 +64,8 @@ class Settings::HostingsControllerTest < ActionDispatch::IntegrationTest
assert_not ExchangeRate.exists?(exchange_rate.id)
assert_not Security::Price.exists?(security_price.id)
- assert_not Account::Holding.exists?(holding.id)
- assert_not Account::Balance.exists?(account_balance.id)
+ assert_not Holding.exists?(holding.id)
+ assert_not Balance.exists?(account_balance.id)
end
test "can clear data only when admin" do
diff --git a/test/controllers/account/trades_controller_test.rb b/test/controllers/trades_controller_test.rb
similarity index 63%
rename from test/controllers/account/trades_controller_test.rb
rename to test/controllers/trades_controller_test.rb
index 66ab86ed..e1ca4b7d 100644
--- a/test/controllers/account/trades_controller_test.rb
+++ b/test/controllers/trades_controller_test.rb
@@ -1,17 +1,17 @@
require "test_helper"
-class Account::TradesControllerTest < ActionDispatch::IntegrationTest
+class TradesControllerTest < ActionDispatch::IntegrationTest
include EntryableResourceInterfaceTest
setup do
sign_in @user = users(:family_admin)
- @entry = account_entries(:trade)
+ @entry = entries(:trade)
end
test "updates trade entry" do
- assert_no_difference [ "Account::Entry.count", "Account::Trade.count" ] do
- patch account_trade_url(@entry), params: {
- account_entry: {
+ assert_no_difference [ "Entry.count", "Trade.count" ] do
+ patch trade_url(@entry), params: {
+ entry: {
currency: "USD",
entryable_attributes: {
id: @entry.entryable_id,
@@ -26,8 +26,8 @@ class Account::TradesControllerTest < ActionDispatch::IntegrationTest
assert_enqueued_with job: SyncJob
- assert_equal 20, @entry.account_trade.qty
- assert_equal 20, @entry.account_trade.price
+ assert_equal 20, @entry.trade.qty
+ assert_equal 20, @entry.trade.price
assert_equal "USD", @entry.currency
assert_redirected_to account_url(@entry.account)
@@ -36,11 +36,11 @@ class Account::TradesControllerTest < ActionDispatch::IntegrationTest
test "creates deposit entry" do
from_account = accounts(:depository) # Account the deposit is coming from
- assert_difference -> { Account::Entry.count } => 2,
- -> { Account::Transaction.count } => 2,
+ assert_difference -> { Entry.count } => 2,
+ -> { Transaction.count } => 2,
-> { Transfer.count } => 1 do
- post account_trades_url, params: {
- account_entry: {
+ post trades_url, params: {
+ entry: {
account_id: @entry.account_id,
type: "deposit",
date: Date.current,
@@ -57,11 +57,11 @@ class Account::TradesControllerTest < ActionDispatch::IntegrationTest
test "creates withdrawal entry" do
to_account = accounts(:depository) # Account the withdrawal is going to
- assert_difference -> { Account::Entry.count } => 2,
- -> { Account::Transaction.count } => 2,
+ assert_difference -> { Entry.count } => 2,
+ -> { Transaction.count } => 2,
-> { Transfer.count } => 1 do
- post account_trades_url, params: {
- account_entry: {
+ post trades_url, params: {
+ entry: {
account_id: @entry.account_id,
type: "withdrawal",
date: Date.current,
@@ -76,11 +76,11 @@ class Account::TradesControllerTest < ActionDispatch::IntegrationTest
end
test "deposit and withdrawal has optional transfer account" do
- assert_difference -> { Account::Entry.count } => 1,
- -> { Account::Transaction.count } => 1,
+ assert_difference -> { Entry.count } => 1,
+ -> { Transaction.count } => 1,
-> { Transfer.count } => 0 do
- post account_trades_url, params: {
- account_entry: {
+ post trades_url, params: {
+ entry: {
account_id: @entry.account_id,
type: "withdrawal",
date: Date.current,
@@ -90,16 +90,16 @@ class Account::TradesControllerTest < ActionDispatch::IntegrationTest
}
end
- created_entry = Account::Entry.order(created_at: :desc).first
+ created_entry = Entry.order(created_at: :desc).first
assert created_entry.amount.positive?
assert_redirected_to @entry.account
end
test "creates interest entry" do
- assert_difference [ "Account::Entry.count", "Account::Transaction.count" ], 1 do
- post account_trades_url, params: {
- account_entry: {
+ assert_difference [ "Entry.count", "Transaction.count" ], 1 do
+ post trades_url, params: {
+ entry: {
account_id: @entry.account_id,
type: "interest",
date: Date.current,
@@ -109,16 +109,16 @@ class Account::TradesControllerTest < ActionDispatch::IntegrationTest
}
end
- created_entry = Account::Entry.order(created_at: :desc).first
+ created_entry = Entry.order(created_at: :desc).first
assert created_entry.amount.negative?
assert_redirected_to @entry.account
end
test "creates trade buy entry" do
- assert_difference [ "Account::Entry.count", "Account::Trade.count", "Security.count" ], 1 do
- post account_trades_url, params: {
- account_entry: {
+ assert_difference [ "Entry.count", "Trade.count", "Security.count" ], 1 do
+ post trades_url, params: {
+ entry: {
account_id: @entry.account_id,
type: "buy",
date: Date.current,
@@ -130,19 +130,19 @@ class Account::TradesControllerTest < ActionDispatch::IntegrationTest
}
end
- created_entry = Account::Entry.order(created_at: :desc).first
+ created_entry = Entry.order(created_at: :desc).first
assert created_entry.amount.positive?
- assert created_entry.account_trade.qty.positive?
+ assert created_entry.trade.qty.positive?
assert_equal "Entry created", flash[:notice]
assert_enqueued_with job: SyncJob
assert_redirected_to account_url(created_entry.account)
end
test "creates trade sell entry" do
- assert_difference [ "Account::Entry.count", "Account::Trade.count" ], 1 do
- post account_trades_url, params: {
- account_entry: {
+ assert_difference [ "Entry.count", "Trade.count" ], 1 do
+ post trades_url, params: {
+ entry: {
account_id: @entry.account_id,
type: "sell",
ticker: "AAPL (NYSE)",
@@ -154,10 +154,10 @@ class Account::TradesControllerTest < ActionDispatch::IntegrationTest
}
end
- created_entry = Account::Entry.order(created_at: :desc).first
+ created_entry = Entry.order(created_at: :desc).first
assert created_entry.amount.negative?
- assert created_entry.account_trade.qty.negative?
+ assert created_entry.trade.qty.negative?
assert_equal "Entry created", flash[:notice]
assert_enqueued_with job: SyncJob
assert_redirected_to account_url(created_entry.account)
diff --git a/test/controllers/transactions/bulk_deletions_controller_test.rb b/test/controllers/transactions/bulk_deletions_controller_test.rb
new file mode 100644
index 00000000..aa981d6c
--- /dev/null
+++ b/test/controllers/transactions/bulk_deletions_controller_test.rb
@@ -0,0 +1,24 @@
+require "test_helper"
+
+class Transactions::BulkDeletionsControllerTest < ActionDispatch::IntegrationTest
+ setup do
+ sign_in @user = users(:family_admin)
+ @entry = entries(:transaction)
+ end
+
+ test "bulk delete" do
+ transactions = @user.family.entries.transactions
+ delete_count = transactions.size
+
+ assert_difference([ "Transaction.count", "Entry.count" ], -delete_count) do
+ post transactions_bulk_deletion_url, params: {
+ bulk_delete: {
+ entry_ids: transactions.pluck(:id)
+ }
+ }
+ end
+
+ assert_redirected_to transactions_url
+ assert_equal "#{delete_count} transactions deleted", flash[:notice]
+ end
+end
diff --git a/test/controllers/transactions/bulk_updates_controller_test.rb b/test/controllers/transactions/bulk_updates_controller_test.rb
new file mode 100644
index 00000000..d7f360fa
--- /dev/null
+++ b/test/controllers/transactions/bulk_updates_controller_test.rb
@@ -0,0 +1,35 @@
+require "test_helper"
+
+class Transactions::BulkUpdatesControllerTest < ActionDispatch::IntegrationTest
+ setup do
+ sign_in @user = users(:family_admin)
+ end
+
+ test "bulk update" do
+ transactions = @user.family.entries.transactions
+
+ assert_difference [ "Entry.count", "Transaction.count" ], 0 do
+ post transactions_bulk_update_url, params: {
+ bulk_update: {
+ entry_ids: transactions.map(&:id),
+ date: 1.day.ago.to_date,
+ category_id: Category.second.id,
+ merchant_id: Merchant.second.id,
+ tag_ids: [ Tag.first.id, Tag.second.id ],
+ notes: "Updated note"
+ }
+ }
+ end
+
+ assert_redirected_to transactions_url
+ assert_equal "#{transactions.count} transactions updated", flash[:notice]
+
+ transactions.reload.each do |transaction|
+ assert_equal 1.day.ago.to_date, transaction.date
+ assert_equal Category.second, transaction.transaction.category
+ assert_equal Merchant.second, transaction.transaction.merchant
+ assert_equal "Updated note", transaction.notes
+ assert_equal [ Tag.first.id, Tag.second.id ], transaction.entryable.tag_ids.sort
+ end
+ end
+end
diff --git a/test/controllers/transactions_controller_test.rb b/test/controllers/transactions_controller_test.rb
index 73492e6e..9eb427d5 100644
--- a/test/controllers/transactions_controller_test.rb
+++ b/test/controllers/transactions_controller_test.rb
@@ -1,11 +1,77 @@
require "test_helper"
class TransactionsControllerTest < ActionDispatch::IntegrationTest
- include Account::EntriesTestHelper
+ include EntryableResourceInterfaceTest, EntriesTestHelper
setup do
sign_in @user = users(:family_admin)
- @transaction = account_entries(:transaction)
+ @entry = entries(:transaction)
+ end
+
+ test "creates with transaction details" do
+ assert_difference [ "Entry.count", "Transaction.count" ], 1 do
+ post transactions_url, params: {
+ entry: {
+ account_id: @entry.account_id,
+ name: "New transaction",
+ date: Date.current,
+ currency: "USD",
+ amount: 100,
+ nature: "inflow",
+ entryable_type: @entry.entryable_type,
+ entryable_attributes: {
+ tag_ids: [ Tag.first.id, Tag.second.id ],
+ category_id: Category.first.id,
+ merchant_id: Merchant.first.id
+ }
+ }
+ }
+ end
+
+ created_entry = Entry.order(:created_at).last
+
+ assert_redirected_to account_url(created_entry.account)
+ assert_equal "Transaction created", flash[:notice]
+ assert_enqueued_with(job: SyncJob)
+ end
+
+ test "updates with transaction details" do
+ assert_no_difference [ "Entry.count", "Transaction.count" ] do
+ patch transaction_url(@entry), params: {
+ entry: {
+ name: "Updated name",
+ date: Date.current,
+ currency: "USD",
+ amount: 100,
+ nature: "inflow",
+ entryable_type: @entry.entryable_type,
+ notes: "test notes",
+ excluded: false,
+ entryable_attributes: {
+ id: @entry.entryable_id,
+ tag_ids: [ Tag.first.id, Tag.second.id ],
+ category_id: Category.first.id,
+ merchant_id: Merchant.first.id
+ }
+ }
+ }
+ end
+
+ @entry.reload
+
+ assert_equal "Updated name", @entry.name
+ assert_equal Date.current, @entry.date
+ assert_equal "USD", @entry.currency
+ assert_equal -100, @entry.amount
+ assert_equal [ Tag.first.id, Tag.second.id ], @entry.entryable.tag_ids.sort
+ assert_equal Category.first.id, @entry.entryable.category_id
+ assert_equal Merchant.first.id, @entry.entryable.merchant_id
+ assert_equal "test notes", @entry.notes
+ assert_equal false, @entry.excluded
+
+ assert_equal "Transaction updated", flash[:notice]
+ assert_redirected_to account_url(@entry.account)
+ assert_enqueued_with(job: SyncJob)
end
test "transaction count represents filtered total" do
@@ -19,7 +85,7 @@ class TransactionsControllerTest < ActionDispatch::IntegrationTest
get transactions_url(per_page: 10)
- assert_dom "#total-transactions", count: 1, text: family.entries.account_transactions.size.to_s
+ assert_dom "#total-transactions", count: 1, text: family.entries.transactions.size.to_s
searchable_transaction = create_transaction(account: account, name: "Unique test name")
@@ -39,7 +105,7 @@ class TransactionsControllerTest < ActionDispatch::IntegrationTest
create_transaction(account: account)
end
- sorted_transactions = family.entries.account_transactions.reverse_chronological.to_a
+ sorted_transactions = family.entries.transactions.reverse_chronological.to_a
assert_equal 11, sorted_transactions.count
diff --git a/test/controllers/account/transfer_matches_controller_test.rb b/test/controllers/transfer_matches_controller_test.rb
similarity index 71%
rename from test/controllers/account/transfer_matches_controller_test.rb
rename to test/controllers/transfer_matches_controller_test.rb
index 0e13883e..aff23f4f 100644
--- a/test/controllers/account/transfer_matches_controller_test.rb
+++ b/test/controllers/transfer_matches_controller_test.rb
@@ -1,7 +1,7 @@
require "test_helper"
-class Account::TransferMatchesControllerTest < ActionDispatch::IntegrationTest
- include Account::EntriesTestHelper
+class TransferMatchesControllerTest < ActionDispatch::IntegrationTest
+ include EntriesTestHelper
setup do
sign_in @user = users(:family_admin)
@@ -12,7 +12,7 @@ class Account::TransferMatchesControllerTest < ActionDispatch::IntegrationTest
outflow_transaction = create_transaction(amount: -100, account: accounts(:investment))
assert_difference "Transfer.count", 1 do
- post account_transaction_transfer_match_path(inflow_transaction), params: {
+ post transaction_transfer_match_path(inflow_transaction), params: {
transfer_match: {
method: "existing",
matched_entry_id: outflow_transaction.id
@@ -27,8 +27,8 @@ class Account::TransferMatchesControllerTest < ActionDispatch::IntegrationTest
test "creates transfer for target account" do
inflow_transaction = create_transaction(amount: 100, account: accounts(:depository))
- assert_difference [ "Transfer.count", "Account::Entry.count", "Account::Transaction.count" ], 1 do
- post account_transaction_transfer_match_path(inflow_transaction), params: {
+ assert_difference [ "Transfer.count", "Entry.count", "Transaction.count" ], 1 do
+ post transaction_transfer_match_path(inflow_transaction), params: {
transfer_match: {
method: "new",
target_account_id: accounts(:investment).id
diff --git a/test/controllers/account/valuations_controller_test.rb b/test/controllers/valuations_controller_test.rb
similarity index 59%
rename from test/controllers/account/valuations_controller_test.rb
rename to test/controllers/valuations_controller_test.rb
index 432c2cd4..34b2515f 100644
--- a/test/controllers/account/valuations_controller_test.rb
+++ b/test/controllers/valuations_controller_test.rb
@@ -1,17 +1,18 @@
require "test_helper"
-class Account::ValuationsControllerTest < ActionDispatch::IntegrationTest
+class ValuationsControllerTest < ActionDispatch::IntegrationTest
include EntryableResourceInterfaceTest
setup do
sign_in @user = users(:family_admin)
- @entry = account_entries(:valuation)
+ @entry = entries(:valuation)
end
test "error when valuation already exists for date" do
- assert_no_difference [ "Account::Entry.count", "Account::Valuation.count" ] do
- post account_valuations_url(@entry.account), params: {
- account_entry: {
+ assert_no_difference [ "Entry.count", "Valuation.count" ] do
+ post valuations_url(@entry.account), params: {
+ entry: {
+ account_id: @entry.account_id,
amount: 19800,
date: @entry.date,
currency: "USD"
@@ -23,9 +24,9 @@ class Account::ValuationsControllerTest < ActionDispatch::IntegrationTest
end
test "creates entry with basic attributes" do
- assert_difference [ "Account::Entry.count", "Account::Valuation.count" ], 1 do
- post account_valuations_url, params: {
- account_entry: {
+ assert_difference [ "Entry.count", "Valuation.count" ], 1 do
+ post valuations_url, params: {
+ entry: {
name: "New entry",
amount: 10000,
currency: "USD",
@@ -35,7 +36,7 @@ class Account::ValuationsControllerTest < ActionDispatch::IntegrationTest
}
end
- created_entry = Account::Entry.order(created_at: :desc).first
+ created_entry = Entry.order(created_at: :desc).first
assert_enqueued_with job: SyncJob
@@ -43,9 +44,9 @@ class Account::ValuationsControllerTest < ActionDispatch::IntegrationTest
end
test "updates entry with basic attributes" do
- assert_no_difference [ "Account::Entry.count", "Account::Valuation.count" ] do
- patch account_valuation_url(@entry), params: {
- account_entry: {
+ assert_no_difference [ "Entry.count", "Valuation.count" ] do
+ patch valuation_url(@entry), params: {
+ entry: {
name: "Updated entry",
amount: 20000,
currency: "USD",
diff --git a/test/controllers/vehicles_controller_test.rb b/test/controllers/vehicles_controller_test.rb
index 3ebd23e3..bb7df9c6 100644
--- a/test/controllers/vehicles_controller_test.rb
+++ b/test/controllers/vehicles_controller_test.rb
@@ -11,8 +11,8 @@ class VehiclesControllerTest < ActionDispatch::IntegrationTest
test "creates with vehicle details" do
assert_difference -> { Account.count } => 1,
-> { Vehicle.count } => 1,
- -> { Account::Valuation.count } => 2,
- -> { Account::Entry.count } => 2 do
+ -> { Valuation.count } => 2,
+ -> { Entry.count } => 2 do
post vehicles_path, params: {
account: {
name: "Vehicle",
diff --git a/test/fixtures/account/balances.yml b/test/fixtures/balances.yml
similarity index 100%
rename from test/fixtures/account/balances.yml
rename to test/fixtures/balances.yml
diff --git a/test/fixtures/account/entries.yml b/test/fixtures/entries.yml
similarity index 80%
rename from test/fixtures/account/entries.yml
rename to test/fixtures/entries.yml
index ccaf29bf..6eac29d2 100644
--- a/test/fixtures/account/entries.yml
+++ b/test/fixtures/entries.yml
@@ -4,7 +4,7 @@ valuation:
amount: 4995
currency: USD
account: depository
- entryable_type: Account::Valuation
+ entryable_type: Valuation
entryable: one
trade:
@@ -13,7 +13,7 @@ trade:
amount: 2140 # 10 shares * $214 per share
currency: USD
account: investment
- entryable_type: Account::Trade
+ entryable_type: Trade
entryable: one
transaction:
@@ -22,7 +22,7 @@ transaction:
amount: 10
currency: USD
account: depository
- entryable_type: Account::Transaction
+ entryable_type: Transaction
entryable: one
transfer_out:
@@ -31,7 +31,7 @@ transfer_out:
amount: 100
currency: USD
account: depository
- entryable_type: Account::Transaction
+ entryable_type: Transaction
entryable: transfer_out
transfer_in:
@@ -40,5 +40,5 @@ transfer_in:
amount: -100
currency: USD
account: credit_card
- entryable_type: Account::Transaction
+ entryable_type: Transaction
entryable: transfer_in
diff --git a/test/fixtures/account/holdings.yml b/test/fixtures/holdings.yml
similarity index 100%
rename from test/fixtures/account/holdings.yml
rename to test/fixtures/holdings.yml
diff --git a/test/fixtures/taggings.yml b/test/fixtures/taggings.yml
index 5039ba27..12432311 100644
--- a/test/fixtures/taggings.yml
+++ b/test/fixtures/taggings.yml
@@ -1,10 +1,10 @@
one:
tag: one
taggable: one
- taggable_type: Account::Transaction
+ taggable_type: Transaction
two:
tag: two
taggable: one
- taggable_type: Account::Transaction
+ taggable_type: Transaction
diff --git a/test/fixtures/account/trades.yml b/test/fixtures/trades.yml
similarity index 100%
rename from test/fixtures/account/trades.yml
rename to test/fixtures/trades.yml
diff --git a/test/fixtures/account/transactions.yml b/test/fixtures/transactions.yml
similarity index 100%
rename from test/fixtures/account/transactions.yml
rename to test/fixtures/transactions.yml
diff --git a/test/fixtures/account/valuations.yml b/test/fixtures/valuations.yml
similarity index 100%
rename from test/fixtures/account/valuations.yml
rename to test/fixtures/valuations.yml
diff --git a/test/interfaces/accountable_resource_interface_test.rb b/test/interfaces/accountable_resource_interface_test.rb
index 1a99d63e..551995de 100644
--- a/test/interfaces/accountable_resource_interface_test.rb
+++ b/test/interfaces/accountable_resource_interface_test.rb
@@ -60,7 +60,7 @@ module AccountableResourceInterfaceTest
end
test "updates account balance by creating new valuation if balance has changed" do
- assert_difference [ "Account::Entry.count", "Account::Valuation.count" ], 1 do
+ assert_difference [ "Entry.count", "Valuation.count" ], 1 do
patch account_url(@account), params: {
account: {
balance: 12000
@@ -74,9 +74,9 @@ module AccountableResourceInterfaceTest
end
test "updates account balance by editing existing valuation for today" do
- @account.entries.create! date: Date.current, amount: 6000, currency: "USD", name: "Balance update", entryable: Account::Valuation.new
+ @account.entries.create! date: Date.current, amount: 6000, currency: "USD", name: "Balance update", entryable: Valuation.new
- assert_no_difference [ "Account::Entry.count", "Account::Valuation.count" ] do
+ assert_no_difference [ "Entry.count", "Valuation.count" ] do
patch account_url(@account), params: {
account: {
balance: 12000
diff --git a/test/interfaces/entryable_resource_interface_test.rb b/test/interfaces/entryable_resource_interface_test.rb
index 28ba3e75..710912ac 100644
--- a/test/interfaces/entryable_resource_interface_test.rb
+++ b/test/interfaces/entryable_resource_interface_test.rb
@@ -9,13 +9,13 @@ module EntryableResourceInterfaceTest
end
test "shows editing drawer" do
- get account_entry_url(@entry)
+ get entry_url(@entry)
assert_response :success
end
test "destroys entry" do
- assert_difference "Account::Entry.count", -1 do
- delete account_entry_url(@entry)
+ assert_difference "Entry.count", -1 do
+ delete entry_url(@entry)
end
assert_enqueued_with job: SyncJob
diff --git a/test/models/account/balance/syncer_test.rb b/test/models/account/balance/syncer_test.rb
deleted file mode 100644
index 72dfc568..00000000
--- a/test/models/account/balance/syncer_test.rb
+++ /dev/null
@@ -1,51 +0,0 @@
-require "test_helper"
-
-class Account::Balance::SyncerTest < ActiveSupport::TestCase
- include Account::EntriesTestHelper
-
- setup do
- @account = families(:empty).accounts.create!(
- name: "Test",
- balance: 20000,
- cash_balance: 20000,
- currency: "USD",
- accountable: Investment.new
- )
- end
-
- test "syncs balances" do
- Account::Holding::Syncer.any_instance.expects(:sync_holdings).returns([]).once
-
- @account.expects(:start_date).returns(2.days.ago.to_date)
-
- Account::Balance::ForwardCalculator.any_instance.expects(:calculate).returns(
- [
- Account::Balance.new(date: 1.day.ago.to_date, balance: 1000, cash_balance: 1000, currency: "USD"),
- Account::Balance.new(date: Date.current, balance: 1000, cash_balance: 1000, currency: "USD")
- ]
- )
-
- assert_difference "@account.balances.count", 2 do
- Account::Balance::Syncer.new(@account, strategy: :forward).sync_balances
- end
- end
-
- test "purges stale balances and holdings" do
- # Balance before start date is stale
- @account.expects(:start_date).returns(2.days.ago.to_date).twice
- stale_balance = Account::Balance.new(date: 3.days.ago.to_date, balance: 10000, cash_balance: 10000, currency: "USD")
-
- Account::Balance::ForwardCalculator.any_instance.expects(:calculate).returns(
- [
- stale_balance,
- Account::Balance.new(date: 2.days.ago.to_date, balance: 10000, cash_balance: 10000, currency: "USD"),
- Account::Balance.new(date: 1.day.ago.to_date, balance: 1000, cash_balance: 1000, currency: "USD"),
- Account::Balance.new(date: Date.current, balance: 1000, cash_balance: 1000, currency: "USD")
- ]
- )
-
- assert_difference "@account.balances.count", 3 do
- Account::Balance::Syncer.new(@account, strategy: :forward).sync_balances
- end
- end
-end
diff --git a/test/models/account/convertible_test.rb b/test/models/account/convertible_test.rb
index 76cc5c85..8d77cae5 100644
--- a/test/models/account/convertible_test.rb
+++ b/test/models/account/convertible_test.rb
@@ -2,7 +2,7 @@ require "test_helper"
require "ostruct"
class Account::ConvertibleTest < ActiveSupport::TestCase
- include Account::EntriesTestHelper, ProviderTestHelper
+ include EntriesTestHelper, ProviderTestHelper
setup do
@family = families(:empty)
diff --git a/test/models/account/entry_test.rb b/test/models/account/entry_test.rb
index f798fb95..5a07ad6e 100644
--- a/test/models/account/entry_test.rb
+++ b/test/models/account/entry_test.rb
@@ -1,10 +1,10 @@
require "test_helper"
-class Account::EntryTest < ActiveSupport::TestCase
- include Account::EntriesTestHelper
+class EntryTest < ActiveSupport::TestCase
+ include EntriesTestHelper
setup do
- @entry = account_entries :transaction
+ @entry = entries :transaction
end
test "entry cannot be older than 10 years ago" do
@@ -14,10 +14,10 @@ class Account::EntryTest < ActiveSupport::TestCase
end
test "valuations cannot have more than one entry per day" do
- existing_valuation = account_entries :valuation
+ existing_valuation = entries :valuation
- new_valuation = Account::Entry.new \
- entryable: Account::Valuation.new,
+ new_valuation = Entry.new \
+ entryable: Valuation.new,
account: existing_valuation.account,
date: existing_valuation.date, # invalid
currency: existing_valuation.currency,
@@ -76,7 +76,7 @@ class Account::EntryTest < ActiveSupport::TestCase
accounts(:credit_card).update!(is_active: false)
# Test the scope
- active_entries = Account::Entry.active
+ active_entries = Entry.active
# Should include entry from active account
assert_includes active_entries, active_transaction
diff --git a/test/models/account/transaction_test.rb b/test/models/account/transaction_test.rb
index 11279945..21dcea21 100644
--- a/test/models/account/transaction_test.rb
+++ b/test/models/account/transaction_test.rb
@@ -1,5 +1,5 @@
require "test_helper"
-class Account::TransactionTest < ActiveSupport::TestCase
- include Account::EntriesTestHelper
+class TransactionTest < ActiveSupport::TestCase
+ include EntriesTestHelper
end
diff --git a/test/models/account_test.rb b/test/models/account_test.rb
index bbf2d192..4d10da21 100644
--- a/test/models/account_test.rb
+++ b/test/models/account_test.rb
@@ -1,7 +1,7 @@
require "test_helper"
class AccountTest < ActiveSupport::TestCase
- include SyncableInterfaceTest, Account::EntriesTestHelper
+ include SyncableInterfaceTest, EntriesTestHelper
setup do
@account = @syncable = accounts(:depository)
diff --git a/test/models/account/balance/forward_calculator_test.rb b/test/models/balance/forward_calculator_test.rb
similarity index 79%
rename from test/models/account/balance/forward_calculator_test.rb
rename to test/models/balance/forward_calculator_test.rb
index cb96572f..7cc84738 100644
--- a/test/models/account/balance/forward_calculator_test.rb
+++ b/test/models/balance/forward_calculator_test.rb
@@ -1,7 +1,7 @@
require "test_helper"
-class Account::Balance::ForwardCalculatorTest < ActiveSupport::TestCase
- include Account::EntriesTestHelper
+class Balance::ForwardCalculatorTest < ActiveSupport::TestCase
+ include EntriesTestHelper
setup do
@account = families(:empty).accounts.create!(
@@ -18,7 +18,7 @@ class Account::Balance::ForwardCalculatorTest < ActiveSupport::TestCase
assert_equal 0, @account.balances.count
expected = [ 0, 0 ]
- calculated = Account::Balance::ForwardCalculator.new(@account).calculate
+ calculated = Balance::ForwardCalculator.new(@account).calculate
assert_equal expected, calculated.map(&:balance)
end
@@ -28,7 +28,7 @@ class Account::Balance::ForwardCalculatorTest < ActiveSupport::TestCase
create_valuation(account: @account, date: 2.days.ago.to_date, amount: 19000)
expected = [ 0, 17000, 17000, 19000, 19000, 19000 ]
- calculated = Account::Balance::ForwardCalculator.new(@account).calculate.sort_by(&:date).map(&:balance)
+ calculated = Balance::ForwardCalculator.new(@account).calculate.sort_by(&:date).map(&:balance)
assert_equal expected, calculated
end
@@ -38,7 +38,7 @@ class Account::Balance::ForwardCalculatorTest < ActiveSupport::TestCase
create_transaction(account: @account, date: 2.days.ago.to_date, amount: 100) # expense
expected = [ 0, 500, 500, 400, 400, 400 ]
- calculated = Account::Balance::ForwardCalculator.new(@account).calculate.sort_by(&:date).map(&:balance)
+ calculated = Balance::ForwardCalculator.new(@account).calculate.sort_by(&:date).map(&:balance)
assert_equal expected, calculated
end
@@ -52,7 +52,7 @@ class Account::Balance::ForwardCalculatorTest < ActiveSupport::TestCase
create_transaction(account: @account, date: 1.day.ago.to_date, amount: 100)
expected = [ 0, 5000, 5000, 17000, 17000, 17500, 17000, 17000, 16900, 16900 ]
- calculated = Account::Balance::ForwardCalculator.new(@account).calculate.sort_by(&:date).map(&:balance)
+ calculated = Balance::ForwardCalculator.new(@account).calculate.sort_by(&:date).map(&:balance)
assert_equal expected, calculated
end
@@ -67,7 +67,7 @@ class Account::Balance::ForwardCalculatorTest < ActiveSupport::TestCase
create_transaction(account: @account, date: 1.day.ago.to_date, amount: -500, currency: "EUR") # €500 * 1.2 = $600
expected = [ 0, 100, 400, 1000, 1000 ]
- calculated = Account::Balance::ForwardCalculator.new(@account).calculate.sort_by(&:date).map(&:balance)
+ calculated = Balance::ForwardCalculator.new(@account).calculate.sort_by(&:date).map(&:balance)
assert_equal expected, calculated
end
diff --git a/test/models/account/balance/reverse_calculator_test.rb b/test/models/balance/reverse_calculator_test.rb
similarity index 77%
rename from test/models/account/balance/reverse_calculator_test.rb
rename to test/models/balance/reverse_calculator_test.rb
index e81c9eb5..358d7313 100644
--- a/test/models/account/balance/reverse_calculator_test.rb
+++ b/test/models/balance/reverse_calculator_test.rb
@@ -1,7 +1,7 @@
require "test_helper"
-class Account::Balance::ReverseCalculatorTest < ActiveSupport::TestCase
- include Account::EntriesTestHelper
+class Balance::ReverseCalculatorTest < ActiveSupport::TestCase
+ include EntriesTestHelper
setup do
@account = families(:empty).accounts.create!(
@@ -18,7 +18,7 @@ class Account::Balance::ReverseCalculatorTest < ActiveSupport::TestCase
assert_equal 0, @account.balances.count
expected = [ @account.balance, @account.balance ]
- calculated = Account::Balance::ReverseCalculator.new(@account).calculate
+ calculated = Balance::ReverseCalculator.new(@account).calculate
assert_equal expected, calculated.map(&:balance)
end
@@ -28,7 +28,7 @@ class Account::Balance::ReverseCalculatorTest < ActiveSupport::TestCase
create_valuation(account: @account, date: 2.days.ago.to_date, amount: 19000)
expected = [ 17000, 17000, 19000, 19000, 20000, 20000 ]
- calculated = Account::Balance::ReverseCalculator.new(@account).calculate.sort_by(&:date).map(&:balance)
+ calculated = Balance::ReverseCalculator.new(@account).calculate.sort_by(&:date).map(&:balance)
assert_equal expected, calculated
end
@@ -38,7 +38,7 @@ class Account::Balance::ReverseCalculatorTest < ActiveSupport::TestCase
create_transaction(account: @account, date: 2.days.ago.to_date, amount: 100) # expense
expected = [ 19600, 20100, 20100, 20000, 20000, 20000 ]
- calculated = Account::Balance::ReverseCalculator.new(@account).calculate.sort_by(&:date).map(&:balance)
+ calculated = Balance::ReverseCalculator.new(@account).calculate.sort_by(&:date).map(&:balance)
assert_equal expected, calculated
end
@@ -52,7 +52,7 @@ class Account::Balance::ReverseCalculatorTest < ActiveSupport::TestCase
create_transaction(account: @account, date: 1.day.ago.to_date, amount: 100)
expected = [ 12000, 17000, 17000, 17000, 16500, 17000, 17000, 20100, 20000, 20000 ]
- calculated = Account::Balance::ReverseCalculator.new(@account).calculate.sort_by(&:date).map(&:balance)
+ calculated = Balance::ReverseCalculator.new(@account).calculate.sort_by(&:date).map(&:balance)
assert_equal expected, calculated
end
diff --git a/test/models/balance/syncer_test.rb b/test/models/balance/syncer_test.rb
new file mode 100644
index 00000000..648f6b3a
--- /dev/null
+++ b/test/models/balance/syncer_test.rb
@@ -0,0 +1,51 @@
+require "test_helper"
+
+class Balance::SyncerTest < ActiveSupport::TestCase
+ include EntriesTestHelper
+
+ setup do
+ @account = families(:empty).accounts.create!(
+ name: "Test",
+ balance: 20000,
+ cash_balance: 20000,
+ currency: "USD",
+ accountable: Investment.new
+ )
+ end
+
+ test "syncs balances" do
+ Holding::Syncer.any_instance.expects(:sync_holdings).returns([]).once
+
+ @account.expects(:start_date).returns(2.days.ago.to_date)
+
+ Balance::ForwardCalculator.any_instance.expects(:calculate).returns(
+ [
+ Balance.new(date: 1.day.ago.to_date, balance: 1000, cash_balance: 1000, currency: "USD"),
+ Balance.new(date: Date.current, balance: 1000, cash_balance: 1000, currency: "USD")
+ ]
+ )
+
+ assert_difference "@account.balances.count", 2 do
+ Balance::Syncer.new(@account, strategy: :forward).sync_balances
+ end
+ end
+
+ test "purges stale balances and holdings" do
+ # Balance before start date is stale
+ @account.expects(:start_date).returns(2.days.ago.to_date).twice
+ stale_balance = Balance.new(date: 3.days.ago.to_date, balance: 10000, cash_balance: 10000, currency: "USD")
+
+ Balance::ForwardCalculator.any_instance.expects(:calculate).returns(
+ [
+ stale_balance,
+ Balance.new(date: 2.days.ago.to_date, balance: 10000, cash_balance: 10000, currency: "USD"),
+ Balance.new(date: 1.day.ago.to_date, balance: 1000, cash_balance: 1000, currency: "USD"),
+ Balance.new(date: Date.current, balance: 1000, cash_balance: 1000, currency: "USD")
+ ]
+ )
+
+ assert_difference "@account.balances.count", 3 do
+ Balance::Syncer.new(@account, strategy: :forward).sync_balances
+ end
+ end
+end
diff --git a/test/models/family/auto_transfer_matchable_test.rb b/test/models/family/auto_transfer_matchable_test.rb
index 9a1c7ca8..77bb80f0 100644
--- a/test/models/family/auto_transfer_matchable_test.rb
+++ b/test/models/family/auto_transfer_matchable_test.rb
@@ -1,7 +1,7 @@
require "test_helper"
class Family::AutoTransferMatchableTest < ActiveSupport::TestCase
- include Account::EntriesTestHelper
+ include EntriesTestHelper
setup do
@family = families(:dylan_family)
diff --git a/test/models/family_test.rb b/test/models/family_test.rb
index 1488234e..7223e64b 100644
--- a/test/models/family_test.rb
+++ b/test/models/family_test.rb
@@ -2,7 +2,7 @@ require "test_helper"
require "csv"
class FamilyTest < ActiveSupport::TestCase
- include Account::EntriesTestHelper
+ include EntriesTestHelper
include SyncableInterfaceTest
def setup
diff --git a/test/models/account/holding/forward_calculator_test.rb b/test/models/holding/forward_calculator_test.rb
similarity index 64%
rename from test/models/account/holding/forward_calculator_test.rb
rename to test/models/holding/forward_calculator_test.rb
index 70fd0e2a..f05e67fc 100644
--- a/test/models/account/holding/forward_calculator_test.rb
+++ b/test/models/holding/forward_calculator_test.rb
@@ -1,7 +1,7 @@
require "test_helper"
-class Account::Holding::ForwardCalculatorTest < ActiveSupport::TestCase
- include Account::EntriesTestHelper
+class Holding::ForwardCalculatorTest < ActiveSupport::TestCase
+ include EntriesTestHelper
setup do
@account = families(:empty).accounts.create!(
@@ -14,7 +14,7 @@ class Account::Holding::ForwardCalculatorTest < ActiveSupport::TestCase
end
test "no holdings" do
- calculated = Account::Holding::ForwardCalculator.new(@account).calculate
+ calculated = Holding::ForwardCalculator.new(@account).calculate
assert_equal [], calculated
end
@@ -35,32 +35,32 @@ class Account::Holding::ForwardCalculatorTest < ActiveSupport::TestCase
expected = [
# 4 days ago
- Account::Holding.new(security: @voo, date: 4.days.ago.to_date, qty: 0, price: 460, amount: 0),
- Account::Holding.new(security: @wmt, date: 4.days.ago.to_date, qty: 0, price: 100, amount: 0),
- Account::Holding.new(security: @amzn, date: 4.days.ago.to_date, qty: 0, price: 200, amount: 0),
+ Holding.new(security: @voo, date: 4.days.ago.to_date, qty: 0, price: 460, amount: 0),
+ Holding.new(security: @wmt, date: 4.days.ago.to_date, qty: 0, price: 100, amount: 0),
+ Holding.new(security: @amzn, date: 4.days.ago.to_date, qty: 0, price: 200, amount: 0),
# 3 days ago
- Account::Holding.new(security: @voo, date: 3.days.ago.to_date, qty: 20, price: 470, amount: 9400),
- Account::Holding.new(security: @wmt, date: 3.days.ago.to_date, qty: 0, price: 100, amount: 0),
- Account::Holding.new(security: @amzn, date: 3.days.ago.to_date, qty: 0, price: 200, amount: 0),
+ Holding.new(security: @voo, date: 3.days.ago.to_date, qty: 20, price: 470, amount: 9400),
+ Holding.new(security: @wmt, date: 3.days.ago.to_date, qty: 0, price: 100, amount: 0),
+ Holding.new(security: @amzn, date: 3.days.ago.to_date, qty: 0, price: 200, amount: 0),
# 2 days ago
- Account::Holding.new(security: @voo, date: 2.days.ago.to_date, qty: 5, price: 480, amount: 2400),
- Account::Holding.new(security: @wmt, date: 2.days.ago.to_date, qty: 0, price: 100, amount: 0),
- Account::Holding.new(security: @amzn, date: 2.days.ago.to_date, qty: 1, price: 200, amount: 200),
+ Holding.new(security: @voo, date: 2.days.ago.to_date, qty: 5, price: 480, amount: 2400),
+ Holding.new(security: @wmt, date: 2.days.ago.to_date, qty: 0, price: 100, amount: 0),
+ Holding.new(security: @amzn, date: 2.days.ago.to_date, qty: 1, price: 200, amount: 200),
# 1 day ago
- Account::Holding.new(security: @voo, date: 1.day.ago.to_date, qty: 10, price: 490, amount: 4900),
- Account::Holding.new(security: @wmt, date: 1.day.ago.to_date, qty: 100, price: 100, amount: 10000),
- Account::Holding.new(security: @amzn, date: 1.day.ago.to_date, qty: 0, price: 200, amount: 0),
+ Holding.new(security: @voo, date: 1.day.ago.to_date, qty: 10, price: 490, amount: 4900),
+ Holding.new(security: @wmt, date: 1.day.ago.to_date, qty: 100, price: 100, amount: 10000),
+ Holding.new(security: @amzn, date: 1.day.ago.to_date, qty: 0, price: 200, amount: 0),
# Today
- Account::Holding.new(security: @voo, date: Date.current, qty: 10, price: 500, amount: 5000),
- Account::Holding.new(security: @wmt, date: Date.current, qty: 100, price: 100, amount: 10000),
- Account::Holding.new(security: @amzn, date: Date.current, qty: 0, price: 200, amount: 0)
+ Holding.new(security: @voo, date: Date.current, qty: 10, price: 500, amount: 5000),
+ Holding.new(security: @wmt, date: Date.current, qty: 100, price: 100, amount: 10000),
+ Holding.new(security: @amzn, date: Date.current, qty: 0, price: 200, amount: 0)
]
- calculated = Account::Holding::ForwardCalculator.new(@account).calculate
+ calculated = Holding::ForwardCalculator.new(@account).calculate
assert_equal expected.length, calculated.length
assert_holdings(expected, calculated)
@@ -74,9 +74,9 @@ class Account::Holding::ForwardCalculatorTest < ActiveSupport::TestCase
create_trade(@wmt, qty: 100, date: 1.day.ago.to_date, price: 100, account: @account)
expected = [
- Account::Holding.new(security: @wmt, date: 2.days.ago.to_date, qty: 0, price: 100, amount: 0),
- Account::Holding.new(security: @wmt, date: 1.day.ago.to_date, qty: 100, price: 100, amount: 10000),
- Account::Holding.new(security: @wmt, date: Date.current, qty: 100, price: 100, amount: 10000)
+ Holding.new(security: @wmt, date: 2.days.ago.to_date, qty: 0, price: 100, amount: 0),
+ Holding.new(security: @wmt, date: 1.day.ago.to_date, qty: 100, price: 100, amount: 10000),
+ Holding.new(security: @wmt, date: Date.current, qty: 100, price: 100, amount: 10000)
]
# Price missing today, so we should carry forward the holding from 1 day ago
@@ -85,7 +85,7 @@ class Account::Holding::ForwardCalculatorTest < ActiveSupport::TestCase
Security::Price.stubs(:find_price).with(security: @wmt, date: 1.day.ago.to_date).returns(Security::Price.new(price: 100))
Security::Price.stubs(:find_price).with(security: @wmt, date: Date.current).returns(nil)
- calculated = Account::Holding::ForwardCalculator.new(@account).calculate
+ calculated = Holding::ForwardCalculator.new(@account).calculate
assert_equal expected.length, calculated.length
assert_holdings(expected, calculated)
@@ -98,13 +98,13 @@ class Account::Holding::ForwardCalculatorTest < ActiveSupport::TestCase
create_trade(offline_security, qty: 1, date: 1.day.ago.to_date, price: 100, account: @account)
expected = [
- Account::Holding.new(security: offline_security, date: 3.days.ago.to_date, qty: 1, price: 90, amount: 90),
- Account::Holding.new(security: offline_security, date: 2.days.ago.to_date, qty: 1, price: 90, amount: 90),
- Account::Holding.new(security: offline_security, date: 1.day.ago.to_date, qty: 2, price: 100, amount: 200),
- Account::Holding.new(security: offline_security, date: Date.current, qty: 2, price: 100, amount: 200)
+ Holding.new(security: offline_security, date: 3.days.ago.to_date, qty: 1, price: 90, amount: 90),
+ Holding.new(security: offline_security, date: 2.days.ago.to_date, qty: 1, price: 90, amount: 90),
+ Holding.new(security: offline_security, date: 1.day.ago.to_date, qty: 2, price: 100, amount: 200),
+ Holding.new(security: offline_security, date: Date.current, qty: 2, price: 100, amount: 200)
]
- calculated = Account::Holding::ForwardCalculator.new(@account).calculate
+ calculated = Holding::ForwardCalculator.new(@account).calculate
assert_equal expected.length, calculated.length
assert_holdings(expected, calculated)
diff --git a/test/models/account/holding/portfolio_cache_test.rb b/test/models/holding/portfolio_cache_test.rb
similarity index 80%
rename from test/models/account/holding/portfolio_cache_test.rb
rename to test/models/holding/portfolio_cache_test.rb
index 9b4124ed..2518e2b7 100644
--- a/test/models/account/holding/portfolio_cache_test.rb
+++ b/test/models/holding/portfolio_cache_test.rb
@@ -1,7 +1,7 @@
require "test_helper"
-class Account::Holding::PortfolioCacheTest < ActiveSupport::TestCase
- include Account::EntriesTestHelper, ProviderTestHelper
+class Holding::PortfolioCacheTest < ActiveSupport::TestCase
+ include EntriesTestHelper, ProviderTestHelper
setup do
@provider = mock
@@ -16,7 +16,7 @@ class Account::Holding::PortfolioCacheTest < ActiveSupport::TestCase
@security = Security.create!(name: "Test Security", ticker: "TEST", exchange_operating_mic: "TEST")
- @trade = create_trade(@security, account: @account, qty: 1, date: 2.days.ago.to_date, price: 210.23).account_trade
+ @trade = create_trade(@security, account: @account, qty: 1, date: 2.days.ago.to_date, price: 210.23).trade
end
test "gets price from DB if available" do
@@ -30,7 +30,7 @@ class Account::Holding::PortfolioCacheTest < ActiveSupport::TestCase
expect_provider_prices([], start_date: @account.start_date)
- cache = Account::Holding::PortfolioCache.new(@account)
+ cache = Holding::PortfolioCache.new(@account)
assert_equal db_price, cache.get_price(@security.id, Date.current).price
end
@@ -46,7 +46,7 @@ class Account::Holding::PortfolioCacheTest < ActiveSupport::TestCase
expect_provider_prices([ provider_price ], start_date: @account.start_date)
- cache = Account::Holding::PortfolioCache.new(@account)
+ cache = Holding::PortfolioCache.new(@account)
assert_equal provider_price.price, cache.get_price(@security.id, Date.current).price
end
@@ -54,15 +54,15 @@ class Account::Holding::PortfolioCacheTest < ActiveSupport::TestCase
Security::Price.destroy_all
expect_provider_prices([], start_date: @account.start_date)
- cache = Account::Holding::PortfolioCache.new(@account)
+ cache = Holding::PortfolioCache.new(@account)
assert_equal @trade.price, cache.get_price(@security.id, @trade.entry.date).price
end
test "if no price from db, provider, or trades, search holdings" do
Security::Price.delete_all
- Account::Entry.delete_all
+ Entry.delete_all
- holding = Account::Holding.create!(
+ holding = Holding.create!(
security: @security,
account: @account,
date: Date.current,
@@ -74,7 +74,7 @@ class Account::Holding::PortfolioCacheTest < ActiveSupport::TestCase
expect_provider_prices([], start_date: @account.start_date)
- cache = Account::Holding::PortfolioCache.new(@account, use_holdings: true)
+ cache = Holding::PortfolioCache.new(@account, use_holdings: true)
assert_equal holding.price, cache.get_price(@security.id, holding.date).price
end
diff --git a/test/models/account/holding/reverse_calculator_test.rb b/test/models/holding/reverse_calculator_test.rb
similarity index 74%
rename from test/models/account/holding/reverse_calculator_test.rb
rename to test/models/holding/reverse_calculator_test.rb
index 6e9535e5..4a13e71f 100644
--- a/test/models/account/holding/reverse_calculator_test.rb
+++ b/test/models/holding/reverse_calculator_test.rb
@@ -1,7 +1,7 @@
require "test_helper"
-class Account::Holding::ReverseCalculatorTest < ActiveSupport::TestCase
- include Account::EntriesTestHelper
+class Holding::ReverseCalculatorTest < ActiveSupport::TestCase
+ include EntriesTestHelper
setup do
@account = families(:empty).accounts.create!(
@@ -14,7 +14,7 @@ class Account::Holding::ReverseCalculatorTest < ActiveSupport::TestCase
end
test "no holdings" do
- calculated = Account::Holding::ReverseCalculator.new(@account).calculate
+ calculated = Holding::ReverseCalculator.new(@account).calculate
assert_equal [], calculated
end
@@ -26,7 +26,7 @@ class Account::Holding::ReverseCalculatorTest < ActiveSupport::TestCase
create_trade(voo, qty: -10, date: Date.current, price: 470, account: @account)
- calculated = Account::Holding::ReverseCalculator.new(@account).calculate
+ calculated = Holding::ReverseCalculator.new(@account).calculate
assert_equal 2, calculated.length
end
@@ -47,32 +47,32 @@ class Account::Holding::ReverseCalculatorTest < ActiveSupport::TestCase
expected = [
# 4 days ago
- Account::Holding.new(security: @voo, date: 4.days.ago.to_date, qty: 0, price: 460, amount: 0),
- Account::Holding.new(security: @wmt, date: 4.days.ago.to_date, qty: 0, price: 100, amount: 0),
- Account::Holding.new(security: @amzn, date: 4.days.ago.to_date, qty: 0, price: 200, amount: 0),
+ Holding.new(security: @voo, date: 4.days.ago.to_date, qty: 0, price: 460, amount: 0),
+ Holding.new(security: @wmt, date: 4.days.ago.to_date, qty: 0, price: 100, amount: 0),
+ Holding.new(security: @amzn, date: 4.days.ago.to_date, qty: 0, price: 200, amount: 0),
# 3 days ago
- Account::Holding.new(security: @voo, date: 3.days.ago.to_date, qty: 20, price: 470, amount: 9400),
- Account::Holding.new(security: @wmt, date: 3.days.ago.to_date, qty: 0, price: 100, amount: 0),
- Account::Holding.new(security: @amzn, date: 3.days.ago.to_date, qty: 0, price: 200, amount: 0),
+ Holding.new(security: @voo, date: 3.days.ago.to_date, qty: 20, price: 470, amount: 9400),
+ Holding.new(security: @wmt, date: 3.days.ago.to_date, qty: 0, price: 100, amount: 0),
+ Holding.new(security: @amzn, date: 3.days.ago.to_date, qty: 0, price: 200, amount: 0),
# 2 days ago
- Account::Holding.new(security: @voo, date: 2.days.ago.to_date, qty: 5, price: 480, amount: 2400),
- Account::Holding.new(security: @wmt, date: 2.days.ago.to_date, qty: 0, price: 100, amount: 0),
- Account::Holding.new(security: @amzn, date: 2.days.ago.to_date, qty: 1, price: 200, amount: 200),
+ Holding.new(security: @voo, date: 2.days.ago.to_date, qty: 5, price: 480, amount: 2400),
+ Holding.new(security: @wmt, date: 2.days.ago.to_date, qty: 0, price: 100, amount: 0),
+ Holding.new(security: @amzn, date: 2.days.ago.to_date, qty: 1, price: 200, amount: 200),
# 1 day ago
- Account::Holding.new(security: @voo, date: 1.day.ago.to_date, qty: 10, price: 490, amount: 4900),
- Account::Holding.new(security: @wmt, date: 1.day.ago.to_date, qty: 100, price: 100, amount: 10000),
- Account::Holding.new(security: @amzn, date: 1.day.ago.to_date, qty: 0, price: 200, amount: 0),
+ Holding.new(security: @voo, date: 1.day.ago.to_date, qty: 10, price: 490, amount: 4900),
+ Holding.new(security: @wmt, date: 1.day.ago.to_date, qty: 100, price: 100, amount: 10000),
+ Holding.new(security: @amzn, date: 1.day.ago.to_date, qty: 0, price: 200, amount: 0),
# Today
- Account::Holding.new(security: @voo, date: Date.current, qty: 10, price: 500, amount: 5000),
- Account::Holding.new(security: @wmt, date: Date.current, qty: 100, price: 100, amount: 10000),
- Account::Holding.new(security: @amzn, date: Date.current, qty: 0, price: 200, amount: 0)
+ Holding.new(security: @voo, date: Date.current, qty: 10, price: 500, amount: 5000),
+ Holding.new(security: @wmt, date: Date.current, qty: 100, price: 100, amount: 10000),
+ Holding.new(security: @amzn, date: Date.current, qty: 0, price: 200, amount: 0)
]
- calculated = Account::Holding::ReverseCalculator.new(@account).calculate
+ calculated = Holding::ReverseCalculator.new(@account).calculate
assert_equal expected.length, calculated.length
diff --git a/test/models/account/holding/syncer_test.rb b/test/models/holding/syncer_test.rb
similarity index 57%
rename from test/models/account/holding/syncer_test.rb
rename to test/models/holding/syncer_test.rb
index 43ca5dcb..19e191c8 100644
--- a/test/models/account/holding/syncer_test.rb
+++ b/test/models/holding/syncer_test.rb
@@ -1,7 +1,7 @@
require "test_helper"
-class Account::Holding::SyncerTest < ActiveSupport::TestCase
- include Account::EntriesTestHelper
+class Holding::SyncerTest < ActiveSupport::TestCase
+ include EntriesTestHelper
setup do
@family = families(:empty)
@@ -14,16 +14,16 @@ class Account::Holding::SyncerTest < ActiveSupport::TestCase
# Should have yesterday's and today's holdings
assert_difference "@account.holdings.count", 2 do
- Account::Holding::Syncer.new(@account, strategy: :forward).sync_holdings
+ Holding::Syncer.new(@account, strategy: :forward).sync_holdings
end
end
test "purges stale holdings for unlinked accounts" do
# Since the account has no entries, there should be no holdings
- Account::Holding.create!(account: @account, security: @aapl, qty: 1, price: 100, amount: 100, currency: "USD", date: Date.current)
+ Holding.create!(account: @account, security: @aapl, qty: 1, price: 100, amount: 100, currency: "USD", date: Date.current)
- assert_difference "Account::Holding.count", -1 do
- Account::Holding::Syncer.new(@account, strategy: :forward).sync_holdings
+ assert_difference "Holding.count", -1 do
+ Holding::Syncer.new(@account, strategy: :forward).sync_holdings
end
end
end
diff --git a/test/models/account/holding_test.rb b/test/models/holding_test.rb
similarity index 95%
rename from test/models/account/holding_test.rb
rename to test/models/holding_test.rb
index c3bf1c39..53fddf95 100644
--- a/test/models/account/holding_test.rb
+++ b/test/models/holding_test.rb
@@ -1,8 +1,8 @@
require "test_helper"
require "ostruct"
-class Account::HoldingTest < ActiveSupport::TestCase
- include Account::EntriesTestHelper, SecuritiesTestHelper
+class HoldingTest < ActiveSupport::TestCase
+ include EntriesTestHelper, SecuritiesTestHelper
setup do
@account = families(:empty).accounts.create!(name: "Test Brokerage", balance: 20000, cash_balance: 0, currency: "USD", accountable: Investment.new)
diff --git a/test/models/income_statement_test.rb b/test/models/income_statement_test.rb
index be97c941..fed6c539 100644
--- a/test/models/income_statement_test.rb
+++ b/test/models/income_statement_test.rb
@@ -1,7 +1,7 @@
require "test_helper"
class IncomeStatementTest < ActiveSupport::TestCase
- include Account::EntriesTestHelper
+ include EntriesTestHelper
setup do
@family = families(:empty)
diff --git a/test/models/plaid_investment_sync_test.rb b/test/models/plaid_investment_sync_test.rb
index 052a941a..f7a3e4e1 100644
--- a/test/models/plaid_investment_sync_test.rb
+++ b/test/models/plaid_investment_sync_test.rb
@@ -43,9 +43,9 @@ class PlaidInvestmentSyncTest < ActiveSupport::TestCase
]
# Cash holding should be ignored, resulting in 1, NOT 2 total holdings after sync
- assert_difference -> { Account::Trade.count } => 1,
- -> { Account::Transaction.count } => 0,
- -> { Account::Holding.count } => 1,
+ assert_difference -> { Trade.count } => 1,
+ -> { Transaction.count } => 0,
+ -> { Holding.count } => 1,
-> { Security.count } => 0 do
PlaidInvestmentSync.new(@plaid_account).sync!(
transactions: transactions,
@@ -69,8 +69,8 @@ class PlaidInvestmentSyncTest < ActiveSupport::TestCase
})
]
- assert_difference -> { Account::Trade.count } => 0,
- -> { Account::Transaction.count } => 1,
+ assert_difference -> { Trade.count } => 0,
+ -> { Transaction.count } => 1,
-> { Security.count } => 0 do
PlaidInvestmentSync.new(@plaid_account).sync!(
transactions: transactions,
diff --git a/test/models/trade_import_test.rb b/test/models/trade_import_test.rb
index b6293b0e..66637fc5 100644
--- a/test/models/trade_import_test.rb
+++ b/test/models/trade_import_test.rb
@@ -53,8 +53,8 @@ class TradeImportTest < ActiveSupport::TestCase
@import.reload
assert_difference [
- -> { Account::Entry.count },
- -> { Account::Trade.count }
+ -> { Entry.count },
+ -> { Trade.count }
], 2 do
assert_difference [
-> { Security.count },
diff --git a/test/models/transaction_import_test.rb b/test/models/transaction_import_test.rb
index 2299194c..c9afc553 100644
--- a/test/models/transaction_import_test.rb
+++ b/test/models/transaction_import_test.rb
@@ -58,8 +58,8 @@ class TransactionImportTest < ActiveSupport::TestCase
@import.reload
- assert_difference -> { Account::Entry.count } => 3,
- -> { Account::Transaction.count } => 3,
+ assert_difference -> { Entry.count } => 3,
+ -> { Transaction.count } => 3,
-> { Tag.count } => 1,
-> { Category.count } => 1,
-> { Account.count } => 1 do
diff --git a/test/models/transfer_test.rb b/test/models/transfer_test.rb
index a3a4ef42..2bc190f0 100644
--- a/test/models/transfer_test.rb
+++ b/test/models/transfer_test.rb
@@ -1,15 +1,15 @@
require "test_helper"
class TransferTest < ActiveSupport::TestCase
- include Account::EntriesTestHelper
+ include EntriesTestHelper
setup do
- @outflow = account_transactions(:transfer_out)
- @inflow = account_transactions(:transfer_in)
+ @outflow = transactions(:transfer_out)
+ @inflow = transactions(:transfer_in)
end
test "transfer destroyed if either transaction is destroyed" do
- assert_difference [ "Transfer.count", "Account::Transaction.count", "Account::Entry.count" ], -1 do
+ assert_difference [ "Transfer.count", "Transaction.count", "Entry.count" ], -1 do
@outflow.entry.destroy
end
end
@@ -20,8 +20,8 @@ class TransferTest < ActiveSupport::TestCase
assert_difference -> { Transfer.count } => 1 do
Transfer.create!(
- inflow_transaction: inflow_entry.account_transaction,
- outflow_transaction: outflow_entry.account_transaction,
+ inflow_transaction: inflow_entry.transaction,
+ outflow_transaction: outflow_entry.transaction,
)
end
end
@@ -31,8 +31,8 @@ class TransferTest < ActiveSupport::TestCase
inflow_entry = create_transaction(date: 1.day.ago.to_date, account: accounts(:depository), amount: -500)
transfer = Transfer.new(
- inflow_transaction: inflow_entry.account_transaction,
- outflow_transaction: outflow_entry.account_transaction,
+ inflow_transaction: inflow_entry.transaction,
+ outflow_transaction: outflow_entry.transaction,
)
assert_no_difference -> { Transfer.count } do
@@ -47,8 +47,8 @@ class TransferTest < ActiveSupport::TestCase
inflow_entry = create_transaction(date: Date.current, account: accounts(:credit_card), amount: -400)
transfer = Transfer.new(
- inflow_transaction: inflow_entry.account_transaction,
- outflow_transaction: outflow_entry.account_transaction,
+ inflow_transaction: inflow_entry.transaction,
+ outflow_transaction: outflow_entry.transaction,
)
assert_no_difference -> { Transfer.count } do
@@ -63,8 +63,8 @@ class TransferTest < ActiveSupport::TestCase
inflow_entry = create_transaction(date: 5.days.ago.to_date, account: accounts(:credit_card), amount: -500)
transfer = Transfer.new(
- inflow_transaction: inflow_entry.account_transaction,
- outflow_transaction: outflow_entry.account_transaction,
+ inflow_transaction: inflow_entry.transaction,
+ outflow_transaction: outflow_entry.transaction,
)
assert_no_difference -> { Transfer.count } do
@@ -85,8 +85,8 @@ class TransferTest < ActiveSupport::TestCase
inflow_txn = create_transaction(date: Date.current, account: family2_account, amount: -500)
transfer = Transfer.new(
- inflow_transaction: inflow_txn.account_transaction,
- outflow_transaction: outflow_txn.account_transaction,
+ inflow_transaction: inflow_txn.transaction,
+ outflow_transaction: outflow_txn.transaction,
)
assert transfer.invalid?
@@ -128,10 +128,10 @@ class TransferTest < ActiveSupport::TestCase
inflow_entry1 = create_transaction(date: Date.current, account: accounts(:credit_card), amount: -500)
inflow_entry2 = create_transaction(date: Date.current, account: accounts(:credit_card), amount: -500)
- Transfer.create!(inflow_transaction: inflow_entry1.account_transaction, outflow_transaction: outflow_entry.account_transaction)
+ Transfer.create!(inflow_transaction: inflow_entry1.transaction, outflow_transaction: outflow_entry.transaction)
assert_raises ActiveRecord::RecordInvalid do
- Transfer.create!(inflow_transaction: inflow_entry2.account_transaction, outflow_transaction: outflow_entry.account_transaction)
+ Transfer.create!(inflow_transaction: inflow_entry2.transaction, outflow_transaction: outflow_entry.transaction)
end
end
end
diff --git a/test/support/account/entries_test_helper.rb b/test/support/entries_test_helper.rb
similarity index 76%
rename from test/support/account/entries_test_helper.rb
rename to test/support/entries_test_helper.rb
index d6152381..c17b8065 100644
--- a/test/support/account/entries_test_helper.rb
+++ b/test/support/entries_test_helper.rb
@@ -1,4 +1,4 @@
-module Account::EntriesTestHelper
+module EntriesTestHelper
def create_transaction(attributes = {})
entry_attributes = attributes.except(:category, :tags, :merchant)
transaction_attributes = attributes.slice(:category, :tags, :merchant)
@@ -9,10 +9,10 @@ module Account::EntriesTestHelper
date: Date.current,
currency: "USD",
amount: 100,
- entryable: Account::Transaction.new(transaction_attributes)
+ entryable: Transaction.new(transaction_attributes)
}
- Account::Entry.create! entry_defaults.merge(entry_attributes)
+ Entry.create! entry_defaults.merge(entry_attributes)
end
def create_valuation(attributes = {})
@@ -22,16 +22,16 @@ module Account::EntriesTestHelper
date: 1.day.ago.to_date,
currency: "USD",
amount: 5000,
- entryable: Account::Valuation.new
+ entryable: Valuation.new
}
- Account::Entry.create! entry_defaults.merge(attributes)
+ Entry.create! entry_defaults.merge(attributes)
end
def create_trade(security, account:, qty:, date:, price: nil)
trade_price = price || Security::Price.find_by!(security: security, date: date).price
- trade = Account::Trade.new \
+ trade = Trade.new \
qty: qty,
security: security,
price: trade_price,
diff --git a/test/system/trades_test.rb b/test/system/trades_test.rb
index cff4a35f..d4da8368 100644
--- a/test/system/trades_test.rb
+++ b/test/system/trades_test.rb
@@ -22,11 +22,11 @@ class TradesTest < ApplicationSystemTestCase
fill_in "Ticker symbol", with: "AAPL"
fill_in "Date", with: Date.current
fill_in "Quantity", with: shares_qty
- fill_in "account_entry[price]", with: 214.23
+ fill_in "entry[price]", with: 214.23
click_button "Add transaction"
- visit_account_trades
+ visit_trades
within_trades do
assert_text "Purchase 10 shares of AAPL"
@@ -43,11 +43,11 @@ class TradesTest < ApplicationSystemTestCase
fill_in "Ticker symbol", with: aapl.ticker
fill_in "Date", with: Date.current
fill_in "Quantity", with: aapl.qty
- fill_in "account_entry[price]", with: 215.33
+ fill_in "entry[price]", with: 215.33
click_button "Add transaction"
- visit_account_trades
+ visit_trades
within_trades do
assert_text "Sell #{aapl.qty.round} shares of AAPL"
@@ -64,7 +64,7 @@ class TradesTest < ApplicationSystemTestCase
within "#" + dom_id(@account, "entries"), &block
end
- def visit_account_trades
+ def visit_trades
visit account_path(@account, tab: "activity")
end
diff --git a/test/system/transactions_test.rb b/test/system/transactions_test.rb
index 18f50c96..c7917bdb 100644
--- a/test/system/transactions_test.rb
+++ b/test/system/transactions_test.rb
@@ -4,7 +4,7 @@ class TransactionsTest < ApplicationSystemTestCase
setup do
sign_in @user = users(:family_admin)
- Account::Entry.delete_all # clean slate
+ Entry.delete_all # clean slate
create_transaction("one", 12.days.ago.to_date, 100)
create_transaction("two", 10.days.ago.to_date, 100)
@@ -19,7 +19,7 @@ class TransactionsTest < ApplicationSystemTestCase
create_transaction("eleven", Date.current, 100, category: categories(:food_and_drink), tags: [ tags(:one) ], merchant: merchants(:amazon))
@transactions = @user.family.entries
- .account_transactions
+ .transactions
.reverse_chronological
@transaction = @transactions.first
@@ -49,7 +49,7 @@ class TransactionsTest < ApplicationSystemTestCase
within "#transaction-filters-menu" do
check(@transaction.account.name)
click_button "Category"
- check(@transaction.account_transaction.category.name)
+ check(@transaction.transaction.category.name)
click_button "Apply"
end
@@ -57,7 +57,7 @@ class TransactionsTest < ApplicationSystemTestCase
within "#transaction-search-filters" do
assert_text @transaction.account.name
- assert_text @transaction.account_transaction.category.name
+ assert_text @transaction.transaction.category.name
end
end
@@ -77,7 +77,7 @@ class TransactionsTest < ApplicationSystemTestCase
within "#transaction-filters-menu" do
click_button "Category"
- check(@transaction.account_transaction.category.name)
+ check(@transaction.transaction.category.name)
click_button "Apply"
end
@@ -89,8 +89,8 @@ class TransactionsTest < ApplicationSystemTestCase
find("#transaction-filters-button").click
account = @transaction.account
- category = @transaction.account_transaction.category
- merchant = @transaction.account_transaction.merchant
+ category = @transaction.transaction.category
+ merchant = @transaction.transaction.merchant
within "#transaction-filters-menu" do
click_button "Account"
@@ -180,7 +180,7 @@ class TransactionsTest < ApplicationSystemTestCase
test "can create deposit transaction for investment account" do
investment_account = accounts(:investment)
- investment_account.entries.create!(name: "Investment account", date: Date.current, amount: 1000, currency: "USD", entryable: Account::Transaction.new)
+ investment_account.entries.create!(name: "Investment account", date: Date.current, amount: 1000, currency: "USD", entryable: Transaction.new)
transfer_date = Date.current
visit account_url(investment_account, tab: "activity")
within "[data-testid='activity-menu']" do
@@ -189,7 +189,7 @@ class TransactionsTest < ApplicationSystemTestCase
end
select "Deposit", from: "Type"
fill_in "Date", with: transfer_date
- fill_in "account_entry[amount]", with: 175.25
+ fill_in "entry[amount]", with: 175.25
click_button "Add transaction"
within "#entry-group-" + transfer_date.to_s do
assert_text "175.25"
@@ -218,7 +218,7 @@ class TransactionsTest < ApplicationSystemTestCase
date: date,
amount: amount,
currency: "USD",
- entryable: Account::Transaction.new(category: category, merchant: merchant, tags: tags)
+ entryable: Transaction.new(category: category, merchant: merchant, tags: tags)
end
def number_of_transactions_on_page