Skip to content

armgit / maybe

Public Imported from GitHub
0

The personal finance app for everyone

Account namespace updates: part 6 (transactions) (#904)

Zach Gollwitzerda18c3d85082
diff --git a/app/controllers/transaction/rows_controller.rb b/app/controllers/account/transaction/rows_controller.rb
similarity index 51%
rename from app/controllers/transaction/rows_controller.rb
rename to app/controllers/account/transaction/rows_controller.rb
index 08f081b9..9bc823f3 100644
--- a/app/controllers/transaction/rows_controller.rb
+++ b/app/controllers/account/transaction/rows_controller.rb
@@ -1,4 +1,4 @@
-class Transaction::RowsController < ApplicationController
+class Account::Transaction::RowsController < ApplicationController
before_action :set_transaction, only: %i[ show update ]
def show
@@ -7,7 +7,7 @@ class Transaction::RowsController < ApplicationController
def update
@transaction.update! transaction_params
- redirect_to transaction_row_path(@transaction)
+ redirect_to account_transaction_row_path(@transaction.account, @transaction)
end
private
@@ -17,6 +17,6 @@ class Transaction::RowsController < ApplicationController
end
def set_transaction
- @transaction = Current.family.transactions.find(params[:id])
+ @transaction = Current.family.accounts.find(params[:account_id]).transactions.find(params[:transaction_id])
end
end
diff --git a/app/controllers/account/transaction/rules_controller.rb b/app/controllers/account/transaction/rules_controller.rb
new file mode 100644
index 00000000..704b2119
--- /dev/null
+++ b/app/controllers/account/transaction/rules_controller.rb
@@ -0,0 +1,6 @@
+class Account::Transaction::RulesController < ApplicationController
+ layout "with_sidebar"
+
+ def index
+ end
+end
diff --git a/app/controllers/account/transactions_controller.rb b/app/controllers/account/transactions_controller.rb
new file mode 100644
index 00000000..184725f6
--- /dev/null
+++ b/app/controllers/account/transactions_controller.rb
@@ -0,0 +1,44 @@
+class Account::TransactionsController < ApplicationController
+ layout "with_sidebar"
+
+ before_action :set_account
+ before_action :set_transaction, only: %i[ show update destroy ]
+
+ def index
+ @transactions = @account.transactions.ordered
+ end
+
+ def show
+ end
+
+ def update
+ @transaction.update! transaction_params
+ @transaction.sync_account_later
+
+ redirect_back_or_to account_transaction_url(@transaction.account, @transaction), notice: t(".success")
+ end
+
+ def destroy
+ @transaction.destroy!
+ @transaction.sync_account_later
+ redirect_back_or_to account_url(@transaction.account), notice: t(".success")
+ end
+
+ private
+
+ def set_account
+ @account = Current.family.accounts.find(params[:account_id])
+ end
+
+ def set_transaction
+ @transaction = @account.transactions.find(params[:id])
+ end
+
+ def search_params
+ params.fetch(:q, {}).permit(:start_date, :end_date, :search, accounts: [], account_ids: [], categories: [], merchants: [])
+ end
+
+ def transaction_params
+ params.require(:transaction).permit(:name, :date, :amount, :currency, :notes, :excluded, :category_id, :merchant_id, tag_ids: [])
+ end
+end
diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb
index 5b8c5eed..42cdd1f2 100644
--- a/app/controllers/pages_controller.rb
+++ b/app/controllers/pages_controller.rb
@@ -21,7 +21,7 @@ class PagesController < ApplicationController
@accounts = Current.family.accounts
@account_groups = @accounts.by_group(period: @period, currency: Current.family.currency)
- @transactions = Current.family.transactions.limit(5).order(date: :desc)
+ @transactions = Current.family.transactions.limit(6).order(date: :desc)
# TODO: Placeholders for trendlines
placeholder_series_data = 10.times.map do |i|
diff --git a/app/controllers/transaction/rules_controller.rb b/app/controllers/transaction/rules_controller.rb
deleted file mode 100644
index 7c7b157a..00000000
--- a/app/controllers/transaction/rules_controller.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-class Transaction::RulesController < ApplicationController
- layout "with_sidebar"
-
- def index
- end
-end
diff --git a/app/controllers/transactions_controller.rb b/app/controllers/transactions_controller.rb
index 98be1c39..ed38b535 100644
--- a/app/controllers/transactions_controller.rb
+++ b/app/controllers/transactions_controller.rb
@@ -1,8 +1,6 @@
class TransactionsController < ApplicationController
layout "with_sidebar"
- before_action :set_transaction, only: %i[ show edit update destroy ]
-
def index
@q = search_params
result = Current.family.transactions.search(@q).ordered
@@ -15,41 +13,22 @@ class TransactionsController < ApplicationController
}
end
- def show
- end
-
def new
- @transaction = Transaction.new.tap do |txn|
+ @transaction = Account::Transaction.new.tap do |txn|
if params[:account_id]
txn.account = Current.family.accounts.find(params[:account_id])
end
end
end
- def edit
- end
-
def create
@transaction = Current.family.accounts
- .find(params[:transaction][:account_id])
- .transactions.build(transaction_params.merge(amount: amount))
-
- @transaction.save!
- @transaction.sync_account_later
- redirect_to transactions_url, notice: t(".success")
- end
+ .find(params[:transaction][:account_id])
+ .transactions
+ .create!(transaction_params.merge(amount: amount))
- def update
- @transaction.update! transaction_params
@transaction.sync_account_later
-
- redirect_to transaction_url(@transaction), notice: t(".success")
- end
-
- def destroy
- @transaction.destroy!
- @transaction.sync_account_later
- redirect_to transactions_url, notice: t(".success")
+ redirect_back_or_to account_path(@transaction.account), notice: t(".success")
end
def bulk_delete
@@ -90,10 +69,6 @@ class TransactionsController < ApplicationController
private
- def set_transaction
- @transaction = Current.family.transactions.find(params[:id])
- end
-
def amount
if nature.income?
transaction_params[:amount].to_d * -1
@@ -119,6 +94,6 @@ class TransactionsController < ApplicationController
end
def transaction_params
- params.require(:transaction).permit(:name, :date, :amount, :currency, :notes, :excluded, :category_id, :merchant_id, tag_ids: [])
+ params.require(:transaction).permit(:name, :date, :amount, :currency, :category_id, tag_ids: [])
end
end
diff --git a/app/helpers/transactions/searches_helper.rb b/app/helpers/account/transaction/searches_helper.rb
similarity index 96%
rename from app/helpers/transactions/searches_helper.rb
rename to app/helpers/account/transaction/searches_helper.rb
index 09bd882a..09d3e0dc 100644
--- a/app/helpers/transactions/searches_helper.rb
+++ b/app/helpers/account/transaction/searches_helper.rb
@@ -1,4 +1,4 @@
-module Transactions::SearchesHelper
+module Account::Transaction::SearchesHelper
def transaction_search_filters
[
{ key: "account_filter", name: "Account", icon: "layers" },
diff --git a/app/helpers/transactions_helper.rb b/app/helpers/account/transactions_helper.rb
similarity index 57%
rename from app/helpers/transactions_helper.rb
rename to app/helpers/account/transactions_helper.rb
index 67758978..bc888360 100644
--- a/app/helpers/transactions_helper.rb
+++ b/app/helpers/account/transactions_helper.rb
@@ -1,23 +1,4 @@
-module TransactionsHelper
- def transactions_group(date, transactions, transaction_partial_path = "transactions/transaction")
- header_left = content_tag :span do
- "#{date.strftime('%b %d, %Y')} · #{transactions.size}".html_safe
- end
-
- header_right = content_tag :span do
- format_money(-transactions.sum(&:amount_money))
- end
-
- header = header_left.concat(header_right)
-
- content = render partial: transaction_partial_path, collection: transactions
-
- render partial: "shared/list_group", locals: {
- header: header,
- content: content
- }
- end
-
+module Account::TransactionsHelper
def unconfirmed_transfer?(transaction)
transaction.marked_as_transfer && transaction.transfer.nil?
end
diff --git a/app/helpers/account/valuations_helper.rb b/app/helpers/account/valuations_helper.rb
index e1a93dde..5143e43d 100644
--- a/app/helpers/account/valuations_helper.rb
+++ b/app/helpers/account/valuations_helper.rb
@@ -1,6 +1,6 @@
module Account::ValuationsHelper
def valuation_icon(valuation)
- if valuation.first_of_series?
+ if valuation.oldest?
"keyboard"
elsif valuation.trend.direction.up?
"arrow-up"
@@ -12,7 +12,7 @@ module Account::ValuationsHelper
end
def valuation_style(valuation)
- color = valuation.first_of_series? ? "#D444F1" : valuation.trend.color
+ color = valuation.oldest? ? "#D444F1" : valuation.trend.color
<<-STYLE.strip
background-color: color-mix(in srgb, #{color} 5%, white);
diff --git a/app/models/transaction.rb b/app/models/account/transaction.rb
similarity index 88%
rename from app/models/transaction.rb
rename to app/models/account/transaction.rb
index bad2aaf6..df4b4621 100644
--- a/app/models/transaction.rb
+++ b/app/models/account/transaction.rb
@@ -1,4 +1,4 @@
-class Transaction < ApplicationRecord
+class Account::Transaction < ApplicationRecord
include Monetizable
monetize :amount
@@ -17,22 +17,22 @@ class Transaction < ApplicationRecord
scope :active, -> { where(excluded: false) }
scope :inflows, -> { where("amount <= 0") }
scope :outflows, -> { where("amount > 0") }
- scope :by_name, ->(name) { where("transactions.name ILIKE ?", "%#{name}%") }
+ scope :by_name, ->(name) { where("account_transactions.name ILIKE ?", "%#{name}%") }
scope :with_categories, ->(categories) { joins(:category).where(categories: { name: categories }) }
scope :with_accounts, ->(accounts) { joins(:account).where(accounts: { name: accounts }) }
scope :with_account_ids, ->(account_ids) { joins(:account).where(accounts: { id: account_ids }) }
scope :with_merchants, ->(merchants) { joins(:merchant).where(merchants: { name: merchants }) }
- scope :on_or_after_date, ->(date) { where("transactions.date >= ?", date) }
- scope :on_or_before_date, ->(date) { where("transactions.date <= ?", date) }
+ scope :on_or_after_date, ->(date) { where("account_transactions.date >= ?", date) }
+ scope :on_or_before_date, ->(date) { where("account_transactions.date <= ?", date) }
scope :with_converted_amount, ->(currency = Current.family.currency) {
# Join with exchange rates to convert the amount to the given currency
# If no rate is available, exclude the transaction from the results
select(
- "transactions.*",
- "transactions.amount * COALESCE(er.rate, 1) AS converted_amount"
+ "account_transactions.*",
+ "account_transactions.amount * COALESCE(er.rate, 1) AS converted_amount"
)
- .joins(sanitize_sql_array([ "LEFT JOIN exchange_rates er ON transactions.date = er.date AND transactions.currency = er.base_currency AND er.converted_currency = ?", currency ]))
- .where("er.rate IS NOT NULL OR transactions.currency = ?", currency)
+ .joins(sanitize_sql_array([ "LEFT JOIN exchange_rates er ON account_transactions.date = er.date AND account_transactions.currency = er.base_currency AND er.converted_currency = ?", currency ]))
+ .where("er.rate IS NOT NULL OR account_transactions.currency = ?", currency)
}
def inflow?
diff --git a/app/models/account/valuation.rb b/app/models/account/valuation.rb
index ddbb519c..ffe21abe 100644
--- a/app/models/account/valuation.rb
+++ b/app/models/account/valuation.rb
@@ -15,14 +15,10 @@ class Account::Valuation < ApplicationRecord
@trend ||= create_trend
end
- def first_of_series?
+ def oldest?
account.valuations.chronological.limit(1).pluck(:date).first == self.date
end
- def last_of_series?
- account.valuations.reverse_chronological.limit(1).pluck(:date).first == self.date
- end
-
def sync_account_later
if destroyed?
sync_start_date = previous_valuation&.date
diff --git a/app/models/category.rb b/app/models/category.rb
index b846ca51..cfcab4ef 100644
--- a/app/models/category.rb
+++ b/app/models/category.rb
@@ -1,5 +1,5 @@
class Category < ApplicationRecord
- has_many :transactions, dependent: :nullify
+ has_many :transactions, dependent: :nullify, class_name: "Account::Transaction"
belongs_to :family
validates :name, :color, :family, presence: true
diff --git a/app/models/family.rb b/app/models/family.rb
index 1159fd87..378dd76e 100644
--- a/app/models/family.rb
+++ b/app/models/family.rb
@@ -3,7 +3,7 @@ class Family < ApplicationRecord
has_many :tags, dependent: :destroy
has_many :accounts, dependent: :destroy
has_many :institutions, dependent: :destroy
- has_many :transactions, through: :accounts
+ has_many :transactions, through: :accounts, class_name: "Account::Transaction"
has_many :imports, through: :accounts
has_many :categories, dependent: :destroy
has_many :merchants, dependent: :destroy
@@ -40,9 +40,9 @@ class Family < ApplicationRecord
"COALESCE(SUM(amount) FILTER (WHERE amount > 0), 0) AS spending",
"COALESCE(SUM(-amount) FILTER (WHERE amount < 0), 0) AS income"
)
- .where("transactions.date >= ?", period.date_range.begin)
- .where("transactions.date <= ?", period.date_range.end)
- .where("transactions.marked_as_transfer = ?", false)
+ .where("account_transactions.date >= ?", period.date_range.begin)
+ .where("account_transactions.date <= ?", period.date_range.end)
+ .where("account_transactions.marked_as_transfer = ?", false)
.group("id")
.to_a
@@ -60,7 +60,7 @@ class Family < ApplicationRecord
end
def snapshot_transactions
- rolling_totals = Transaction.daily_rolling_totals(transactions, period: Period.last_30_days, currency: self.currency)
+ rolling_totals = Account::Transaction.daily_rolling_totals(transactions, period: Period.last_30_days, currency: self.currency)
spending = []
income = []
diff --git a/app/models/merchant.rb b/app/models/merchant.rb
index 5e657763..3d1448e2 100644
--- a/app/models/merchant.rb
+++ b/app/models/merchant.rb
@@ -1,5 +1,5 @@
class Merchant < ApplicationRecord
- has_many :transactions, dependent: :nullify
+ has_many :transactions, dependent: :nullify, class_name: "Account::Transaction"
belongs_to :family
validates :name, :color, :family, presence: true
diff --git a/app/models/tag.rb b/app/models/tag.rb
index 6dd5988c..eab4d866 100644
--- a/app/models/tag.rb
+++ b/app/models/tag.rb
@@ -1,7 +1,7 @@
class Tag < ApplicationRecord
belongs_to :family
has_many :taggings, dependent: :destroy
- has_many :transactions, through: :taggings, source: :taggable, source_type: "Transaction"
+ has_many :transactions, through: :taggings, source: :taggable, source_type: "Account::Transaction"
validates :name, presence: true, uniqueness: { scope: :family }
diff --git a/app/views/account/transaction/rows/show.html.erb b/app/views/account/transaction/rows/show.html.erb
new file mode 100644
index 00000000..473d8200
--- /dev/null
+++ b/app/views/account/transaction/rows/show.html.erb
@@ -0,0 +1 @@
+<%= render "account/transactions/transaction", transaction: @transaction %>
diff --git a/app/views/transaction/rules/index.html.erb b/app/views/account/transaction/rules/index.html.erb
similarity index 99%
rename from app/views/transaction/rules/index.html.erb
rename to app/views/account/transaction/rules/index.html.erb
index 6e3162a7..62222550 100644
--- a/app/views/transaction/rules/index.html.erb
+++ b/app/views/account/transaction/rules/index.html.erb
@@ -1,6 +1,7 @@
<% content_for :sidebar do %>
<%= render "settings/nav" %>
<% end %>
+
<div class="space-y-4">
<h1 class="text-gray-900 text-xl font-medium mb-4">Rules</h1>
<div class="bg-white shadow-xs border border-alpha-black-25 rounded-xl p-4">
diff --git a/app/views/transactions/_empty.html.erb b/app/views/account/transactions/_empty.html.erb
similarity index 100%
rename from app/views/transactions/_empty.html.erb
rename to app/views/account/transactions/_empty.html.erb
diff --git a/app/views/account/transactions/_loading.html.erb b/app/views/account/transactions/_loading.html.erb
new file mode 100644
index 00000000..4f49ca61
--- /dev/null
+++ b/app/views/account/transactions/_loading.html.erb
@@ -0,0 +1,5 @@
+<div class="bg-white space-y-4 p-5 border border-alpha-black-25 rounded-xl shadow-xs">
+ <div class="p-5 flex justify-center items-center">
+ <%= tag.p t(".loading"), class: "text-gray-500 animate-pulse text-sm" %>
+ </div>
+</div>
diff --git a/app/views/transactions/_selection_bar.html.erb b/app/views/account/transactions/_selection_bar.html.erb
similarity index 93%
rename from app/views/transactions/_selection_bar.html.erb
rename to app/views/account/transactions/_selection_bar.html.erb
index 3def43bb..50655998 100644
--- a/app/views/transactions/_selection_bar.html.erb
+++ b/app/views/account/transactions/_selection_bar.html.erb
@@ -12,6 +12,7 @@
builder: ActionView::Helpers::FormBuilder,
scope: "bulk_update",
data: {
+ turbo_frame: "_top",
turbo_confirm: {
title: t(".mark_transfers"),
body: t(".mark_transfers_message"),
@@ -30,7 +31,7 @@
<%= lucide_icon "pencil-line", class: "w-5 group-hover:text-white" %>
<% end %>
- <%= form_with url: bulk_delete_transactions_path, builder: ActionView::Helpers::FormBuilder, data: { turbo_confirm: true } do %>
+ <%= form_with url: bulk_delete_transactions_path, builder: ActionView::Helpers::FormBuilder, 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/account/transactions/_transaction.html.erb
new file mode 100644
index 00000000..8d341a18
--- /dev/null
+++ b/app/views/account/transactions/_transaction.html.erb
@@ -0,0 +1,89 @@
+<%# locals: (transaction:, selectable: true, editable: true, short: false, show_tags: false) %>
+<%= turbo_frame_tag dom_id(transaction), class: "grid grid-cols-12 items-center text-gray-900 text-sm font-medium p-4" do %>
+
+ <% name_col_span = transaction.transfer? ? "col-span-10" : short ? "col-span-6" : "col-span-4" %>
+ <div class="pr-10 flex items-center gap-4 <%= name_col_span %>">
+ <% if selectable %>
+ <%= check_box_tag dom_id(transaction, "selection"),
+ class: "maybe-checkbox maybe-checkbox--light",
+ data: { id: transaction.id, "bulk-select-target": "row", action: "bulk-select#toggleRowSelection" } %>
+ <% end %>
+
+ <div class="max-w-full">
+ <%= content_tag :div, class: ["flex items-center gap-2"] do %>
+ <div class="flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-gray-600/5 text-gray-600">
+ <%= transaction.name[0].upcase %>
+ </div>
+
+ <div class="truncate text-gray-900">
+ <% if transaction.new_record? %>
+ <%= content_tag :p, transaction.name %>
+ <% else %>
+ <%= link_to transaction.name,
+ account_transaction_path(transaction.account, transaction),
+ data: { turbo_frame: "drawer", turbo_prefetch: false },
+ class: "hover:underline hover:text-gray-800" %>
+ <% end %>
+ </div>
+ <% end %>
+ </div>
+
+ <% if unconfirmed_transfer?(transaction) %>
+ <% if editable %>
+ <%= form_with url: unmark_transfers_transactions_path, builder: ActionView::Helpers::FormBuilder, class: "flex items-center", data: {
+ turbo_confirm: {
+ title: t(".remove_transfer"),
+ body: t(".remove_transfer_body"),
+ accept: t(".remove_transfer_confirm"),
+ },
+ turbo_frame: "_top"
+ } do |f| %>
+ <%= f.hidden_field "bulk_update[transaction_ids][]", value: transaction.id %>
+ <%= f.button class: "flex items-center justify-center group", title: "Remove transfer" do %>
+ <%= lucide_icon "arrow-left-right", class: "group-hover:hidden text-gray-500 w-4 h-4" %>
+ <%= lucide_icon "unlink", class: "hidden group-hover:inline-block text-gray-900 w-4 h-4" %>
+ <% end %>
+ <% end %>
+ <% else %>
+ <%= lucide_icon "arrow-left-right", class: "text-gray-500 w-4 h-4" %>
+ <% end %>
+ <% end %>
+ </div>
+
+ <% unless transaction.transfer? %>
+ <% unless short %>
+ <div class="flex items-center gap-1 <%= show_tags ? "col-span-6" : "col-span-3" %>">
+ <% if editable %>
+ <%= render "categories/menu", transaction: transaction %>
+ <% else %>
+ <%= render "categories/badge", category: transaction.category %>
+ <% end %>
+
+ <% if show_tags %>
+ <% transaction.tags.each do |tag| %>
+ <%= render partial: "tags/badge", locals: { tag: tag } %>
+ <% end %>
+ <% end %>
+ </div>
+ <% end %>
+
+ <% unless show_tags %>
+ <%= tag.div class: short ? "col-span-4" : "col-span-3" do %>
+ <% if transaction.new_record? %>
+ <%= tag.p transaction.account.name %>
+ <% else %>
+ <%= link_to transaction.account.name,
+ account_path(transaction.account, tab: "transactions"),
+ data: { turbo_frame: "_top" },
+ class: "hover:underline" %>
+ <% end %>
+ <% end %>
+ <% end %>
+ <% end %>
+
+ <div class="col-span-2 ml-auto">
+ <%= content_tag :p,
+ format_money(-transaction.amount_money),
+ class: ["text-green-600": transaction.inflow?] %>
+ </div>
+<% end %>
diff --git a/app/views/account/transactions/_transaction_group.html.erb b/app/views/account/transactions/_transaction_group.html.erb
new file mode 100644
index 00000000..54ab5520
--- /dev/null
+++ b/app/views/account/transactions/_transaction_group.html.erb
@@ -0,0 +1,21 @@
+<%# locals: (date:, transactions:, transfers: [], selectable: true, **transaction_opts) %>
+<div id="date-group-<%= date %>" class="bg-gray-25 rounded-xl p-1 w-full" data-bulk-select-target="group">
+ <div class="py-2 px-4 flex items-center justify-between font-medium text-xs text-gray-500">
+ <div class="flex pl-0.5 items-center gap-4">
+ <% if selectable %>
+ <%= check_box_tag "#{date}_transactions_selection",
+ class: ["maybe-checkbox maybe-checkbox--light", "hidden": transactions.count == 0],
+ id: "selection_transaction_#{date}",
+ data: { action: "bulk-select#toggleGroupSelection" } %>
+ <% end %>
+
+ <%= tag.span "#{date.strftime('%b %d, %Y')} · #{transactions.size + (transfers.size * 2)}" %>
+ </div>
+
+ <%= totals_by_currency(collection: transactions, money_method: :amount_money, negate: true) %>
+ </div>
+ <div class="bg-white shadow-xs rounded-md border border-alpha-black-25 divide-y divide-alpha-black-50">
+ <%= render transactions, selectable:, **transaction_opts.except(:selectable) %>
+ <%= render transfers %>
+ </div>
+</div>
diff --git a/app/views/account/transactions/index.html.erb b/app/views/account/transactions/index.html.erb
new file mode 100644
index 00000000..371a6bc4
--- /dev/null
+++ b/app/views/account/transactions/index.html.erb
@@ -0,0 +1,29 @@
+<%= turbo_frame_tag dom_id(@account, "transactions") do %>
+ <div class="bg-white space-y-4 p-5 border border-alpha-black-25 rounded-xl shadow-xs">
+ <div class="flex justify-between items-center">
+ <h3 class="font-medium text-lg"><%= t(".transactions") %></h3>
+ <%= link_to new_transaction_path(account_id: @account),
+ class: "flex gap-1 font-medium items-center bg-gray-50 text-gray-900 p-2 rounded-lg",
+ data: { turbo_frame: :modal } do %>
+ <%= lucide_icon("plus", class: "w-5 h-5 text-gray-900") %>
+ <span class="text-sm"><%= t(".new") %></span>
+ <% end %>
+ </div>
+
+ <div id="transactions" data-controller="bulk-select" data-bulk-select-resource-value="<%= t(".transaction") %>">
+ <div hidden id="transaction-selection-bar" data-bulk-select-target="selectionBar">
+ <%= render "account/transactions/selection_bar" %>
+ </div>
+
+ <% if @transactions.empty? %>
+ <p class="text-gray-500 py-4"><%= t(".no_transactions") %></p>
+ <% else %>
+ <div class="space-y-6">
+ <% group_transactions_by_date(@transactions).each do |date, group| %>
+ <%= render "transaction_group", date:, transactions: group[:transactions], transfers: group[:transfers] %>
+ <% end %>
+ </div>
+ <% end %>
+ </div>
+ </div>
+<% end %>
diff --git a/app/views/transactions/show.html.erb b/app/views/account/transactions/show.html.erb
similarity index 98%
rename from app/views/transactions/show.html.erb
rename to app/views/account/transactions/show.html.erb
index e83e4c59..b2c48555 100644
--- a/app/views/transactions/show.html.erb
+++ b/app/views/account/transactions/show.html.erb
@@ -90,7 +90,7 @@
</div>
<%= button_to t(".delete"),
- transaction_path(@transaction),
+ account_transaction_path(@transaction),
method: :delete,
class: "rounded-lg px-3 py-2 text-red-500 text-sm font-medium border border-alpha-black-200",
data: { turbo_confirm: true, turbo_frame: "_top" } %>
diff --git a/app/views/account/transfers/_transfer.html.erb b/app/views/account/transfers/_transfer.html.erb
index eeec6868..3a04b3f5 100644
--- a/app/views/account/transfers/_transfer.html.erb
+++ b/app/views/account/transfers/_transfer.html.erb
@@ -1,6 +1,6 @@
<%= turbo_frame_tag dom_id(transfer), class: "block" do %>
- <details class="group flex items-center text-gray-900 p-4 text-sm font-medium">
- <summary class="flex items-center justify-between">
+ <details class="group flex items-center text-gray-900 text-sm font-medium">
+ <summary class="flex items-center justify-between p-4">
<div class="flex items-center gap-4">
<%= button_to account_transfer_path(transfer),
method: :delete,
@@ -25,16 +25,9 @@
<%= lucide_icon "chevron-down", class: "group-open:transform group-open:rotate-180 text-gray-500 w-5" %>
</summary>
- <div class="pt-2 divide-y divide-alpha-black-200">
+ <div class="divide-y divide-alpha-black-200">
<% transfer.transactions.each do |transaction| %>
- <div class="py-3 grid grid-cols-12 items-center">
- <div class="col-span-10">
- <%= render "transactions/name", transaction: transaction %>
- </div>
- <div class="col-span-2 ml-auto">
- <%= render "transactions/amount", transaction: transaction %>
- </div>
- </div>
+ <%= render transaction, selectable: false, editable: false %>
<% end %>
</div>
</details>
diff --git a/app/views/account/valuations/_loading.html.erb b/app/views/account/valuations/_loading.html.erb
new file mode 100644
index 00000000..4f49ca61
--- /dev/null
+++ b/app/views/account/valuations/_loading.html.erb
@@ -0,0 +1,5 @@
+<div class="bg-white space-y-4 p-5 border border-alpha-black-25 rounded-xl shadow-xs">
+ <div class="p-5 flex justify-center items-center">
+ <%= tag.p t(".loading"), class: "text-gray-500 animate-pulse text-sm" %>
+ </div>
+</div>
diff --git a/app/views/account/valuations/_valuation.html.erb b/app/views/account/valuations/_valuation.html.erb
index 2d496e98..7fa0021d 100644
--- a/app/views/account/valuations/_valuation.html.erb
+++ b/app/views/account/valuations/_valuation.html.erb
@@ -1,5 +1,3 @@
-<%# locals: (valuation:) %>
-
<%= turbo_frame_tag dom_id(valuation) do %>
<div class="p-4 grid grid-cols-10 items-center">
<div class="col-span-5 flex items-center gap-4">
@@ -9,7 +7,7 @@
<div class="text-sm">
<%= tag.p valuation.date, class: "text-gray-900 font-medium" %>
- <%= tag.p valuation.first_of_series? ? t(".start_balance") : t(".value_update"), class: "text-gray-500" %>
+ <%= tag.p valuation.oldest? ? t(".start_balance") : t(".value_update"), class: "text-gray-500" %>
</div>
</div>
@@ -43,8 +41,4 @@
<% end %>
</div>
</div>
-
- <% unless valuation.last_of_series? %>
- <div class="h-px bg-alpha-black-50 ml-16 mr-4"></div>
- <% end %>
<% end %>
diff --git a/app/views/account/valuations/_valuation_ruler.html.erb b/app/views/account/valuations/_valuation_ruler.html.erb
new file mode 100644
index 00000000..31c6ee6c
--- /dev/null
+++ b/app/views/account/valuations/_valuation_ruler.html.erb
@@ -0,0 +1 @@
+<div class="h-px bg-alpha-black-50 ml-16 mr-4"></div>
diff --git a/app/views/account/valuations/index.html.erb b/app/views/account/valuations/index.html.erb
index 4fa523bb..e4062d9f 100644
--- a/app/views/account/valuations/index.html.erb
+++ b/app/views/account/valuations/index.html.erb
@@ -1,15 +1,35 @@
<%= turbo_frame_tag dom_id(@account, "valuations") do %>
- <div class="grid grid-cols-10 items-center uppercase text-xs font-medium text-gray-500 px-4 py-2">
- <%= tag.p t(".date"), class: "col-span-5" %>
- <%= tag.p t(".value"), class: "col-span-2 justify-self-end" %>
- <%= tag.p t(".change"), class: "col-span-2 justify-self-end" %>
- <%= tag.div class: "col-span-1" %>
- </div>
+ <div class="bg-white space-y-4 p-5 border border-alpha-black-25 rounded-xl shadow-xs">
+ <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::Valuation.new) },
+ class: "flex gap-1 font-medium items-center bg-gray-50 text-gray-900 p-2 rounded-lg" do %>
+ <%= lucide_icon("plus", class: "w-5 h-5 text-gray-900") %>
+ <%= tag.span t(".new_entry"), class: "text-sm" %>
+ <% end %>
+ </div>
+
+ <div class="rounded-xl bg-gray-25 p-1">
+ <div class="grid grid-cols-10 items-center uppercase text-xs font-medium text-gray-500 px-4 py-2">
+ <%= tag.p t(".date"), class: "col-span-5" %>
+ <%= tag.p t(".value"), class: "col-span-2 justify-self-end" %>
+ <%= tag.p t(".change"), class: "col-span-2 justify-self-end" %>
+ <%= tag.div class: "col-span-1" %>
+ </div>
+
+ <div class="rounded-lg bg-white border-alpha-black-25 shadow-xs">
+ <%= turbo_frame_tag dom_id(Account::Valuation.new) %>
- <div class="rounded-lg bg-white border-alpha-black-25 shadow-xs">
- <%= turbo_frame_tag dom_id(Account::Valuation.new) %>
- <% @account.valuations.reverse_chronological.each do |valuation| %>
- <%= render valuation %>
- <% end %>
+ <% valuations = @account.valuations.reverse_chronological %>
+ <% if valuations.any? %>
+ <%= render partial: "valuation",
+ collection: @account.valuations.reverse_chronological,
+ spacer_template: "valuation_ruler" %>
+ <% else %>
+ <p class="text-gray-500 text-sm p-4"><%= t(".no_valuations") %></p>
+ <% end %>
+ </div>
+ </div>
</div>
<% end %>
diff --git a/app/views/accounts/_transactions.html.erb b/app/views/accounts/_transactions.html.erb
deleted file mode 100644
index 4f90c021..00000000
--- a/app/views/accounts/_transactions.html.erb
+++ /dev/null
@@ -1,20 +0,0 @@
-<%# locals: (account:, transactions:)%>
-<div class="bg-white space-y-4 p-5 border border-alpha-black-25 rounded-xl shadow-xs">
- <div class="flex justify-between items-center">
- <h3 class="font-medium text-lg">Transactions</h3>
- <%= link_to new_transaction_path(account_id: account), class: "flex gap-1 font-medium items-center bg-gray-50 text-gray-900 p-2 rounded-lg", data: { turbo_frame: :modal } do %>
- <%= lucide_icon("plus", class: "w-5 h-5 text-gray-900") %>
- <span class="text-sm">New transaction</span>
- <% end %>
- </div>
-
- <% if transactions.empty? %>
- <p class="text-gray-500 py-4">No transactions for this account yet.</p>
- <% else %>
- <div class="space-y-6">
- <% transactions.group_by(&:date).each do |date, transactions| %>
- <%= transactions_group(date, transactions, "accounts/transactions/transaction") %>
- <% end %>
- </div>
- <% end %>
-</div>
diff --git a/app/views/accounts/show.html.erb b/app/views/accounts/show.html.erb
index 38c76f6f..58d31cfd 100644
--- a/app/views/accounts/show.html.erb
+++ b/app/views/accounts/show.html.erb
@@ -1,4 +1,5 @@
<%= turbo_stream_from @account %>
+
<div class="space-y-4">
<div class="flex justify-between items-center">
<div class="flex items-center gap-3">
@@ -70,34 +71,23 @@
<%= render partial: "shared/line_chart", locals: { series: @balance_series } %>
</div>
</div>
- <div data-controller="tabs" data-tabs-active-class="bg-gray-100" data-tabs-default-tab-value="account-history-tab">
- <div class="flex gap-1 text-sm text-gray-900 font-medium mb-4">
- <button data-id="account-history-tab" class="p-2 rounded-lg" data-tabs-target="btn" data-action="click->tabs#select">History</button>
- <button data-id="account-transactions-tab" class="p-2 rounded-lg" data-tabs-target="btn" data-action="click->tabs#select">Transactions</button>
- </div>
- <div class="min-h-[800px]">
- <div data-tabs-target="tab" id="account-history-tab">
- <div class="bg-white space-y-4 p-5 border border-alpha-black-25 rounded-xl shadow-xs">
- <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::Valuation.new) }, class: "flex gap-1 font-medium items-center bg-gray-50 text-gray-900 p-2 rounded-lg" do %>
- <%= lucide_icon("plus", class: "w-5 h-5 text-gray-900") %>
- <%= tag.span t(".new_entry"), class: "text-sm" %>
- <% end %>
- </div>
- <div class="rounded-xl bg-gray-25 p-1">
- <%= turbo_frame_tag dom_id(@account, "valuations"), src: account_valuations_path(@account) do %>
- <div class="p-5 flex justify-center items-center">
- <%= tag.p t(".loading_history"), class: "text-gray-500 animate-pulse text-sm" %>
- </div>
- <% end %>
- </div>
- </div>
- </div>
- <div data-tabs-target="tab" id="account-transactions-tab" class="hidden">
- <%= render partial: "accounts/transactions", locals: { account: @account, transactions: @account.transactions.order(date: :desc) } %>
- </div>
- </div>
+ <% selected_tab = params[:tab] || "history" %>
+
+ <div class="flex gap-1 text-sm text-gray-900 font-medium mb-4">
+ <%= link_to "History", account_path(tab: "history"), class: ["p-2 rounded-lg", "bg-gray-100": selected_tab == "history"] %>
+ <%= link_to "Transactions", account_path(tab: "transactions"), class: ["p-2 rounded-lg", "bg-gray-100": selected_tab == "transactions"] %>
+ </div>
+
+ <div class="min-h-[800px]">
+ <% if selected_tab == "transactions" %>
+ <%= turbo_frame_tag dom_id(@account, "transactions"), src: account_transactions_path(@account) do %>
+ <%= render "account/transactions/loading" %>
+ <% end %>
+ <% else %>
+ <%= turbo_frame_tag dom_id(@account, "valuations"), src: account_valuations_path(@account) do %>
+ <%= render "account/valuations/loading" %>
+ <% end %>
+ <% end %>
</div>
</div>
diff --git a/app/views/accounts/transactions/_transaction.html.erb b/app/views/accounts/transactions/_transaction.html.erb
deleted file mode 100644
index e725c818..00000000
--- a/app/views/accounts/transactions/_transaction.html.erb
+++ /dev/null
@@ -1,24 +0,0 @@
-<%= turbo_frame_tag dom_id(transaction), class: "grid grid-cols-12 items-center text-gray-900 py-4 text-sm font-medium px-4" do %>
- <div class="col-span-4">
- <%= render "transactions/name", transaction: transaction %>
- </div>
-
- <div class="col-span-3">
- <% if transaction.marked_as_transfer %>
- <div class="flex items-center gap-1 text-gray-500 pl-5">
- <%= lucide_icon "arrow-right-left", class: "w-4 h-4 text-gray-500" %>
- <p>Transfer</p>
- </div>
- <% else %>
- <%= render "categories/badge", category: transaction.category %>
- <% end %>
- </div>
-
- <%= link_to transaction.account.name,
- account_path(transaction.account),
- class: ["col-span-3 hover:underline"] %>
-
- <div class="col-span-2 ml-auto">
- <%= render "transactions/amount", transaction: transaction %>
- </div>
-<% end %>
diff --git a/app/views/category/dropdowns/_row.html.erb b/app/views/category/dropdowns/_row.html.erb
index 44d47fef..bca65ceb 100644
--- a/app/views/category/dropdowns/_row.html.erb
+++ b/app/views/category/dropdowns/_row.html.erb
@@ -2,7 +2,7 @@
<% is_selected = category.id === @selected_category&.id %>
<%= content_tag :div, class: ["filterable-item flex justify-between items-center border-none rounded-lg px-2 py-1 group w-full", { "bg-gray-25": is_selected }], data: { filter_name: category.name } do %>
- <%= button_to transaction_row_path(@transaction, transaction: { category_id: category.id }), method: :patch, data: { turbo_frame: dom_id(@transaction) }, class: "flex w-full items-center gap-1.5 cursor-pointer" do %>
+ <%= button_to account_transaction_row_path(@transaction.account, @transaction, transaction: { category_id: category.id }), method: :patch, data: { turbo_frame: dom_id(@transaction) }, class: "flex w-full items-center gap-1.5 cursor-pointer" do %>
<span class="w-5 h-5">
<%= lucide_icon("check", class: "w-5 h-5 text-gray-500") if is_selected %>
</span>
diff --git a/app/views/category/dropdowns/show.html.erb b/app/views/category/dropdowns/show.html.erb
index 0ddfd1ec..fd966334 100644
--- a/app/views/category/dropdowns/show.html.erb
+++ b/app/views/category/dropdowns/show.html.erb
@@ -25,7 +25,7 @@
<% end %>
<% if @transaction.category %>
- <%= button_to transaction_row_path(@transaction),
+ <%= button_to account_transaction_row_path(@transaction.account, @transaction),
method: :patch,
data: { turbo_frame: dom_id(@transaction) },
params: { transaction: { category_id: nil } },
diff --git a/app/views/imports/confirm.html.erb b/app/views/imports/confirm.html.erb
index 32694dff..cc47b42b 100644
--- a/app/views/imports/confirm.html.erb
+++ b/app/views/imports/confirm.html.erb
@@ -9,8 +9,15 @@
</div>
<div class="mb-8 space-y-4">
- <% @import.dry_run.group_by(&:date).each do |date, draft_transactions| %>
- <%= transactions_group(date, draft_transactions, "imports/transactions/transaction") %>
+ <% transactions = @import.dry_run %>
+ <% group_transactions_by_date(transactions).each do |date, group| %>
+ <%= render "account/transactions/transaction_group",
+ date: date,
+ transactions: group[:transactions],
+ transfers: group[:transfers],
+ show_tags: true,
+ selectable: false,
+ editable: false %>
<% end %>
</div>
diff --git a/app/views/imports/index.html.erb b/app/views/imports/index.html.erb
index 3406f8c2..8f0435dc 100644
--- a/app/views/imports/index.html.erb
+++ b/app/views/imports/index.html.erb
@@ -25,7 +25,7 @@
<% end %>
</div>
<div class="flex justify-between gap-4">
- <%= previous_setting("Rules", transaction_rules_path) %>
+ <%= previous_setting("Rules", account_transaction_rules_path) %>
<%= next_setting("What's new", changelog_path) %>
</div>
</div>
diff --git a/app/views/imports/transactions/_transaction.html.erb b/app/views/imports/transactions/_transaction.html.erb
deleted file mode 100644
index d3594222..00000000
--- a/app/views/imports/transactions/_transaction.html.erb
+++ /dev/null
@@ -1,20 +0,0 @@
-<%# locals: (transaction:) %>
-<div class="text-gray-900 grid grid-cols-8 items-center py-4 text-sm font-medium px-4">
- <div class="col-span-3">
- <%= render "transactions/name", transaction: transaction %>
- </div>
-
- <div class="col-span-2">
- <%= render partial: "categories/badge", locals: { category: transaction.category } %>
- </div>
-
- <div class="col-span-2 flex items-center gap-1">
- <% transaction.tags.each do |tag| %>
- <%= render partial: "tags/badge", locals: { tag: tag } %>
- <% end %>
- </div>
-
- <div class="col-span-1 justify-self-end">
- <%= render "transactions/amount", transaction: transaction %>
- </div>
-</div>
diff --git a/app/views/merchants/index.html.erb b/app/views/merchants/index.html.erb
index 0629c818..8e3eca22 100644
--- a/app/views/merchants/index.html.erb
+++ b/app/views/merchants/index.html.erb
@@ -35,6 +35,6 @@
</div>
<div class="flex justify-between gap-4">
<%= previous_setting("Categories", categories_path) %>
- <%= next_setting("Rules", transaction_rules_path) %>
+ <%= next_setting("Rules", account_transaction_rules_path) %>
</div>
</div>
diff --git a/app/views/pages/dashboard.html.erb b/app/views/pages/dashboard.html.erb
index 9296f5f8..5909d1fb 100644
--- a/app/views/pages/dashboard.html.erb
+++ b/app/views/pages/dashboard.html.erb
@@ -3,7 +3,7 @@
<div>
<h1 class="sr-only">Dashboard</h1>
<p class="text-xl font-medium text-gray-900 mb-1"><%= t(".greeting", name: Current.user.first_name ) %></p>
- <% if [email protected]? %>
+ <% unless @accounts.blank? %>
<p class="text-gray-500 text-sm"><%= t(".subtitle") %></p>
<% end %>
</div>
@@ -162,8 +162,14 @@
</div>
<% else %>
<div class="text-gray-500 p-1 space-y-1 bg-gray-25 rounded-xl">
- <% @transactions.group_by(&:date).each do |date, transactions| %>
- <%= transactions_group(date, transactions, "pages/dashboard/transactions/transaction") %>
+ <% group_transactions_by_date(@transactions).each do |date, group| %>
+ <%= render "account/transactions/transaction_group",
+ date: date,
+ transactions: group[:transactions],
+ transfers: group[:transfers],
+ selectable: false,
+ editable: false,
+ short: true %>
<% end %>
<p class="py-2 text-sm text-center"><%= link_to t(".view_all"), transactions_path %></p>
diff --git a/app/views/pages/dashboard/transactions/_transaction.html.erb b/app/views/pages/dashboard/transactions/_transaction.html.erb
deleted file mode 100644
index 49fc3be3..00000000
--- a/app/views/pages/dashboard/transactions/_transaction.html.erb
+++ /dev/null
@@ -1,9 +0,0 @@
-<div class="text-gray-900 flex items-center py-4 text-sm font-medium px-4">
- <div class="grow max-w-72">
- <%= render "transactions/name", transaction: transaction %>
- </div>
-
- <div class="ml-auto">
- <%= render "transactions/amount", transaction: transaction %>
- </div>
-</div>
diff --git a/app/views/settings/_nav.html.erb b/app/views/settings/_nav.html.erb
index cf0a8209..333ee3bc 100644
--- a/app/views/settings/_nav.html.erb
+++ b/app/views/settings/_nav.html.erb
@@ -56,7 +56,7 @@
<%= sidebar_link_to t(".merchants_label"), merchants_path, icon: "store" %>
</li>
<li>
- <%= sidebar_link_to t(".rules_label"), transaction_rules_path, icon: "list-checks" %>
+ <%= sidebar_link_to t(".rules_label"), account_transaction_rules_path, icon: "list-checks" %>
</li>
<li>
<%= sidebar_link_to t(".imports_label"), imports_path, icon: "download" %>
diff --git a/app/views/transaction/rows/show.html.erb b/app/views/transaction/rows/show.html.erb
deleted file mode 100644
index e40ab43e..00000000
--- a/app/views/transaction/rows/show.html.erb
+++ /dev/null
@@ -1 +0,0 @@
-<%= render "transactions/transaction", transaction: @transaction %>
diff --git a/app/views/transactions/_amount.html.erb b/app/views/transactions/_amount.html.erb
deleted file mode 100644
index 1ebf81ff..00000000
--- a/app/views/transactions/_amount.html.erb
+++ /dev/null
@@ -1,3 +0,0 @@
-<%= content_tag :p,
- format_money(-transaction.amount_money),
- class: ["text-green-600": transaction.inflow?] %>
diff --git a/app/views/transactions/_date_group.html.erb b/app/views/transactions/_date_group.html.erb
deleted file mode 100644
index a464cfc9..00000000
--- a/app/views/transactions/_date_group.html.erb
+++ /dev/null
@@ -1,21 +0,0 @@
-<%# locals: (date:, group:) %>
-<div id="date-group-<%= date %>" class="bg-gray-25 rounded-xl p-1 w-full" data-bulk-select-target="group">
- <div class="py-2 px-4 flex items-center justify-between font-medium text-xs text-gray-500">
- <div class="flex pl-0.5 items-center gap-4">
- <%= check_box_tag "#{date}_transactions_selection",
- class: ["maybe-checkbox maybe-checkbox--light", "hidden": group[:transactions].count == 0],
- id: "selection_transaction_#{date}",
- data: { action: "bulk-select#toggleGroupSelection" } %>
-
- <%= tag.span "#{date.strftime('%b %d, %Y')} · #{group[:transactions].size + (group[:transfers].size * 2)}" %>
- </div>
-
- <div>
- <%= totals_by_currency(collection: group[:transactions], money_method: :amount_money, negate: true) %>
- </div>
- </div>
- <div class="bg-white shadow-xs rounded-md border border-alpha-black-25 divide-y divide-alpha-black-50">
- <%= render group[:transactions] %>
- <%= render group[:transfers] %>
- </div>
-</div>
diff --git a/app/views/transactions/_form.html.erb b/app/views/transactions/_form.html.erb
index 575e9fc6..46f00a38 100644
--- a/app/views/transactions/_form.html.erb
+++ b/app/views/transactions/_form.html.erb
@@ -1,4 +1,4 @@
-<%= form_with model: @transaction, data: { turbo_frame: "_top" } do |f| %>
+<%= form_with model: @transaction, url: transactions_path, scope: "transaction", data: { turbo_frame: "_top" } do |f| %>
<section>
<fieldset class="bg-gray-50 rounded-lg p-1 grid grid-flow-col justify-stretch gap-x-2">
<%= radio_tab_tag form: f, name: :nature, value: :expense, label: t(".expense"), icon: "minus-circle", checked: params[:nature] == "expense" || params[:nature].nil? %>
diff --git a/app/views/transactions/_name.html.erb b/app/views/transactions/_name.html.erb
deleted file mode 100644
index 32891964..00000000
--- a/app/views/transactions/_name.html.erb
+++ /dev/null
@@ -1,16 +0,0 @@
-<%= content_tag :div, class: ["flex items-center gap-2"] do %>
- <div class="flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-gray-600/5 text-gray-600">
- <%= transaction.name[0].upcase %>
- </div>
-
- <div class="truncate text-gray-900">
- <% if transaction.new_record? %>
- <%= content_tag :p, transaction.name %>
- <% else %>
- <%= link_to transaction.name,
- transaction_path(transaction),
- data: { turbo_frame: "drawer", turbo_prefetch: false },
- class: "hover:underline hover:text-gray-800" %>
- <% end %>
- </div>
-<% end %>
diff --git a/app/views/transactions/_pagination.html.erb b/app/views/transactions/_pagination.html.erb
index a485ce71..ae481645 100644
--- a/app/views/transactions/_pagination.html.erb
+++ b/app/views/transactions/_pagination.html.erb
@@ -1,3 +1,4 @@
+<%# locals: (pagy:) %>
<nav class="flex items-center justify-between px-4 mt-4 sm:px-0 w-full">
<div class="flex">
<div>
@@ -38,7 +39,6 @@
<% end %>
</div>
</div>
- <% per_page = params[:per_page] || "50" %>
<div class="flex items-center gap-4">
<%= form_with url: transactions_path,
builder: ActionView::Helpers::FormBuilder,
diff --git a/app/views/transactions/_transaction.html.erb b/app/views/transactions/_transaction.html.erb
deleted file mode 100644
index 98f49c81..00000000
--- a/app/views/transactions/_transaction.html.erb
+++ /dev/null
@@ -1,43 +0,0 @@
-<%= turbo_frame_tag dom_id(transaction), class: "grid grid-cols-12 items-center text-gray-900 text-sm font-medium p-4" do %>
- <div class="pr-10 flex items-center gap-4 <%= unconfirmed_transfer?(transaction) ? "col-span-10" : "col-span-4" %>">
- <%= check_box_tag dom_id(transaction, "selection"),
- class: "maybe-checkbox maybe-checkbox--light",
- data: { id: transaction.id, "bulk-select-target": "row", action: "bulk-select#toggleRowSelection" } %>
-
- <div class="max-w-full">
- <%= render "transactions/name", transaction: transaction %>
- </div>
-
- <% if unconfirmed_transfer?(transaction) %>
- <%= form_with url: unmark_transfers_transactions_path, builder: ActionView::Helpers::FormBuilder, class: "flex items-center", data: {
- turbo_confirm: {
- title: t(".remove_transfer"),
- body: t(".remove_transfer_body"),
- accept: t(".remove_transfer_confirm"),
- },
- turbo_frame: "_top"
- } do |f| %>
- <%= f.hidden_field "bulk_update[transaction_ids][]", value: transaction.id %>
- <%= f.button class: "flex items-center justify-center group", title: "Remove transfer" do %>
- <%= lucide_icon "arrow-left-right", class: "group-hover:hidden text-gray-500 w-4 h-4" %>
- <%= lucide_icon "unlink", class: "hidden group-hover:inline-block text-gray-900 w-4 h-4" %>
- <% end %>
- <% end %>
- <% end %>
- </div>
-
- <% unless unconfirmed_transfer?(transaction) %>
- <div class="col-span-3">
- <%= render "categories/menu", transaction: transaction %>
- </div>
-
- <%= link_to transaction.account.name,
- account_path(transaction.account),
- data: { turbo_frame: "_top" },
- class: ["col-span-3 hover:underline"] %>
- <% end %>
-
- <div class="col-span-2 ml-auto">
- <%= render "transactions/amount", transaction: transaction %>
- </div>
-<% end %>
diff --git a/app/views/transactions/index.html.erb b/app/views/transactions/index.html.erb
index faf0f110..652f6366 100644
--- a/app/views/transactions/index.html.erb
+++ b/app/views/transactions/index.html.erb
@@ -1,17 +1,16 @@
<div class="space-y-4 h-full flex flex-col overflow-y-auto">
<%= render "header" %>
- <%= render partial: "transactions/summary", locals: { totals: @totals } %>
+ <%= render "summary", totals: @totals %>
<div id="transactions" data-controller="bulk-select" data-bulk-select-resource-value="<%= t(".transaction") %>" class="overflow-y-auto flex flex-col bg-white rounded-xl border border-alpha-black-25 shadow-xs pb-4">
-
<div class="p-4 pb-0">
<%= render partial: "transactions/searches/search", locals: { transactions: @transactions } %>
</div>
<% if @transactions.present? %>
<div hidden id="transaction-selection-bar" data-bulk-select-target="selectionBar">
- <%= render "selection_bar" %>
+ <%= render "account/transactions/selection_bar" %>
</div>
<div class="grow overflow-y-auto px-4">
<div class="grid grid-cols-12 bg-gray-25 rounded-xl px-5 py-3 text-xs uppercase font-medium text-gray-500 items-center mb-4">
@@ -27,13 +26,13 @@
<p class="col-span-2 justify-self-end">amount</p>
</div>
<div class="space-y-6">
- <% group_transactions_by_date(@transactions).each do |date, group| %>
- <%= render partial: "date_group", locals: { date:, group: } %>
- <% end %>
+ <% group_transactions_by_date(@transactions).each do |date, group| %>
+ <%= render "account/transactions/transaction_group", date:, transactions: group[:transactions], transfers: group[:transfers] %>
+ <% end %>
</div>
</div>
<% else %>
- <%= render "empty" %>
+ <%= render "account/transactions/empty" %>
<% end %>
<div class="px-4">
@@ -41,6 +40,5 @@
<%= render "pagination", pagy: @pagy %>
<% end %>
</div>
-
</div>
</div>
diff --git a/config/locales/views/account/transactions/en.yml b/config/locales/views/account/transactions/en.yml
new file mode 100644
index 00000000..560c831a
--- /dev/null
+++ b/config/locales/views/account/transactions/en.yml
@@ -0,0 +1,49 @@
+---
+en:
+ account:
+ transactions:
+ destroy:
+ success: Transaction deleted successfully
+ empty:
+ description: Try adding a transaction, editing filters or refining your search
+ title: No transactions found
+ index:
+ new: New transaction
+ no_transactions: No transactions for this account yet.
+ transaction: transaction
+ transactions: Transactions
+ loading:
+ loading: Loading transactions...
+ selection_bar:
+ mark_transfers: Mark as transfers?
+ mark_transfers_confirm: Mark as transfers
+ mark_transfers_message: By marking transactions as transfers, they will no
+ longer be included in income or spending calculations.
+ show:
+ account_label: Account
+ account_placeholder: Select an account
+ additional: Additional
+ category_label: Category
+ category_placeholder: Select a 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
+ exclude_subtitle: This excludes the transaction from any in-app features or
+ analytics.
+ exclude_title: Exclude transaction
+ merchant_label: Merchant
+ merchant_placeholder: Select a merchant
+ name_label: Name
+ note_label: Notes
+ note_placeholder: Enter a note
+ overview: Overview
+ settings: Settings
+ tags_label: Select one or more tags
+ transaction:
+ remove_transfer: Remove transfer
+ remove_transfer_body: This will remove the transfer from this transaction
+ remove_transfer_confirm: Confirm
+ update:
+ success: Transaction updated successfully
diff --git a/config/locales/views/account/valuations/en.yml b/config/locales/views/account/valuations/en.yml
index 98713c98..a8533305 100644
--- a/config/locales/views/account/valuations/en.yml
+++ b/config/locales/views/account/valuations/en.yml
@@ -9,7 +9,12 @@ en:
index:
change: change
date: date
+ new_entry: New entry
+ no_valuations: No valuations for this account yet
+ valuations: Value history
value: value
+ loading:
+ loading: Loading history...
update:
success: Valuation updated
valuation:
diff --git a/config/locales/views/accounts/en.yml b/config/locales/views/accounts/en.yml
index 51b048e2..65c63348 100644
--- a/config/locales/views/accounts/en.yml
+++ b/config/locales/views/accounts/en.yml
@@ -58,12 +58,9 @@ en:
confirm_title: Delete account?
edit: Edit
import: Import transactions
- loading_history: Loading account history...
- new_entry: New entry
sync_message_missing_rates: Since exchange rates haven't been synced, balance
graphs may not reflect accurate values.
sync_message_unknown_error: An error has occurred during the sync.
- valuations: Value history
summary:
new: New account
sync:
diff --git a/config/locales/views/transactions/en.yml b/config/locales/views/transactions/en.yml
index 6d485f48..d6286a0d 100644
--- a/config/locales/views/transactions/en.yml
+++ b/config/locales/views/transactions/en.yml
@@ -24,11 +24,6 @@ en:
success: "%{count} transactions updated"
create:
success: New transaction created successfully
- destroy:
- success: Transaction deleted successfully
- empty:
- description: Try adding a transaction, editing filters or refining your search
- title: No transactions found
form:
account: Account
account_prompt: Select an Account
@@ -52,38 +47,5 @@ en:
success: Marked as transfer
pagination:
rows_per_page: Rows per page
- selection_bar:
- mark_transfers: Mark as transfers?
- mark_transfers_confirm: Mark as transfers
- mark_transfers_message: By marking transactions as transfers, they will no longer
- be included in income or spending calculations.
- show:
- account_label: Account
- account_placeholder: Select an account
- additional: Additional
- category_label: Category
- category_placeholder: Select a 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
- exclude_subtitle: This excludes the transaction from any in-app features or
- analytics.
- exclude_title: Exclude transaction
- merchant_label: Merchant
- merchant_placeholder: Select a merchant
- name_label: Name
- note_label: Notes
- note_placeholder: Enter a note
- overview: Overview
- settings: Settings
- tags_label: Select one or more tags
- transaction:
- remove_transfer: Remove transfer
- remove_transfer_body: This will remove the transfer from this transaction
- remove_transfer_confirm: Confirm
unmark_transfers:
success: Transfer removed
- update:
- success: Transaction updated successfully
diff --git a/config/routes.rb b/config/routes.rb
index 12c059c6..83059b78 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -51,23 +51,12 @@ Rails.application.routes.draw do
resources :merchants, only: %i[ index new create edit update destroy ]
- namespace :transaction do
- resources :rows, only: %i[ show update ]
- resources :rules, only: %i[ index ]
- end
-
- resources :transactions do
- collection do
- post "bulk_delete"
- get "bulk_edit"
- post "bulk_update"
- post "mark_transfers"
- post "unmark_transfers"
- end
- end
-
namespace :account do
resources :transfers, only: %i[ new create destroy ]
+
+ namespace :transaction do
+ resources :rules, only: %i[ index ]
+ end
end
resources :accounts do
@@ -82,7 +71,22 @@ Rails.application.routes.draw do
scope module: :account do
resource :logo, only: :show
+
resources :valuations
+
+ resources :transactions, only: %i[ index show update destroy ] do
+ resource :row, only: %i[ show update ], module: :transaction
+ end
+ end
+ end
+
+ resources :transactions, only: %i[ index new create ] do
+ collection do
+ post "bulk_delete"
+ get "bulk_edit"
+ post "bulk_update"
+ post "mark_transfers"
+ post "unmark_transfers"
end
end
diff --git a/db/migrate/20240621212528_rename_transactions_table.rb b/db/migrate/20240621212528_rename_transactions_table.rb
new file mode 100644
index 00000000..e58098bf
--- /dev/null
+++ b/db/migrate/20240621212528_rename_transactions_table.rb
@@ -0,0 +1,15 @@
+class RenameTransactionsTable < ActiveRecord::Migration[7.2]
+ def change
+ rename_table :transactions, :account_transactions
+
+ reversible do |dir|
+ dir.up do
+ Tagging.where(taggable_type: 'Transaction').update_all(taggable_type: "Account::Transaction")
+ end
+
+ dir.down do
+ Tagging.where(taggable_type: 'Account::Transaction').update_all(taggable_type: "Transaction")
+ end
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 05378ced..7caed3c7 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: 2024_06_20_221801) do
+ActiveRecord::Schema[7.2].define(version: 2024_06_21_212528) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"
@@ -32,6 +32,26 @@ ActiveRecord::Schema[7.2].define(version: 2024_06_20_221801) do
t.index ["account_id"], name: "index_account_balances_on_account_id"
end
+ create_table "account_transactions", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
+ t.string "name"
+ t.date "date", null: false
+ t.decimal "amount", precision: 19, scale: 4, null: false
+ t.string "currency", default: "USD", null: false
+ t.uuid "account_id", null: false
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.uuid "category_id"
+ t.boolean "excluded", default: false
+ t.text "notes"
+ t.uuid "merchant_id"
+ t.uuid "transfer_id"
+ t.boolean "marked_as_transfer", default: false, null: false
+ t.index ["account_id"], name: "index_account_transactions_on_account_id"
+ t.index ["category_id"], name: "index_account_transactions_on_category_id"
+ t.index ["merchant_id"], name: "index_account_transactions_on_merchant_id"
+ t.index ["transfer_id"], name: "index_account_transactions_on_transfer_id"
+ end
+
create_table "account_transfers", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
@@ -309,26 +329,6 @@ ActiveRecord::Schema[7.2].define(version: 2024_06_20_221801) do
t.index ["family_id"], name: "index_tags_on_family_id"
end
- create_table "transactions", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
- t.string "name"
- t.date "date", null: false
- t.decimal "amount", precision: 19, scale: 4, null: false
- t.string "currency", default: "USD", null: false
- t.uuid "account_id", null: false
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
- t.uuid "category_id"
- t.boolean "excluded", default: false
- t.text "notes"
- t.uuid "merchant_id"
- t.uuid "transfer_id"
- t.boolean "marked_as_transfer", default: false, null: false
- t.index ["account_id"], name: "index_transactions_on_account_id"
- t.index ["category_id"], name: "index_transactions_on_category_id"
- t.index ["merchant_id"], name: "index_transactions_on_merchant_id"
- t.index ["transfer_id"], name: "index_transactions_on_transfer_id"
- end
-
create_table "users", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.uuid "family_id", null: false
t.string "first_name"
@@ -352,6 +352,10 @@ ActiveRecord::Schema[7.2].define(version: 2024_06_20_221801) do
end
add_foreign_key "account_balances", "accounts", on_delete: :cascade
+ add_foreign_key "account_transactions", "account_transfers", column: "transfer_id"
+ add_foreign_key "account_transactions", "accounts", on_delete: :cascade
+ add_foreign_key "account_transactions", "categories", on_delete: :nullify
+ add_foreign_key "account_transactions", "merchants"
add_foreign_key "account_valuations", "accounts", on_delete: :cascade
add_foreign_key "accounts", "families"
add_foreign_key "accounts", "institutions"
@@ -363,9 +367,5 @@ ActiveRecord::Schema[7.2].define(version: 2024_06_20_221801) do
add_foreign_key "merchants", "families"
add_foreign_key "taggings", "tags"
add_foreign_key "tags", "families"
- add_foreign_key "transactions", "account_transfers", column: "transfer_id"
- add_foreign_key "transactions", "accounts", on_delete: :cascade
- add_foreign_key "transactions", "categories", on_delete: :nullify
- add_foreign_key "transactions", "merchants"
add_foreign_key "users", "families"
end
diff --git a/test/controllers/account/transactions_controller_test.rb b/test/controllers/account/transactions_controller_test.rb
new file mode 100644
index 00000000..3778db85
--- /dev/null
+++ b/test/controllers/account/transactions_controller_test.rb
@@ -0,0 +1,40 @@
+require "test_helper"
+
+class Account::TransactionsControllerTest < ActionDispatch::IntegrationTest
+ setup do
+ sign_in @user = users(:family_admin)
+ @transaction = account_transactions(:checking_one)
+ @account = @transaction.account
+ @recent_transactions = @user.family.transactions.ordered.limit(20).to_a
+ end
+
+ test "should show transaction" do
+ get account_transaction_url(@transaction.account, @transaction)
+ assert_response :success
+ end
+
+ test "should update transaction" do
+ patch account_transaction_url(@transaction.account, @transaction), params: {
+ transaction: {
+ account_id: @transaction.account_id,
+ amount: @transaction.amount,
+ currency: @transaction.currency,
+ date: @transaction.date,
+ name: @transaction.name,
+ tag_ids: [ Tag.first.id, Tag.second.id ]
+ }
+ }
+
+ assert_redirected_to account_transaction_url(@transaction.account, @transaction)
+ assert_enqueued_with(job: AccountSyncJob)
+ end
+
+ test "should destroy transaction" do
+ assert_difference("Account::Transaction.count", -1) do
+ delete account_transaction_url(@transaction.account, @transaction)
+ end
+
+ assert_redirected_to account_url(@transaction.account)
+ assert_enqueued_with(job: AccountSyncJob)
+ end
+end
diff --git a/test/controllers/account/transfers_controller_test.rb b/test/controllers/account/transfers_controller_test.rb
index 9ceb5a30..1597471c 100644
--- a/test/controllers/account/transfers_controller_test.rb
+++ b/test/controllers/account/transfers_controller_test.rb
@@ -26,7 +26,7 @@ class Account::TransfersControllerTest < ActionDispatch::IntegrationTest
end
test "can destroy transfer" do
- assert_difference -> { Account::Transfer.count } => -1, -> { Transaction.count } => 0 do
+ assert_difference -> { Account::Transfer.count } => -1, -> { Account::Transaction.count } => 0 do
delete account_transfer_url(account_transfers(:credit_card_payment))
end
end
diff --git a/test/controllers/categories_controller_test.rb b/test/controllers/categories_controller_test.rb
index b38fff9f..b9fed5b0 100644
--- a/test/controllers/categories_controller_test.rb
+++ b/test/controllers/categories_controller_test.rb
@@ -37,7 +37,7 @@ class CategoriesControllerTest < ActionDispatch::IntegrationTest
assert_difference "Category.count", +1 do
post categories_url, params: {
- transaction_id: transactions(:checking_one).id,
+ transaction_id: account_transactions(:checking_one).id,
category: {
name: "New Category",
color: color } }
@@ -48,7 +48,7 @@ class CategoriesControllerTest < ActionDispatch::IntegrationTest
assert_redirected_to transactions_url
assert_equal "New Category", new_category.name
assert_equal color, new_category.color
- assert_equal transactions(:checking_one).reload.category, new_category
+ assert_equal account_transactions(:checking_one).reload.category, new_category
end
test "edit" do
diff --git a/test/controllers/category/deletions_controller_test.rb b/test/controllers/category/deletions_controller_test.rb
index c8bd3d37..51900fc4 100644
--- a/test/controllers/category/deletions_controller_test.rb
+++ b/test/controllers/category/deletions_controller_test.rb
@@ -30,7 +30,7 @@ class Category::DeletionsControllerTest < ActionDispatch::IntegrationTest
assert_not_empty @category.transactions
assert_difference "Category.count", -1 do
- assert_difference "Transaction.where(category: nil).count", @category.transactions.count do
+ assert_difference "Account::Transaction.where(category: nil).count", @category.transactions.count do
post category_deletions_url(@category)
end
end
diff --git a/test/controllers/transactions_controller_test.rb b/test/controllers/transactions_controller_test.rb
index fe861f64..2a3c172c 100644
--- a/test/controllers/transactions_controller_test.rb
+++ b/test/controllers/transactions_controller_test.rb
@@ -3,61 +3,19 @@ require "test_helper"
class TransactionsControllerTest < ActionDispatch::IntegrationTest
setup do
sign_in @user = users(:family_admin)
- @transaction = transactions(:checking_one)
+ @transaction = account_transactions(:checking_one)
@recent_transactions = @user.family.transactions.ordered.limit(20).to_a
end
- test "should get paginated index with most recent transactions first" do
- get transactions_url
- assert_response :success
-
- @recent_transactions.first(10).each do |transaction|
- assert_dom "#" + dom_id(transaction), count: 1
- end
- end
-
- test "transaction count represents filtered total" do
- get transactions_url
- assert_dom "#total-transactions", count: 1, text: @user.family.transactions.select { |t| t.currency == "USD" }.count.to_s
-
- new_transaction = @user.family.accounts.first.transactions.create! \
- name: "Transaction to search for",
- date: Date.current,
- amount: 0
-
- get transactions_url(q: { search: new_transaction.name })
-
- # Only finds 1 transaction that matches filter
- assert_dom "#" + dom_id(new_transaction), count: 1
- assert_dom "#total-transactions", count: 1, text: "1"
- end
-
- test "can navigate to paginated result" do
- get transactions_url(page: 2)
- assert_response :success
-
- @recent_transactions[10, 10].select { |t| t.transfer_id == nil }.each do |transaction|
- assert_dom "#" + dom_id(transaction), count: 1
- end
- end
-
- test "loads last page when page is out of range" do
- user_oldest_transaction = @user.family.transactions.ordered.reject(&:transfer?).last
- get transactions_url(page: 9999999999)
-
- assert_response :success
- assert_dom "#" + dom_id(user_oldest_transaction), count: 1
- end
-
test "should get new" do
get new_transaction_url
assert_response :success
end
- test "prefills account_id if provided" do
- get new_transaction_url(account_id: @transaction.account_id)
+ test "prefills account_id" do
+ get new_transaction_url(account_id: @transaction.account.id)
assert_response :success
- assert_select "option[selected][value='#{@transaction.account_id}']"
+ assert_select "option[selected][value='#{@transaction.account.id}']"
end
test "should create transaction" do
@@ -70,33 +28,38 @@ class TransactionsControllerTest < ActionDispatch::IntegrationTest
name: "Test transaction"
}
- assert_difference("Transaction.count") do
+ assert_difference("Account::Transaction.count") do
post transactions_url, params: { transaction: transaction_params }
end
- assert_equal transaction_params[:amount].to_d, Transaction.order(created_at: :desc).first.amount
+ assert_equal transaction_params[:amount].to_d, Account::Transaction.order(created_at: :desc).first.amount
assert_equal "New transaction created successfully", flash[:notice]
assert_enqueued_with(job: AccountSyncJob)
- assert_redirected_to transactions_url
+ assert_redirected_to account_url(account)
end
test "expenses are positive" do
- assert_difference("Transaction.count") do
- post transactions_url, params: { transaction: {
- nature: "expense",
- account_id: @transaction.account_id,
- amount: @transaction.amount,
- currency: @transaction.currency,
- date: @transaction.date,
- name: @transaction.name } }
+ assert_difference("Account::Transaction.count") do
+ post transactions_url, params: {
+ transaction: {
+ nature: "expense",
+ account_id: @transaction.account_id,
+ amount: @transaction.amount,
+ currency: @transaction.currency,
+ date: @transaction.date,
+ name: @transaction.name
+ }
+ }
end
- assert_redirected_to transactions_url
- assert Transaction.order(created_at: :desc).first.amount.positive?, "Amount should be positive"
+ created_transaction = Account::Transaction.order(created_at: :desc).first
+
+ assert_redirected_to account_url(@transaction.account)
+ assert created_transaction.amount.positive?, "Amount should be positive"
end
test "incomes are negative" do
- assert_difference("Transaction.count") do
+ assert_difference("Account::Transaction.count") do
post transactions_url, params: {
transaction: {
nature: "income",
@@ -109,44 +72,62 @@ class TransactionsControllerTest < ActionDispatch::IntegrationTest
}
end
- assert_redirected_to transactions_url
- assert Transaction.order(created_at: :desc).first.amount.negative?, "Amount should be negative"
+ created_transaction = Account::Transaction.order(created_at: :desc).first
+
+ assert_redirected_to account_url(@transaction.account)
+ assert created_transaction.amount.negative?, "Amount should be negative"
end
- test "should show transaction" do
- get transaction_url(@transaction)
+ test "should get paginated index with most recent transactions first" do
+ get transactions_url
assert_response :success
+
+ @recent_transactions.first(10).each do |transaction|
+ assert_dom "#" + dom_id(transaction), count: 1
+ end
end
- test "should update transaction" do
- patch transaction_url(@transaction), params: {
- transaction: {
- account_id: @transaction.account_id,
- amount: @transaction.amount,
- currency: @transaction.currency,
- date: @transaction.date,
- name: @transaction.name,
- tag_ids: [ Tag.first.id, Tag.second.id ]
- }
- }
+ test "transaction count represents filtered total" do
+ get transactions_url
+ assert_dom "#total-transactions", count: 1, text: @user.family.transactions.select { |t| t.currency == "USD" }.count.to_s
- assert_redirected_to transaction_url(@transaction)
- assert_enqueued_with(job: AccountSyncJob)
+ new_transaction = @user.family.accounts.first.transactions.create! \
+ name: "Transaction to search for",
+ date: Date.current,
+ amount: 0
+
+ get transactions_url(q: { search: new_transaction.name })
+
+ # Only finds 1 transaction that matches filter
+ assert_dom "#" + dom_id(new_transaction), count: 1
+ assert_dom "#total-transactions", count: 1, text: "1"
end
- test "should destroy transaction" do
- assert_difference("Transaction.count", -1) do
- delete transaction_url(@transaction)
+ test "can navigate to paginated result" do
+ get transactions_url(page: 2)
+ assert_response :success
+
+ @recent_transactions[10, 10].select { |t| t.transfer_id == nil }.each do |transaction|
+ assert_dom "#" + dom_id(transaction), count: 1
end
+ end
- assert_redirected_to transactions_url
- assert_enqueued_with(job: AccountSyncJob)
+ test "loads last page when page is out of range" do
+ user_oldest_transaction = @user.family.transactions.ordered.reject(&:transfer?).last
+ get transactions_url(page: 9999999999)
+
+ assert_response :success
+ assert_dom "#" + dom_id(user_oldest_transaction), count: 1
end
test "can destroy many transactions at once" do
delete_count = 10
- assert_difference("Transaction.count", -delete_count) do
- post bulk_delete_transactions_url, params: { bulk_delete: { transaction_ids: @recent_transactions.first(delete_count).pluck(:id) } }
+ assert_difference("Account::Transaction.count", -delete_count) do
+ post bulk_delete_transactions_url, params: {
+ bulk_delete: {
+ transaction_ids: @recent_transactions.first(delete_count).pluck(:id)
+ }
+ }
end
assert_redirected_to transactions_url
diff --git a/test/fixtures/transactions.yml b/test/fixtures/account/transactions.yml
similarity index 100%
rename from test/fixtures/transactions.yml
rename to test/fixtures/account/transactions.yml
diff --git a/test/fixtures/taggings.yml b/test/fixtures/taggings.yml
index f99a13de..caefa609 100644
--- a/test/fixtures/taggings.yml
+++ b/test/fixtures/taggings.yml
@@ -1,10 +1,10 @@
one:
tag: hawaii_trip
taggable: checking_one
- taggable_type: Transaction
+ taggable_type: Account::Transaction
two:
tag: emergency_fund
taggable: checking_two
- taggable_type: Transaction
+ taggable_type: Account::Transaction
diff --git a/test/models/.keep b/test/models/.keep
deleted file mode 100644
index e69de29b..00000000
diff --git a/test/models/transaction_test.rb b/test/models/account/transaction_test.rb
similarity index 81%
rename from test/models/transaction_test.rb
rename to test/models/account/transaction_test.rb
index 141b294c..d34c91b3 100644
--- a/test/models/transaction_test.rb
+++ b/test/models/account/transaction_test.rb
@@ -1,15 +1,15 @@
require "test_helper"
-class TransactionTest < ActiveSupport::TestCase
+class Account::TransactionTest < ActiveSupport::TestCase
setup do
- @transaction = transactions(:checking_one)
+ @transaction = account_transactions(:checking_one)
@family = families(:dylan_family)
end
# See: https://github.com/maybe-finance/maybe/wiki/vision#signage-of-money
test "negative amounts are inflows, positive amounts are outflows to an account" do
- inflow_transaction = transactions(:checking_four)
- outflow_transaction = transactions(:checking_five)
+ inflow_transaction = account_transactions(:checking_four)
+ outflow_transaction = account_transactions(:checking_five)
assert inflow_transaction.amount < 0
assert inflow_transaction.inflow?
@@ -35,8 +35,8 @@ class TransactionTest < ActiveSupport::TestCase
end
test "triggers sync with correct start date when transaction deleted" do
- prior_transaction = transactions(:checking_two) # 12 days ago
- current_transaction = transactions(:checking_one) # 5 days ago
+ prior_transaction = account_transactions(:checking_two) # 12 days ago
+ current_transaction = account_transactions(:checking_one) # 5 days ago
current_transaction.destroy!
current_transaction.account.expects(:sync_later).with(prior_transaction.date)
diff --git a/test/models/account/transfer_test.rb b/test/models/account/transfer_test.rb
index 7eb280d8..82199343 100644
--- a/test/models/account/transfer_test.rb
+++ b/test/models/account/transfer_test.rb
@@ -15,7 +15,7 @@ class Account::TransferTest < ActiveSupport::TestCase
test "transfer must have 2 transactions" do
invalid_transfer_1 = Account::Transfer.new transactions: [ @outflow ]
- invalid_transfer_2 = Account::Transfer.new transactions: [ @inflow, @outflow, transactions(:savings_four) ]
+ invalid_transfer_2 = Account::Transfer.new transactions: [ @inflow, @outflow, account_transactions(:savings_four) ]
assert invalid_transfer_1.invalid?
assert invalid_transfer_2.invalid?
diff --git a/test/models/account_test.rb b/test/models/account_test.rb
index 36633ff6..ef36badd 100644
--- a/test/models/account_test.rb
+++ b/test/models/account_test.rb
@@ -99,7 +99,7 @@ class AccountTest < ActiveSupport::TestCase
end
test "should destroy dependent transactions" do
- assert_difference("Transaction.count", [email protected]) do
+ assert_difference("Account::Transaction.count", [email protected]) do
@account.destroy
end
end
diff --git a/test/models/category_test.rb b/test/models/category_test.rb
index a0f920f6..4020747b 100644
--- a/test/models/category_test.rb
+++ b/test/models/category_test.rb
@@ -34,7 +34,7 @@ class CategoryTest < ActiveSupport::TestCase
end
test "replacing and destroying" do
- transctions = categories(:food_and_drink).transactions.to_a
+ transactions = categories(:food_and_drink).transactions.to_a
categories(:food_and_drink).replace_and_destroy!(categories(:income))
diff --git a/test/models/import_test.rb b/test/models/import_test.rb
index 02c4d127..ed03f934 100644
--- a/test/models/import_test.rb
+++ b/test/models/import_test.rb
@@ -45,7 +45,7 @@ class ImportTest < ActiveSupport::TestCase
# Fixtures already define "Food & Drink" and "Income", so these should not be created
# "Shopping" is a new category, but should only be created 1x during import
assert_difference \
- -> { Transaction.count } => 4,
+ -> { Account::Transaction.count } => 4,
-> { Category.count } => 1,
-> { Tagging.count } => 4,
-> { Tag.count } => 2 do
@@ -59,11 +59,11 @@ class ImportTest < ActiveSupport::TestCase
test "publishes a valid import with missing data" do
@empty_import.update! raw_csv_str: valid_csv_with_missing_data
- assert_difference -> { Category.count } => 1, -> { Transaction.count } => 2 do
+ assert_difference -> { Category.count } => 1, -> { Account::Transaction.count } => 2 do
@empty_import.publish
end
- assert_not_nil Transaction.find_sole_by(name: Import::FALLBACK_TRANSACTION_NAME)
+ assert_not_nil Account::Transaction.find_sole_by(name: Import::FALLBACK_TRANSACTION_NAME)
@empty_import.reload
@@ -73,7 +73,7 @@ class ImportTest < ActiveSupport::TestCase
test "failed publish results in error status" do
@empty_import.update! raw_csv_str: valid_csv_with_invalid_values
- assert_difference "Transaction.count", 0 do
+ assert_difference "Account::Transaction.count", 0 do
@empty_import.publish
end
diff --git a/test/system/settings_test.rb b/test/system/settings_test.rb
index 1c844ebd..20aba151 100644
--- a/test/system/settings_test.rb
+++ b/test/system/settings_test.rb
@@ -14,7 +14,7 @@ class SettingsTest < ApplicationSystemTestCase
[ "Tags", "Tags", tags_path ],
[ "Categories", "Categories", categories_path ],
[ "Merchants", "Merchants", merchants_path ],
- [ "Rules", "Rules", transaction_rules_path ],
+ [ "Rules", "Rules", account_transaction_rules_path ],
[ "Imports", "Imports", imports_path ],
[ "What's New", "What's New", changelog_path ],
[ "Feedback", "Feedback", feedback_path ],
diff --git a/test/system/transactions_test.rb b/test/system/transactions_test.rb
index 097d8d8e..b5bd1dc0 100644
--- a/test/system/transactions_test.rb
+++ b/test/system/transactions_test.rb
@@ -132,7 +132,7 @@ class TransactionsTest < ApplicationSystemTestCase
private
def number_of_transactions_on_page
- page_size = 50
+ page_size = 10
[ @user.family.transactions.where(transfer_id: nil).count, page_size ].min
end
diff --git a/test/system/transfers_test.rb b/test/system/transfers_test.rb
index 4f70f101..de7bb671 100644
--- a/test/system/transfers_test.rb
+++ b/test/system/transfers_test.rb
@@ -33,8 +33,8 @@ class TransfersTest < ApplicationSystemTestCase
test "can match 2 transactions and create a transfer" do
transfer_date = Date.current
- outflow = Transaction.create! name: "Outflow from savings account", date: transfer_date, account: accounts(:savings), amount: 100
- inflow = Transaction.create! name: "Inflow to checking account", date: transfer_date, account: accounts(:checking), amount: -100
+ outflow = Account::Transaction.create! name: "Outflow from savings account", date: transfer_date, account: accounts(:savings), amount: 100
+ inflow = Account::Transaction.create! name: "Inflow to checking account", date: transfer_date, account: accounts(:checking), amount: -100
visit transactions_url