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.mdcindex 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 logictest "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_balancesendend# BAD!!# Unnecessary test - in this case, this is simply testing ActiveRecord's functionalitytest "saves balance" do- balance_record = Account::Balance.new(balance: 100, currency: "USD")+ balance_record = Balance.new(balance: 100, currency: "USD")assert balance_record.saveenddiff --git a/.cursor/rules/project-design.mdc b/.cursor/rules/project-design.mdcindex 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 API2. [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 Syncsdiff --git a/app/controllers/account/trades_controller.rb b/app/controllers/account/trades_controller.rbdeleted file mode 100644index 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-enddiff --git a/app/controllers/account/transaction_categories_controller.rb b/app/controllers/account/transaction_categories_controller.rbdeleted file mode 100644index 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-enddiff --git a/app/controllers/account/transactions_controller.rb b/app/controllers/account/transactions_controller.rbdeleted file mode 100644index 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-enddiff --git a/app/controllers/account/valuations_controller.rb b/app/controllers/account/valuations_controller.rbdeleted file mode 100644index 08f566f3..00000000--- a/app/controllers/account/valuations_controller.rb+++ /dev/null@@ -1,3 +0,0 @@-class Account::ValuationsController < ApplicationController- include EntryableResource-enddiff --git a/app/controllers/budget_categories_controller.rb b/app/controllers/budget_categories_controller.rbindex dcd96262..e8cc83e6 100644--- a/app/controllers/budget_categories_controller.rb+++ b/app/controllers/budget_categories_controller.rb@@ -11,14 +11,14 @@ class BudgetCategoriesController < ApplicationControllerif 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)enddef updatediff --git a/app/controllers/concerns/entryable_resource.rb b/app/controllers/concerns/entryable_resource.rbindex 58519725..443b0483 100644--- a/app/controllers/concerns/entryable_resource.rb+++ b/app/controllers/concerns/entryable_resource.rb@@ -2,14 +2,9 @@ module EntryableResourceextend ActiveSupport::Concernincluded 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]enddef 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)enddef 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"enddef 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"enddef 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")endprivate- 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.newenddef 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- )- endenddiff --git a/app/controllers/concerns/stream_extensions.rb b/app/controllers/concerns/stream_extensions.rbnew file mode 100644index 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+enddiff --git a/app/controllers/account/holdings_controller.rb b/app/controllers/holdings_controller.rbsimilarity index 92%rename from app/controllers/account/holdings_controller.rbrename to app/controllers/holdings_controller.rbindex 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 < ApplicationControllerbefore_action :set_holding, only: %i[show destroy]def indexdiff --git a/app/controllers/trades_controller.rb b/app/controllers/trades_controller.rbnew file mode 100644index 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+enddiff --git a/app/controllers/transaction_categories_controller.rb b/app/controllers/transaction_categories_controller.rbnew file mode 100644index 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+enddiff --git a/app/controllers/transactions/bulk_deletions_controller.rb b/app/controllers/transactions/bulk_deletions_controller.rbnew file mode 100644index 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+enddiff --git a/app/controllers/transactions/bulk_updates_controller.rb b/app/controllers/transactions/bulk_updates_controller.rbnew file mode 100644index 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+enddiff --git a/app/controllers/transactions_controller.rb b/app/controllers/transactions_controller.rbindex 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, EntryableResourcebefore_action :store_params!, only: :index@@ -48,7 +48,62 @@ class TransactionsController < ApplicationControllerredirect_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+ enddef search_paramscleaned_params = params.fetch(:q, {})diff --git a/app/controllers/account/transfer_matches_controller.rb b/app/controllers/transfer_matches_controller.rbsimilarity index 73%rename from app/controllers/account/transfer_matches_controller.rbrename to app/controllers/transfer_matches_controller.rbindex 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 < ApplicationControllerbefore_action :set_entrydef 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_candidatesenddef 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"endprivate@@ -27,7 +27,7 @@ class Account::TransferMatchesController < ApplicationControllerif 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 < ApplicationControllertarget_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"transferdiff --git a/app/controllers/valuations_controller.rb b/app/controllers/valuations_controller.rbnew file mode 100644index 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+enddiff --git a/app/helpers/account/entries_helper.rb b/app/helpers/entries_helper.rbsimilarity index 78%rename from app/helpers/account/entries_helper.rbrename to app/helpers/entries_helper.rbindex 5fac75cc..e198e6ee 100644--- a/app/helpers/account/entries_helper.rb+++ b/app/helpers/entries_helper.rb@@ -1,8 +1,8 @@-module Account::EntriesHelper+module EntriesHelperdef 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&.idend@@ -12,7 +12,7 @@ module Account::EntriesHelpergrouped_entrieselsegrouped_entries.reject do |e|- e.entryable_type == "Account::Transaction" &&+ e.entryable_type == "Transaction" &&e.entryable.transfer_as_inflow.present?endend@@ -25,7 +25,7 @@ module Account::EntriesHelpernext 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_safeenddiff --git a/app/models/account.rb b/app/models/account.rbindex b93a13e1..42a9d67f 100644--- a/app/models/account.rb+++ b/app/models/account.rb@@ -7,11 +7,11 @@ class Account < ApplicationRecordbelongs_to :import, optional: truehas_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: :destroyhas_many :balances, dependent: :destroymonetize :balance, :cash_balance@@ -43,14 +43,14 @@ class Account < ApplicationRecorddate: 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 < ApplicationRecordenddef update_balance!(balance)- valuation = entries.account_valuations.find_by(date: Date.current)+ valuation = entries.valuations.find_by(date: Date.current)if valuationvaluation.update! amount: balance@@ -123,7 +123,7 @@ class Account < ApplicationRecordname: "Balance update",amount: balance,currency: currency,- entryable: Account::Valuation.new+ entryable: Valuation.newendend@@ -148,7 +148,7 @@ class Account < ApplicationRecordenddef first_valuation- entries.account_valuations.order(:date).first+ entries.valuations.order(:date).firstenddef first_valuation_amountdiff --git a/app/models/account/chartable.rb b/app/models/account/chartable.rbindex bac6a50e..d9a6c44b 100644--- a/app/models/account/chartable.rb+++ b/app/models/account/chartable.rb@@ -7,7 +7,7 @@ module Account::Chartableseries_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::ChartableCOUNT(CASE WHEN accounts.currency <> :target_currency AND er.rate IS NULL THEN 1 END) as missing_ratesFROM dates dLEFT 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 ANDab.currency = accounts.currency ANDab.account_id = accounts.iddiff --git a/app/models/account/enrichable.rb b/app/models/account/enrichable.rbindex 260aec5a..f5f175b4 100644--- a/app/models/account/enrichable.rb+++ b/app/models/account/enrichable.rb@@ -2,9 +2,9 @@ module Account::Enrichableextend ActiveSupport::Concerndef 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").countif total_unenriched > 0@@ -63,7 +63,7 @@ module Account::Enrichabletransactions.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.rbdeleted file mode 100644index 219ecd90..00000000--- a/app/models/account/valuation.rb+++ /dev/null@@ -1,3 +0,0 @@-class Account::Valuation < ApplicationRecord- include Account::Entryable-enddiff --git a/app/models/account_import.rb b/app/models/account_import.rbindex 98e7e0d0..96fdfd47 100644--- a/app/models/account_import.rb+++ b/app/models/account_import.rb@@ -20,7 +20,7 @@ class AccountImport < Importcurrency: row.currency,date: Date.current,name: "Imported account value",- entryable: Account::Valuation.new+ entryable: Valuation.new)endenddiff --git a/app/models/account/balance.rb b/app/models/balance.rbsimilarity index 85%rename from app/models/account/balance.rbrename to app/models/balance.rbindex 5d4e3710..90c4df41 100644--- a/app/models/account/balance.rb+++ b/app/models/balance.rb@@ -1,4 +1,4 @@-class Account::Balance < ApplicationRecord+class Balance < ApplicationRecordinclude Monetizablebelongs_to :accountdiff --git a/app/models/account/balance/base_calculator.rb b/app/models/balance/base_calculator.rbsimilarity index 84%rename from app/models/account/balance/base_calculator.rbrename to app/models/balance/base_calculator.rbindex 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::BaseCalculatorattr_reader :accountdef initialize(account)@@ -13,11 +13,11 @@ class Account::Balance::BaseCalculatorprivatedef sync_cache- @sync_cache ||= Account::Balance::SyncCache.new(account)+ @sync_cache ||= Balance::SyncCache.new(account)enddef 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.rbsimilarity index 90%rename from app/models/account/balance/forward_calculator.rbrename to app/models/balance/forward_calculator.rbindex 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::BaseCalculatorprivatedef calculate_balancescurrent_cash_balance = 0diff --git a/app/models/account/balance/reverse_calculator.rb b/app/models/balance/reverse_calculator.rbsimilarity index 92%rename from app/models/account/balance/reverse_calculator.rbrename to app/models/balance/reverse_calculator.rbindex 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::BaseCalculatorprivatedef calculate_balancescurrent_cash_balance = account.cash_balancediff --git a/app/models/account/balance/sync_cache.rb b/app/models/balance/sync_cache.rbsimilarity index 83%rename from app/models/account/balance/sync_cache.rbrename to app/models/balance/sync_cache.rbindex 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::SyncCachedef initialize(account)@account = accountenddef get_valuation(date)- converted_entries.find { |e| e.date == date && e.account_valuation? }+ converted_entries.find { |e| e.date == date && e.valuation? }enddef get_holdings(date)@@ -12,7 +12,7 @@ class Account::Balance::SyncCacheenddef 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?) }endprivatediff --git a/app/models/account/balance/syncer.rb b/app/models/balance/syncer.rbsimilarity index 86%rename from app/models/account/balance/syncer.rbrename to app/models/balance/syncer.rbindex 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::Syncerattr_reader :account, :strategydef initialize(account, strategy:)@@ -7,7 +7,7 @@ class Account::Balance::Syncerenddef sync_balances- Account::Balance.transaction do+ Balance.transaction dosync_holdingscalculate_balances@@ -26,7 +26,7 @@ class Account::Balance::Syncerprivatedef sync_holdings- @holdings = Account::Holding::Syncer.new(account, strategy: strategy).sync_holdings+ @holdings = Holding::Syncer.new(account, strategy: strategy).sync_holdingsenddef update_account_info@@ -63,9 +63,9 @@ class Account::Balance::Syncerdef calculatorif strategy == :reverse- Account::Balance::ReverseCalculator.new(account)+ Balance::ReverseCalculator.new(account)else- Account::Balance::ForwardCalculator.new(account)+ Balance::ForwardCalculator.new(account)endendenddiff --git a/app/models/account/balance_trend_calculator.rb b/app/models/balance/trend_calculator.rbsimilarity index 95%rename from app/models/account/balance_trend_calculator.rbrename to app/models/balance/trend_calculator.rbindex 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::TrendCalculatorBalanceTrend = Struct.new(:trend, :cash, keyword_init: true)class << self@@ -48,12 +48,12 @@ class Account::BalanceTrendCalculatortodays_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.amountcurrent_cash_balance = e.amountelsemultiplier = e.account.liability? ? 1 : -1- balance_change = e.account_trade? ? 0 : multiplier * e.amount+ balance_change = e.trade? ? 0 : multiplier * e.amountcash_change = multiplier * e.amountcurrent_balance = prior_balance + balance_changediff --git a/app/models/category.rb b/app/models/category.rbindex 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 :familydiff --git a/app/models/demo/generator.rb b/app/models/demo/generator.rbindex 9d62e684..181b9806 100644--- a/app/models/demo/generator.rb+++ b/app/models/demo/generator.rb@@ -361,7 +361,7 @@ class Demo::Generatorunknown = 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::Generatoramount: 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)endend@@ -450,20 +450,20 @@ class Demo::Generatorentry_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)enddef 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.newenddef random_family_record(model, family)diff --git a/app/models/account/entry.rb b/app/models/entry.rbsimilarity index 78%rename from app/models/account/entry.rbrename to app/models/entry.rbindex 4e6292a1..0f35cd39 100644--- a/app/models/account/entry.rb+++ b/app/models/entry.rb@@ -1,4 +1,4 @@-class Account::Entry < ApplicationRecord+class Entry < ApplicationRecordinclude Monetizablemonetize :amount@@ -7,11 +7,11 @@ class Account::Entry < ApplicationRecordbelongs_to :transfer, optional: truebelongs_to :import, optional: true- delegated_type :entryable, types: Account::Entryable::TYPES, dependent: :destroy+ delegated_type :entryable, types: Entryable::TYPES, dependent: :destroyaccepts_nested_attributes_for :entryablevalidates :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 < ApplicationRecordscope :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 < ApplicationRecordscope :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 < ApplicationRecordenddef balance_trend(entries, balances)- Account::BalanceTrendCalculator.new(self, entries, balances).trend+ Balance::TrendCalculator.new(self, entries, balances).trendenddef display_name@@ -53,7 +53,7 @@ class Account::Entry < ApplicationRecordclass << selfdef search(params)- Account::EntrySearch.new(params).build_query(all)+ EntrySearch.new(params).build_query(all)end# arbitrary cutoff date to avoid expensive sync operationsdiff --git a/app/models/account/entry_search.rb b/app/models/entry_search.rbsimilarity index 74%rename from app/models/account/entry_search.rbrename to app/models/entry_search.rbindex b08c338f..bed87613 100644--- a/app/models/account/entry_search.rb+++ b/app/models/entry_search.rb@@ -1,4 +1,4 @@-class Account::EntrySearch+class EntrySearchinclude ActiveModel::Modelinclude ActiveModel::Attributes@@ -16,7 +16,7 @@ class Account::EntrySearchreturn 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::EntrySearchreturn 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?queryend@@ -38,11 +38,11 @@ class Account::EntrySearchcase amount_operatorwhen "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)endquerydiff --git a/app/models/account/entryable.rb b/app/models/entryable.rbsimilarity index 50%rename from app/models/account/entryable.rbrename to app/models/entryable.rbindex 91df5521..84ab6c12 100644--- a/app/models/account/entryable.rb+++ b/app/models/entryable.rb@@ -1,7 +1,7 @@-module Account::Entryable+module Entryableextend 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::Entryablescope :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)}endenddiff --git a/app/models/family/auto_transfer_matchable.rb b/app/models/family/auto_transfer_matchable.rbindex 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::AutoTransferMatchabledef 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 ANDoutflow_candidates.amount > 0 ANDinflow_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 firstenddiff --git a/app/models/account/holding.rb b/app/models/holding.rbsimilarity index 79%rename from app/models/account/holding.rbrename to app/models/holding.rbindex ba7a7e2d..fb9b001e 100644--- a/app/models/account/holding.rb+++ b/app/models/holding.rb@@ -1,4 +1,4 @@-class Account::Holding < ApplicationRecord+class Holding < ApplicationRecordinclude Monetizable, Gapfillablemonetize :amount@@ -27,9 +27,9 @@ class Account::Holding < ApplicationRecord# Basic approximation of cost-basisdef 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.rbsimilarity index 88%rename from app/models/account/holding/base_calculator.rbrename to app/models/holding/base_calculator.rbindex 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::BaseCalculatorattr_reader :accountdef initialize(account)@@ -8,13 +8,13 @@ class Account::Holding::BaseCalculatordef calculateRails.logger.tagged(self.class.name) doholdings = calculate_holdings- Account::Holding.gapfill(holdings)+ Holding.gapfill(holdings)endendprivatedef portfolio_cache- @portfolio_cache ||= Account::Holding::PortfolioCache.new(account)+ @portfolio_cache ||= Holding::PortfolioCache.new(account)enddef empty_portfolio@@ -49,7 +49,7 @@ class Account::Holding::BaseCalculatornextend- 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.rbsimilarity index 77%rename from app/models/account/holding/forward_calculator.rbrename to app/models/holding/forward_calculator.rbindex 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::BaseCalculatorprivatedef portfolio_cache- @portfolio_cache ||= Account::Holding::PortfolioCache.new(account)+ @portfolio_cache ||= Holding::PortfolioCache.new(account)enddef calculate_holdingsdiff --git a/app/models/account/holding/gapfillable.rb b/app/models/holding/gapfillable.rbsimilarity index 91%rename from app/models/account/holding/gapfillable.rbrename to app/models/holding/gapfillable.rbindex 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::Gapfillableextend ActiveSupport::Concernclass_methods do@@ -19,7 +19,7 @@ module Account::Holding::Gapfillableprevious_holding = holdingelse# 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.rbsimilarity index 98%rename from app/models/account/holding/portfolio_cache.rbrename to app/models/holding/portfolio_cache.rbindex 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::PortfolioCacheattr_reader :account, :use_holdingsclass SecurityNotFound < StandardError@@ -49,7 +49,7 @@ class Account::Holding::PortfolioCachePriceWithPriority = 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_aenddef holdingsdiff --git a/app/models/account/holding/reverse_calculator.rb b/app/models/holding/reverse_calculator.rbsimilarity index 87%rename from app/models/account/holding/reverse_calculator.rbrename to app/models/holding/reverse_calculator.rbindex 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::BaseCalculatorprivate# 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)enddef calculate_holdingsdiff --git a/app/models/account/holding/syncer.rb b/app/models/holding/syncer.rbsimilarity index 84%rename from app/models/account/holding/syncer.rbrename to app/models/holding/syncer.rbindex 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::Syncerdef initialize(account, strategy:)@account = account@strategy = strategy@@ -36,7 +36,7 @@ class Account::Holding::Syncerenddef 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 holdingsif portfolio_security_ids.empty?@@ -50,9 +50,9 @@ class Account::Holding::Syncerdef calculatorif strategy == :reverse- Account::Holding::ReverseCalculator.new(account)+ Holding::ReverseCalculator.new(account)else- Account::Holding::ForwardCalculator.new(account)+ Holding::ForwardCalculator.new(account)endendenddiff --git a/app/models/import.rb b/app/models/import.rbindex 662b4cee..bb367cf9 100644--- a/app/models/import.rb+++ b/app/models/import.rb@@ -34,7 +34,7 @@ class Import < ApplicationRecordhas_many :rows, dependent: :destroyhas_many :mappings, dependent: :destroyhas_many :accounts, dependent: :destroy- has_many :entries, dependent: :destroy, class_name: "Account::Entry"+ has_many :entries, dependent: :destroyclass << selfdef parse_csv_str(csv_str, col_sep: ",")diff --git a/app/models/import/row.rb b/app/models/import/row.rbindex 622a9d0a..350d8084 100644--- a/app/models/import/row.rb+++ b/app/models/import/row.rb@@ -63,7 +63,7 @@ class Import::Row < ApplicationRecordreturnend- min_date = Account::Entry.min_supported_date+ min_date = Entry.min_supported_datemax_date = Date.currentif parsed_date < min_date || parsed_date > max_datediff --git a/app/models/income_statement/base_query.rb b/app/models/income_statement/base_query.rbindex 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::BaseQueryCOUNT(ae.id) as transactions_count,BOOL_OR(ae.currency <> :target_currency AND er.rate IS NULL) as missing_exchange_ratesFROM (#{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_idLEFT JOIN (SELECT t.*, t.id as transfer_id, a.accountable_typeFROM 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 ORdiff --git a/app/models/merchant.rb b/app/models/merchant.rbindex 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 :familyvalidates :name, :color, :family, presence: truediff --git a/app/models/mint_import.rb b/app/models/mint_import.rbindex 66e3bb69..da9ced2a 100644--- a/app/models/mint_import.rb+++ b/app/models/mint_import.rb@@ -35,7 +35,7 @@ class MintImport < Importname: row.name,currency: row.currency,notes: row.notes,- entryable: Account::Transaction.new(category: category, tags: tags),+ entryable: Transaction.new(category: category, tags: tags),import: selfentry.save!diff --git a/app/models/plaid_account.rb b/app/models/plaid_account.rbindex e0e71f67..4f2b923c 100644--- a/app/models/plaid_account.rb+++ b/app/models/plaid_account.rb@@ -87,7 +87,7 @@ class PlaidAccount < ApplicationRecordt.amount = plaid_txn.amountt.currency = plaid_txn.iso_currency_codet.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 < ApplicationRecorde.amount = loan_data.origination_principal_amounte.currency = account.currencye.date = loan_data.origination_date- e.entryable = Account::Valuation.new+ e.entryable = Valuation.newendendenddiff --git a/app/models/plaid_investment_sync.rb b/app/models/plaid_investment_sync.rbindex bcb1f330..489b0ca1 100644--- a/app/models/plaid_investment_sync.rb+++ b/app/models/plaid_investment_sync.rb@@ -31,7 +31,7 @@ class PlaidInvestmentSynct.amount = transaction.amountt.currency = transaction.iso_currency_codet.date = transaction.date- t.entryable = Account::Transaction.new+ t.entryable = Transaction.newendelsenew_transaction = plaid_account.account.entries.find_or_create_by!(plaid_id: transaction.investment_transaction_id) do |t|@@ -39,7 +39,7 @@ class PlaidInvestmentSynct.amount = transaction.quantity * transaction.pricet.currency = transaction.iso_currency_codet.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.rbindex b30a1071..42d2979e 100644--- a/app/models/property.rb+++ b/app/models/property.rb@@ -44,6 +44,6 @@ class Property < ApplicationRecordprivatedef 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_moneyendenddiff --git a/app/models/rejected_transfer.rb b/app/models/rejected_transfer.rbindex 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"enddiff --git a/app/models/security.rb b/app/models/security.rbindex 30abbe85..0adabd8a 100644--- a/app/models/security.rb+++ b/app/models/security.rb@@ -3,7 +3,7 @@ class Security < ApplicationRecordbefore_save :upcase_ticker- has_many :trades, dependent: :nullify, class_name: "Account::Trade"+ has_many :trades, dependent: :nullify, class_name: "Trade"has_many :prices, dependent: :destroyvalidates :ticker, presence: truediff --git a/app/models/tag.rb b/app/models/tag.rbindex 6b2fb67b..c5bdc0bc 100644--- a/app/models/tag.rb+++ b/app/models/tag.rb@@ -1,7 +1,7 @@class Tag < ApplicationRecordbelongs_to :familyhas_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.rbsimilarity index 83%rename from app/models/account/trade.rbrename to app/models/trade.rbindex 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, Monetizablemonetize :pricediff --git a/app/models/account/trade_builder.rb b/app/models/trade_builder.rbsimilarity index 94%rename from app/models/account/trade_builder.rbrename to app/models/trade_builder.rbindex c632f272..9b7e0471 100644--- a/app/models/account/trade_builder.rb+++ b/app/models/trade_builder.rb@@ -1,4 +1,4 @@-class Account::TradeBuilder+class TradeBuilderinclude ActiveModel::Modelattr_accessor :account, :date, :amount, :currency, :qty,@@ -46,7 +46,7 @@ class Account::TradeBuilderdate: 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::TradeBuilderdate: date,amount: signed_amount,currency: currency,- entryable: Account::Transaction.new+ entryable: Transaction.new)endend@@ -85,7 +85,7 @@ class Account::TradeBuilderdate: date,amount: signed_amount,currency: currency,- entryable: Account::Transaction.new+ entryable: Transaction.new)enddiff --git a/app/models/trade_import.rb b/app/models/trade_import.rbindex db917f04..d126fec0 100644--- a/app/models/trade_import.rb+++ b/app/models/trade_import.rb@@ -16,12 +16,12 @@ class TradeImport < Importexchange_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)endenddiff --git a/app/models/account/transaction.rb b/app/models/transaction.rbsimilarity index 64%rename from app/models/account/transaction.rbrename to app/models/transaction.rbindex 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, Providedbelongs_to :category, optional: truebelongs_to :merchant, optional: true@@ -11,7 +11,7 @@ class Account::Transaction < ApplicationRecordclass << selfdef search(params)- Account::TransactionSearch.new(params).build_query(all)+ Search.new(params).build_query(all)endendenddiff --git a/app/models/account/transaction/provided.rb b/app/models/transaction/provided.rbsimilarity index 89%rename from app/models/account/transaction/provided.rbrename to app/models/transaction/provided.rbindex 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::Providedextend ActiveSupport::Concerndef fetch_enrichment_infodiff --git a/app/models/account/transaction_search.rb b/app/models/transaction/search.rbsimilarity index 77%rename from app/models/account/transaction_search.rbrename to app/models/transaction/search.rbindex 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::Searchinclude ActiveModel::Modelinclude ActiveModel::Attributes@@ -22,10 +22,10 @@ class Account::TransactionSearchquery = 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)queryend@@ -36,12 +36,12 @@ class Account::TransactionSearchLEFT JOIN (SELECT t.*, t.id as transfer_id, a.accountable_typeFROM 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)SQLend@@ -68,8 +68,8 @@ class Account::TransactionSearchreturn 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.sortwhen [ "transfer" ]diff --git a/app/models/account/transaction/transferable.rb b/app/models/transaction/transferable.rbsimilarity index 96%rename from app/models/account/transaction/transferable.rbrename to app/models/transaction/transferable.rbindex 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::Transferableextend ActiveSupport::Concernincluded dodiff --git a/app/models/transaction_import.rb b/app/models/transaction_import.rbindex cf3f6e12..dd44cca4 100644--- a/app/models/transaction_import.rb+++ b/app/models/transaction_import.rb@@ -13,10 +13,10 @@ class TransactionImport < Importcategory = 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)endenddiff --git a/app/models/transfer.rb b/app/models/transfer.rbindex 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 < ApplicationRecordendnew(- 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.rbnew file mode 100644index 00000000..6d1d2b4b--- /dev/null+++ b/app/models/valuation.rb@@ -0,0 +1,3 @@+class Valuation < ApplicationRecord+ include Entryable+enddiff --git a/app/models/vehicle.rb b/app/models/vehicle.rbindex 6ba19540..255e11d6 100644--- a/app/models/vehicle.rb+++ b/app/models/vehicle.rb@@ -31,6 +31,6 @@ class Vehicle < ApplicationRecordprivatedef 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_moneyendenddiff --git a/app/views/account/transactions/_header.html.erb b/app/views/account/transactions/_header.html.erbdeleted file mode 100644index 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.erbdeleted file mode 100644index 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.erbindex 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.erbindex 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.erbindex 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.erbsimilarity index 100%rename from app/views/account/entries/_empty.html.erbrename to app/views/entries/_empty.html.erbdiff --git a/app/views/account/entries/_entry.html.erb b/app/views/entries/_entry.html.erbsimilarity index 100%rename from app/views/account/entries/_entry.html.erbrename to app/views/entries/_entry.html.erbdiff --git a/app/views/account/entries/_entry_group.html.erb b/app/views/entries/_entry_group.html.erbsimilarity index 100%rename from app/views/account/entries/_entry_group.html.erbrename to app/views/entries/_entry_group.html.erbdiff --git a/app/views/account/entries/_loading.html.erb b/app/views/entries/_loading.html.erbsimilarity index 100%rename from app/views/account/entries/_loading.html.erbrename to app/views/entries/_loading.html.erbdiff --git a/app/views/account/entries/_ruler.html.erb b/app/views/entries/_ruler.html.erbsimilarity index 100%rename from app/views/account/entries/_ruler.html.erbrename to app/views/entries/_ruler.html.erbdiff --git a/app/views/account/entries/_selection_bar.html.erb b/app/views/entries/_selection_bar.html.erbsimilarity index 86%rename from app/views/account/entries/_selection_bar.html.erbrename to app/views/entries/_selection_bar.html.erbindex 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.erbsimilarity index 100%rename from app/views/account/holdings/_cash.html.erbrename to app/views/holdings/_cash.html.erbdiff --git a/app/views/account/holdings/_holding.html.erb b/app/views/holdings/_holding.html.erbsimilarity index 93%rename from app/views/account/holdings/_holding.html.erbrename to app/views/holdings/_holding.html.erbindex 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.erbsimilarity index 100%rename from app/views/account/holdings/_missing_price_tooltip.html.erbrename to app/views/holdings/_missing_price_tooltip.html.erbdiff --git a/app/views/account/holdings/_ruler.html.erb b/app/views/holdings/_ruler.html.erbsimilarity index 100%rename from app/views/account/holdings/_ruler.html.erbrename to app/views/holdings/_ruler.html.erbdiff --git a/app/views/account/holdings/index.html.erb b/app/views/holdings/index.html.erbsimilarity index 80%rename from app/views/account/holdings/index.html.erbrename to app/views/holdings/index.html.erbindex 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.erbsimilarity index 100%rename from app/views/account/holdings/new.html.erbrename to app/views/holdings/new.html.erbdiff --git a/app/views/account/holdings/show.html.erb b/app/views/holdings/show.html.erbsimilarity index 95%rename from app/views/account/holdings/show.html.erbrename to app/views/holdings/show.html.erbindex 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.erbindex 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.erbsimilarity index 87%rename from app/views/account/trades/_form.html.erbrename to app/views/trades/_form.html.erbindex 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.erbsimilarity index 98%rename from app/views/account/trades/_header.html.erbrename to app/views/trades/_header.html.erbindex 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.erbsimilarity index 97%rename from app/views/account/trades/_trade.html.erbrename to app/views/trades/_trade.html.erbindex 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.erbsimilarity index 52%rename from app/views/account/trades/new.html.erbrename to app/views/trades/new.html.erbindex 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.erbsimilarity index 91%rename from app/views/account/trades/show.html.erbrename to app/views/trades/show.html.erbindex 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-smfont-medium border border-secondary",diff --git a/app/views/account/transactions/_form.html.erb b/app/views/transactions/_form.html.erbsimilarity index 91%rename from app/views/account/transactions/_form.html.erbrename to app/views/transactions/_form.html.erbindex 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.erbindex 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.erbsimilarity index 86%rename from app/views/account/transactions/_selection_bar.html.erbrename to app/views/transactions/_selection_bar.html.erbindex 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.erbsimilarity index 94%rename from app/views/account/transactions/_transaction.html.erbrename to app/views/transactions/_transaction.html.erbindex 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.erbsimilarity index 100%rename from app/views/account/transactions/_transaction_category.html.erbrename to app/views/transactions/_transaction_category.html.erbdiff --git a/app/views/account/transactions/_transfer_match.html.erb b/app/views/transactions/_transfer_match.html.erbsimilarity index 100%rename from app/views/account/transactions/_transfer_match.html.erbrename to app/views/transactions/_transfer_match.html.erbdiff --git a/app/views/account/transactions/bulk_edit.html.erb b/app/views/transactions/bulk_updates/new.html.erbsimilarity index 71%rename from app/views/account/transactions/bulk_edit.html.erbrename to app/views/transactions/bulk_updates/new.html.erbindex 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.erbindex 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.erbnew file mode 100644index 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.erbsimilarity index 90%rename from app/views/account/transactions/show.html.erbrename to app/views/transactions/show.html.erbindex 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-smfont-medium border border-secondary",diff --git a/app/views/account/transfer_matches/_matching_fields.html.erb b/app/views/transfer_matches/_matching_fields.html.erbsimilarity index 100%rename from app/views/account/transfer_matches/_matching_fields.html.erbrename to app/views/transfer_matches/_matching_fields.html.erbdiff --git a/app/views/account/transfer_matches/new.html.erb b/app/views/transfer_matches/new.html.erbsimilarity index 91%rename from app/views/account/transfer_matches/new.html.erbrename to app/views/transfer_matches/new.html.erbindex 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.erbindex 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.erbindex 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.erbsimilarity index 71%rename from app/views/account/valuations/_form.html.erbrename to app/views/valuations/_form.html.erbindex 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.erbsimilarity index 100%rename from app/views/account/valuations/_header.html.erbrename to app/views/valuations/_header.html.erbdiff --git a/app/views/account/valuations/_valuation.html.erb b/app/views/valuations/_valuation.html.erbsimilarity index 97%rename from app/views/account/valuations/_valuation.html.erbrename to app/views/valuations/_valuation.html.erbindex 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.erbsimilarity index 82%rename from app/views/account/valuations/index.html.erbrename to app/views/valuations/index.html.erbindex 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.erbsimilarity index 100%rename from app/views/account/valuations/new.html.erbrename to app/views/valuations/new.html.erbdiff --git a/app/views/account/valuations/show.html.erb b/app/views/valuations/show.html.erbsimilarity index 91%rename from app/views/account/valuations/show.html.erbrename to app/views/valuations/show.html.erbindex 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.ignoreindex 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.ymlsimilarity index 90%rename from config/locales/models/account/entry/en.ymlrename to config/locales/models/entry/en.ymlindex 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} becausediff --git a/config/locales/views/account/entries/en.yml b/config/locales/views/account/entries/en.ymldeleted file mode 100644index 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 updateddiff --git a/config/locales/views/account/holdings/en.yml b/config/locales/views/account/holdings/en.ymldeleted file mode 100644index 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: Unknowndiff --git a/config/locales/views/account/trades/en.yml b/config/locales/views/account/trades/en.ymldeleted file mode 100644index 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: Settingsdiff --git a/config/locales/views/account/transactions/en.yml b/config/locales/views/account/transactions/en.ymldeleted file mode 100644index 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 createddiff --git a/config/locales/views/account/valuations/en.yml b/config/locales/views/account/valuations/en.ymldeleted file mode 100644index 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: Settingsdiff --git a/config/locales/views/entries/en.yml b/config/locales/views/entries/en.ymlnew file mode 100644index 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 updateddiff --git a/config/locales/views/holdings/en.yml b/config/locales/views/holdings/en.ymlnew file mode 100644index 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: Unknowndiff --git a/config/locales/views/trades/en.yml b/config/locales/views/trades/en.ymlnew file mode 100644index 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: Settingsdiff --git a/config/locales/views/transactions/en.yml b/config/locales/views/transactions/en.ymlindex 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 categoriesedit_imports: Edit importsdiff --git a/config/locales/views/valuations/en.yml b/config/locales/views/valuations/en.ymlnew file mode 100644index 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: Settingsdiff --git a/config/routes.rb b/config/routes.rbindex e8e072ae..b4767b46 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -95,7 +95,7 @@ Rails.application.routes.draw doresources :mappings, only: :update, module: :importend- resources :accounts, only: %i[index new] do+ resources :accounts, only: %i[index new], shallow: true docollection dopost :sync_allend@@ -107,42 +107,34 @@ Rails.application.routes.draw doendend- 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_filterend-- 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, optionselseroute_for entry.entryable_name, entry, optionsendend- 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/123direct :account do |model, options|diff --git a/db/migrate/20250413141446_table_renames.rb b/db/migrate/20250413141446_table_renames.rbnew file mode 100644index 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+enddiff --git a/db/schema.rb b/db/schema.rbindex 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 databaseenable_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) dot.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: falset.uuid "category_id", null: false@@ -227,6 +168,26 @@ ActiveRecord::Schema[7.2].define(version: 2025_04_11_140604) dot.datetime "updated_at", null: falseend+ 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: falset.string "to_currency", null: false@@ -255,6 +216,21 @@ ActiveRecord::Schema[7.2].define(version: 2025_04_11_140604) dot.boolean "data_enrichment_enabled", default: falseend+ 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: falset.string "controller"@@ -585,6 +561,25 @@ ActiveRecord::Schema[7.2].define(version: 2025_04_11_140604) dot.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: falset.uuid "outflow_transaction_id", null: false@@ -624,6 +619,11 @@ ActiveRecord::Schema[7.2].define(version: 2025_04_11_140604) dot.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: falset.datetime "updated_at", null: false@@ -634,24 +634,21 @@ ActiveRecord::Schema[7.2].define(version: 2025_04_11_140604) dot.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: :cascadeadd_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) doadd_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) doadd_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: :cascadeadd_foreign_key "users", "chats", column: "last_viewed_chat_id"add_foreign_key "users", "families"enddiff --git a/lib/tasks/securities.rake b/lib/tasks/securities.rakeindex 57ec28f6..4254b8c6 100644--- a/lib/tasks/securities.rake+++ b/lib/tasks/securities.rake@@ -81,8 +81,8 @@ namespace :securities doputs " 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).countprices_count = Security::Price.where(security_id: security.id).countputs " Would update:"@@ -94,8 +94,8 @@ namespace :securities dobeginActiveRecord::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 doputs " 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).countprices_count = Security::Price.where(security_id: duplicates).counttotal_holdings += holdings_count@@ -151,8 +151,8 @@ namespace :securities dobeginActiveRecord::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 duplicatesdiff --git a/test/controllers/account/transactions_controller_test.rb b/test/controllers/account/transactions_controller_test.rbdeleted file mode 100644index 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-enddiff --git a/test/controllers/categories_controller_test.rb b/test/controllers/categories_controller_test.rbindex 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::IntegrationTestsetup dosign_in users(:family_admin)- @transaction = account_transactions :one+ @transaction = transactions :oneendtest "index" dodiff --git a/test/controllers/category/deletions_controller_test.rb b/test/controllers/category/deletions_controller_test.rbindex 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::IntegrationTestassert_not_empty @category.transactionsassert_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 dopost category_deletions_url(@category)endenddiff --git a/test/controllers/credit_cards_controller_test.rb b/test/controllers/credit_cards_controller_test.rbindex 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::IntegrationTesttest "creates with credit card details" doassert_difference -> { Account.count } => 1,-> { CreditCard.count } => 1,- -> { Account::Valuation.count } => 2,- -> { Account::Entry.count } => 2 do+ -> { Valuation.count } => 2,+ -> { Entry.count } => 2 dopost 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.rbsimilarity index 61%rename from test/controllers/account/holdings_controller_test.rbrename to test/controllers/holdings_controller_test.rbindex 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::IntegrationTestsetup dosign_in users(:family_admin)@account = accounts(:investment)@@ -8,20 +8,20 @@ class Account::HoldingsControllerTest < ActionDispatch::IntegrationTestendtest "gets holdings" do- get account_holdings_url(account_id: @account.id)+ get holdings_url(account_id: @account.id)assert_response :successendtest "gets holding" do- get account_holding_path(@holding)+ get holding_path(@holding)assert_response :successendtest "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)endassert_redirected_to account_path(@holding.account)diff --git a/test/controllers/loans_controller_test.rb b/test/controllers/loans_controller_test.rbindex 774c5d1a..ec590363 100644--- a/test/controllers/loans_controller_test.rb+++ b/test/controllers/loans_controller_test.rb@@ -11,8 +11,8 @@ class LoansControllerTest < ActionDispatch::IntegrationTesttest "creates with loan details" doassert_difference -> { Account.count } => 1,-> { Loan.count } => 1,- -> { Account::Valuation.count } => 2,- -> { Account::Entry.count } => 2 do+ -> { Valuation.count } => 2,+ -> { Entry.count } => 2 dopost loans_path, params: {account: {name: "New Loan",diff --git a/test/controllers/properties_controller_test.rb b/test/controllers/properties_controller_test.rbindex 9eaf63e8..43053373 100644--- a/test/controllers/properties_controller_test.rb+++ b/test/controllers/properties_controller_test.rb@@ -11,8 +11,8 @@ class PropertiesControllerTest < ActionDispatch::IntegrationTesttest "creates with property details" doassert_difference -> { Account.count } => 1,-> { Property.count } => 1,- -> { Account::Valuation.count } => 2,- -> { Account::Entry.count } => 2 do+ -> { Valuation.count } => 2,+ -> { Entry.count } => 2 dopost properties_path, params: {account: {name: "Property",diff --git a/test/controllers/settings/hostings_controller_test.rb b/test/controllers/settings/hostings_controller_test.rbindex 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::IntegrationTestassert_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)endtest "can clear data only when admin" dodiff --git a/test/controllers/account/trades_controller_test.rb b/test/controllers/trades_controller_test.rbsimilarity index 63%rename from test/controllers/account/trades_controller_test.rbrename to test/controllers/trades_controller_test.rbindex 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::IntegrationTestinclude EntryableResourceInterfaceTestsetup dosign_in @user = users(:family_admin)- @entry = account_entries(:trade)+ @entry = entries(:trade)endtest "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::IntegrationTestassert_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.priceassert_equal "USD", @entry.currencyassert_redirected_to account_url(@entry.account)@@ -36,11 +36,11 @@ class Account::TradesControllerTest < ActionDispatch::IntegrationTesttest "creates deposit entry" dofrom_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::IntegrationTesttest "creates withdrawal entry" doto_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::IntegrationTestendtest "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).firstassert created_entry.amount.positive?assert_redirected_to @entry.accountendtest "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).firstassert created_entry.amount.negative?assert_redirected_to @entry.accountendtest "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).firstassert 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: SyncJobassert_redirected_to account_url(created_entry.account)endtest "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).firstassert 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: SyncJobassert_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.rbnew file mode 100644index 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+enddiff --git a/test/controllers/transactions/bulk_updates_controller_test.rb b/test/controllers/transactions/bulk_updates_controller_test.rbnew file mode 100644index 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+enddiff --git a/test/controllers/transactions_controller_test.rb b/test/controllers/transactions_controller_test.rbindex 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, EntriesTestHelpersetup dosign_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)endtest "transaction count represents filtered total" do@@ -19,7 +85,7 @@ class TransactionsControllerTest < ActionDispatch::IntegrationTestget 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_ssearchable_transaction = create_transaction(account: account, name: "Unique test name")@@ -39,7 +105,7 @@ class TransactionsControllerTest < ActionDispatch::IntegrationTestcreate_transaction(account: account)end- sorted_transactions = family.entries.account_transactions.reverse_chronological.to_a+ sorted_transactions = family.entries.transactions.reverse_chronological.to_aassert_equal 11, sorted_transactions.countdiff --git a/test/controllers/account/transfer_matches_controller_test.rb b/test/controllers/transfer_matches_controller_test.rbsimilarity index 71%rename from test/controllers/account/transfer_matches_controller_test.rbrename to test/controllers/transfer_matches_controller_test.rbindex 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 EntriesTestHelpersetup dosign_in @user = users(:family_admin)@@ -12,7 +12,7 @@ class Account::TransferMatchesControllerTest < ActionDispatch::IntegrationTestoutflow_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::IntegrationTesttest "creates transfer for target account" doinflow_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).iddiff --git a/test/controllers/account/valuations_controller_test.rb b/test/controllers/valuations_controller_test.rbsimilarity index 59%rename from test/controllers/account/valuations_controller_test.rbrename to test/controllers/valuations_controller_test.rbindex 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::IntegrationTestinclude EntryableResourceInterfaceTestsetup dosign_in @user = users(:family_admin)- @entry = account_entries(:valuation)+ @entry = entries(:valuation)endtest "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::IntegrationTestendtest "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).firstassert_enqueued_with job: SyncJob@@ -43,9 +44,9 @@ class Account::ValuationsControllerTest < ActionDispatch::IntegrationTestendtest "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.rbindex 3ebd23e3..bb7df9c6 100644--- a/test/controllers/vehicles_controller_test.rb+++ b/test/controllers/vehicles_controller_test.rb@@ -11,8 +11,8 @@ class VehiclesControllerTest < ActionDispatch::IntegrationTesttest "creates with vehicle details" doassert_difference -> { Account.count } => 1,-> { Vehicle.count } => 1,- -> { Account::Valuation.count } => 2,- -> { Account::Entry.count } => 2 do+ -> { Valuation.count } => 2,+ -> { Entry.count } => 2 dopost vehicles_path, params: {account: {name: "Vehicle",diff --git a/test/fixtures/account/balances.yml b/test/fixtures/balances.ymlsimilarity index 100%rename from test/fixtures/account/balances.ymlrename to test/fixtures/balances.ymldiff --git a/test/fixtures/account/entries.yml b/test/fixtures/entries.ymlsimilarity index 80%rename from test/fixtures/account/entries.ymlrename to test/fixtures/entries.ymlindex ccaf29bf..6eac29d2 100644--- a/test/fixtures/account/entries.yml+++ b/test/fixtures/entries.yml@@ -4,7 +4,7 @@ valuation:amount: 4995currency: USDaccount: depository- entryable_type: Account::Valuation+ entryable_type: Valuationentryable: onetrade:@@ -13,7 +13,7 @@ trade:amount: 2140 # 10 shares * $214 per sharecurrency: USDaccount: investment- entryable_type: Account::Trade+ entryable_type: Tradeentryable: onetransaction:@@ -22,7 +22,7 @@ transaction:amount: 10currency: USDaccount: depository- entryable_type: Account::Transaction+ entryable_type: Transactionentryable: onetransfer_out:@@ -31,7 +31,7 @@ transfer_out:amount: 100currency: USDaccount: depository- entryable_type: Account::Transaction+ entryable_type: Transactionentryable: transfer_outtransfer_in:@@ -40,5 +40,5 @@ transfer_in:amount: -100currency: USDaccount: credit_card- entryable_type: Account::Transaction+ entryable_type: Transactionentryable: transfer_indiff --git a/test/fixtures/account/holdings.yml b/test/fixtures/holdings.ymlsimilarity index 100%rename from test/fixtures/account/holdings.ymlrename to test/fixtures/holdings.ymldiff --git a/test/fixtures/taggings.yml b/test/fixtures/taggings.ymlindex 5039ba27..12432311 100644--- a/test/fixtures/taggings.yml+++ b/test/fixtures/taggings.yml@@ -1,10 +1,10 @@one:tag: onetaggable: one- taggable_type: Account::Transaction+ taggable_type: Transactiontwo:tag: twotaggable: one- taggable_type: Account::Transaction+ taggable_type: Transactiondiff --git a/test/fixtures/account/trades.yml b/test/fixtures/trades.ymlsimilarity index 100%rename from test/fixtures/account/trades.ymlrename to test/fixtures/trades.ymldiff --git a/test/fixtures/account/transactions.yml b/test/fixtures/transactions.ymlsimilarity index 100%rename from test/fixtures/account/transactions.ymlrename to test/fixtures/transactions.ymldiff --git a/test/fixtures/account/valuations.yml b/test/fixtures/valuations.ymlsimilarity index 100%rename from test/fixtures/account/valuations.ymlrename to test/fixtures/valuations.ymldiff --git a/test/interfaces/accountable_resource_interface_test.rb b/test/interfaces/accountable_resource_interface_test.rbindex 1a99d63e..551995de 100644--- a/test/interfaces/accountable_resource_interface_test.rb+++ b/test/interfaces/accountable_resource_interface_test.rb@@ -60,7 +60,7 @@ module AccountableResourceInterfaceTestendtest "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 dopatch account_url(@account), params: {account: {balance: 12000@@ -74,9 +74,9 @@ module AccountableResourceInterfaceTestendtest "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" ] dopatch account_url(@account), params: {account: {balance: 12000diff --git a/test/interfaces/entryable_resource_interface_test.rb b/test/interfaces/entryable_resource_interface_test.rbindex 28ba3e75..710912ac 100644--- a/test/interfaces/entryable_resource_interface_test.rb+++ b/test/interfaces/entryable_resource_interface_test.rb@@ -9,13 +9,13 @@ module EntryableResourceInterfaceTestendtest "shows editing drawer" do- get account_entry_url(@entry)+ get entry_url(@entry)assert_response :successendtest "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)endassert_enqueued_with job: SyncJobdiff --git a/test/models/account/balance/syncer_test.rb b/test/models/account/balance/syncer_test.rbdeleted file mode 100644index 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-enddiff --git a/test/models/account/convertible_test.rb b/test/models/account/convertible_test.rbindex 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, ProviderTestHelpersetup do@family = families(:empty)diff --git a/test/models/account/entry_test.rb b/test/models/account/entry_test.rbindex 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 EntriesTestHelpersetup do- @entry = account_entries :transaction+ @entry = entries :transactionendtest "entry cannot be older than 10 years ago" do@@ -14,10 +14,10 @@ class Account::EntryTest < ActiveSupport::TestCaseendtest "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, # invalidcurrency: existing_valuation.currency,@@ -76,7 +76,7 @@ class Account::EntryTest < ActiveSupport::TestCaseaccounts(:credit_card).update!(is_active: false)# Test the scope- active_entries = Account::Entry.active+ active_entries = Entry.active# Should include entry from active accountassert_includes active_entries, active_transactiondiff --git a/test/models/account/transaction_test.rb b/test/models/account/transaction_test.rbindex 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 EntriesTestHelperenddiff --git a/test/models/account_test.rb b/test/models/account_test.rbindex 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, EntriesTestHelpersetup do@account = @syncable = accounts(:depository)diff --git a/test/models/account/balance/forward_calculator_test.rb b/test/models/balance/forward_calculator_test.rbsimilarity index 79%rename from test/models/account/balance/forward_calculator_test.rbrename to test/models/balance/forward_calculator_test.rbindex 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 EntriesTestHelpersetup do@account = families(:empty).accounts.create!(@@ -18,7 +18,7 @@ class Account::Balance::ForwardCalculatorTest < ActiveSupport::TestCaseassert_equal 0, @account.balances.countexpected = [ 0, 0 ]- calculated = Account::Balance::ForwardCalculator.new(@account).calculate+ calculated = Balance::ForwardCalculator.new(@account).calculateassert_equal expected, calculated.map(&:balance)end@@ -28,7 +28,7 @@ class Account::Balance::ForwardCalculatorTest < ActiveSupport::TestCasecreate_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, calculatedend@@ -38,7 +38,7 @@ class Account::Balance::ForwardCalculatorTest < ActiveSupport::TestCasecreate_transaction(account: @account, date: 2.days.ago.to_date, amount: 100) # expenseexpected = [ 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, calculatedend@@ -52,7 +52,7 @@ class Account::Balance::ForwardCalculatorTest < ActiveSupport::TestCasecreate_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, calculatedend@@ -67,7 +67,7 @@ class Account::Balance::ForwardCalculatorTest < ActiveSupport::TestCasecreate_transaction(account: @account, date: 1.day.ago.to_date, amount: -500, currency: "EUR") # €500 * 1.2 = $600expected = [ 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, calculatedenddiff --git a/test/models/account/balance/reverse_calculator_test.rb b/test/models/balance/reverse_calculator_test.rbsimilarity index 77%rename from test/models/account/balance/reverse_calculator_test.rbrename to test/models/balance/reverse_calculator_test.rbindex 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 EntriesTestHelpersetup do@account = families(:empty).accounts.create!(@@ -18,7 +18,7 @@ class Account::Balance::ReverseCalculatorTest < ActiveSupport::TestCaseassert_equal 0, @account.balances.countexpected = [ @account.balance, @account.balance ]- calculated = Account::Balance::ReverseCalculator.new(@account).calculate+ calculated = Balance::ReverseCalculator.new(@account).calculateassert_equal expected, calculated.map(&:balance)end@@ -28,7 +28,7 @@ class Account::Balance::ReverseCalculatorTest < ActiveSupport::TestCasecreate_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, calculatedend@@ -38,7 +38,7 @@ class Account::Balance::ReverseCalculatorTest < ActiveSupport::TestCasecreate_transaction(account: @account, date: 2.days.ago.to_date, amount: 100) # expenseexpected = [ 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, calculatedend@@ -52,7 +52,7 @@ class Account::Balance::ReverseCalculatorTest < ActiveSupport::TestCasecreate_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, calculatedenddiff --git a/test/models/balance/syncer_test.rb b/test/models/balance/syncer_test.rbnew file mode 100644index 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+enddiff --git a/test/models/family/auto_transfer_matchable_test.rb b/test/models/family/auto_transfer_matchable_test.rbindex 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 EntriesTestHelpersetup do@family = families(:dylan_family)diff --git a/test/models/family_test.rb b/test/models/family_test.rbindex 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 EntriesTestHelperinclude SyncableInterfaceTestdef setupdiff --git a/test/models/account/holding/forward_calculator_test.rb b/test/models/holding/forward_calculator_test.rbsimilarity index 64%rename from test/models/account/holding/forward_calculator_test.rbrename to test/models/holding/forward_calculator_test.rbindex 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 EntriesTestHelpersetup do@account = families(:empty).accounts.create!(@@ -14,7 +14,7 @@ class Account::Holding::ForwardCalculatorTest < ActiveSupport::TestCaseendtest "no holdings" do- calculated = Account::Holding::ForwardCalculator.new(@account).calculate+ calculated = Holding::ForwardCalculator.new(@account).calculateassert_equal [], calculatedend@@ -35,32 +35,32 @@ class Account::Holding::ForwardCalculatorTest < ActiveSupport::TestCaseexpected = [# 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).calculateassert_equal expected.length, calculated.lengthassert_holdings(expected, calculated)@@ -74,9 +74,9 @@ class Account::Holding::ForwardCalculatorTest < ActiveSupport::TestCasecreate_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::TestCaseSecurity::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).calculateassert_equal expected.length, calculated.lengthassert_holdings(expected, calculated)@@ -98,13 +98,13 @@ class Account::Holding::ForwardCalculatorTest < ActiveSupport::TestCasecreate_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).calculateassert_equal expected.length, calculated.lengthassert_holdings(expected, calculated)diff --git a/test/models/account/holding/portfolio_cache_test.rb b/test/models/holding/portfolio_cache_test.rbsimilarity index 80%rename from test/models/account/holding/portfolio_cache_test.rbrename to test/models/holding/portfolio_cache_test.rbindex 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, ProviderTestHelpersetup 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).tradeendtest "gets price from DB if available" do@@ -30,7 +30,7 @@ class Account::Holding::PortfolioCacheTest < ActiveSupport::TestCaseexpect_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).priceend@@ -46,7 +46,7 @@ class Account::Holding::PortfolioCacheTest < ActiveSupport::TestCaseexpect_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).priceend@@ -54,15 +54,15 @@ class Account::Holding::PortfolioCacheTest < ActiveSupport::TestCaseSecurity::Price.destroy_allexpect_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).priceendtest "if no price from db, provider, or trades, search holdings" doSecurity::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::TestCaseexpect_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).priceenddiff --git a/test/models/account/holding/reverse_calculator_test.rb b/test/models/holding/reverse_calculator_test.rbsimilarity index 74%rename from test/models/account/holding/reverse_calculator_test.rbrename to test/models/holding/reverse_calculator_test.rbindex 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 EntriesTestHelpersetup do@account = families(:empty).accounts.create!(@@ -14,7 +14,7 @@ class Account::Holding::ReverseCalculatorTest < ActiveSupport::TestCaseendtest "no holdings" do- calculated = Account::Holding::ReverseCalculator.new(@account).calculate+ calculated = Holding::ReverseCalculator.new(@account).calculateassert_equal [], calculatedend@@ -26,7 +26,7 @@ class Account::Holding::ReverseCalculatorTest < ActiveSupport::TestCasecreate_trade(voo, qty: -10, date: Date.current, price: 470, account: @account)- calculated = Account::Holding::ReverseCalculator.new(@account).calculate+ calculated = Holding::ReverseCalculator.new(@account).calculateassert_equal 2, calculated.lengthend@@ -47,32 +47,32 @@ class Account::Holding::ReverseCalculatorTest < ActiveSupport::TestCaseexpected = [# 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).calculateassert_equal expected.length, calculated.lengthdiff --git a/test/models/account/holding/syncer_test.rb b/test/models/holding/syncer_test.rbsimilarity index 57%rename from test/models/account/holding/syncer_test.rbrename to test/models/holding/syncer_test.rbindex 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 EntriesTestHelpersetup do@family = families(:empty)@@ -14,16 +14,16 @@ class Account::Holding::SyncerTest < ActiveSupport::TestCase# Should have yesterday's and today's holdingsassert_difference "@account.holdings.count", 2 do- Account::Holding::Syncer.new(@account, strategy: :forward).sync_holdings+ Holding::Syncer.new(@account, strategy: :forward).sync_holdingsendendtest "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_holdingsendendenddiff --git a/test/models/account/holding_test.rb b/test/models/holding_test.rbsimilarity index 95%rename from test/models/account/holding_test.rbrename to test/models/holding_test.rbindex 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, SecuritiesTestHelpersetup 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.rbindex 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 EntriesTestHelpersetup do@family = families(:empty)diff --git a/test/models/plaid_investment_sync_test.rb b/test/models/plaid_investment_sync_test.rbindex 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 doPlaidInvestmentSync.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 doPlaidInvestmentSync.new(@plaid_account).sync!(transactions: transactions,diff --git a/test/models/trade_import_test.rb b/test/models/trade_import_test.rbindex 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.reloadassert_difference [- -> { Account::Entry.count },- -> { Account::Trade.count }+ -> { Entry.count },+ -> { Trade.count }], 2 doassert_difference [-> { Security.count },diff --git a/test/models/transaction_import_test.rb b/test/models/transaction_import_test.rbindex 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 dodiff --git a/test/models/transfer_test.rb b/test/models/transfer_test.rbindex 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 EntriesTestHelpersetup do- @outflow = account_transactions(:transfer_out)- @inflow = account_transactions(:transfer_in)+ @outflow = transactions(:transfer_out)+ @inflow = transactions(:transfer_in)endtest "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.destroyendend@@ -20,8 +20,8 @@ class TransferTest < ActiveSupport::TestCaseassert_difference -> { Transfer.count } => 1 doTransfer.create!(- inflow_transaction: inflow_entry.account_transaction,- outflow_transaction: outflow_entry.account_transaction,+ inflow_transaction: inflow_entry.transaction,+ outflow_transaction: outflow_entry.transaction,)endend@@ -31,8 +31,8 @@ class TransferTest < ActiveSupport::TestCaseinflow_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::TestCaseinflow_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::TestCaseinflow_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::TestCaseinflow_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::TestCaseinflow_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)endendenddiff --git a/test/support/account/entries_test_helper.rb b/test/support/entries_test_helper.rbsimilarity index 76%rename from test/support/account/entries_test_helper.rbrename to test/support/entries_test_helper.rbindex 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 EntriesTestHelperdef create_transaction(attributes = {})entry_attributes = attributes.except(:category, :tags, :merchant)transaction_attributes = attributes.slice(:category, :tags, :merchant)@@ -9,10 +9,10 @@ module Account::EntriesTestHelperdate: 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)enddef create_valuation(attributes = {})@@ -22,16 +22,16 @@ module Account::EntriesTestHelperdate: 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)enddef 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.rbindex cff4a35f..d4da8368 100644--- a/test/system/trades_test.rb+++ b/test/system/trades_test.rb@@ -22,11 +22,11 @@ class TradesTest < ApplicationSystemTestCasefill_in "Ticker symbol", with: "AAPL"fill_in "Date", with: Date.currentfill_in "Quantity", with: shares_qty- fill_in "account_entry[price]", with: 214.23+ fill_in "entry[price]", with: 214.23click_button "Add transaction"- visit_account_trades+ visit_tradeswithin_trades doassert_text "Purchase 10 shares of AAPL"@@ -43,11 +43,11 @@ class TradesTest < ApplicationSystemTestCasefill_in "Ticker symbol", with: aapl.tickerfill_in "Date", with: Date.currentfill_in "Quantity", with: aapl.qty- fill_in "account_entry[price]", with: 215.33+ fill_in "entry[price]", with: 215.33click_button "Add transaction"- visit_account_trades+ visit_tradeswithin_trades doassert_text "Sell #{aapl.qty.round} shares of AAPL"@@ -64,7 +64,7 @@ class TradesTest < ApplicationSystemTestCasewithin "#" + dom_id(@account, "entries"), &blockend- def visit_account_trades+ def visit_tradesvisit account_path(@account, tab: "activity")enddiff --git a/test/system/transactions_test.rb b/test/system/transactions_test.rbindex 18f50c96..c7917bdb 100644--- a/test/system/transactions_test.rb+++ b/test/system/transactions_test.rb@@ -4,7 +4,7 @@ class TransactionsTest < ApplicationSystemTestCasesetup dosign_in @user = users(:family_admin)- Account::Entry.delete_all # clean slate+ Entry.delete_all # clean slatecreate_transaction("one", 12.days.ago.to_date, 100)create_transaction("two", 10.days.ago.to_date, 100)@@ -19,7 +19,7 @@ class TransactionsTest < ApplicationSystemTestCasecreate_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 < ApplicationSystemTestCasewithin "#transaction-filters-menu" docheck(@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 < ApplicationSystemTestCasewithin "#transaction-search-filters" doassert_text @transaction.account.name- assert_text @transaction.account_transaction.category.name+ assert_text @transaction.transaction.category.nameendend@@ -77,7 +77,7 @@ class TransactionsTest < ApplicationSystemTestCasewithin "#transaction-filters-menu" doclick_button "Category"- check(@transaction.account_transaction.category.name)+ check(@transaction.transaction.category.name)click_button "Apply"end@@ -89,8 +89,8 @@ class TransactionsTest < ApplicationSystemTestCasefind("#transaction-filters-button").clickaccount = @transaction.account- category = @transaction.account_transaction.category- merchant = @transaction.account_transaction.merchant+ category = @transaction.transaction.category+ merchant = @transaction.transaction.merchantwithin "#transaction-filters-menu" doclick_button "Account"@@ -180,7 +180,7 @@ class TransactionsTest < ApplicationSystemTestCasetest "can create deposit transaction for investment account" doinvestment_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.currentvisit account_url(investment_account, tab: "activity")within "[data-testid='activity-menu']" do@@ -189,7 +189,7 @@ class TransactionsTest < ApplicationSystemTestCaseendselect "Deposit", from: "Type"fill_in "Date", with: transfer_date- fill_in "account_entry[amount]", with: 175.25+ fill_in "entry[amount]", with: 175.25click_button "Add transaction"within "#entry-group-" + transfer_date.to_s doassert_text "175.25"@@ -218,7 +218,7 @@ class TransactionsTest < ApplicationSystemTestCasedate: date,amount: amount,currency: "USD",- entryable: Account::Transaction.new(category: category, merchant: merchant, tags: tags)+ entryable: Transaction.new(category: category, merchant: merchant, tags: tags)enddef number_of_transactions_on_page