Skip to content
This repository was archived by the owner on Jul 27, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Transactions::Categories::DeletionsController < ApplicationController
class Categories::DeletionsController < ApplicationController
layout "with_sidebar"

before_action :set_category
Expand All @@ -15,12 +15,12 @@ def create

private
def set_category
@category = Current.family.transaction_categories.find(params[:category_id])
@category = Current.family.categories.find(params[:category_id])
end

def set_replacement_category
if params[:replacement_category_id].present?
@replacement_category = Current.family.transaction_categories.find(params[:replacement_category_id])
@replacement_category = Current.family.categories.find(params[:replacement_category_id])
end
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Transactions::Categories::DropdownsController < ApplicationController
class Categories::DropdownsController < ApplicationController
before_action :set_from_params

def show
Expand All @@ -17,6 +17,6 @@ def set_from_params
end

def categories_scope
Current.family.transaction_categories.alphabetically
Current.family.categories.alphabetically
end
end
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
class Transactions::CategoriesController < ApplicationController
class CategoriesController < ApplicationController
layout "with_sidebar"

before_action :set_category, only: %i[ edit update ]
before_action :set_transaction, only: :create

def index
@categories = Current.family.transaction_categories.alphabetically
@categories = Current.family.categories.alphabetically
end

def new
@category = Current.family.transaction_categories.new color: Transaction::Category::COLORS.sample
@category = Current.family.categories.new color: Category::COLORS.sample
end

def create
Transaction::Category.transaction do
category = Current.family.transaction_categories.create!(category_params)
Category.transaction do
category = Current.family.categories.create!(category_params)
@transaction.update!(category_id: category.id) if @transaction
end

Expand All @@ -32,7 +32,7 @@ def update

private
def set_category
@category = Current.family.transaction_categories.find(params[:id])
@category = Current.family.categories.find(params[:id])
end

def set_transaction
Expand All @@ -42,6 +42,6 @@ def set_transaction
end

def category_params
params.require(:transaction_category).permit(:name, :color)
params.require(:category).permit(:name, :color)
end
end
2 changes: 1 addition & 1 deletion app/controllers/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def create
@user.role = :admin

if @user.save
Transaction::Category.create_default_categories(@user.family)
Category.create_default_categories(@user.family)
login @user
flash[:notice] = t(".success")
redirect_to root_path
Expand Down
7 changes: 7 additions & 0 deletions app/helpers/categories_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module CategoriesHelper
def null_category
Category.new \
name: "Uncategorized",
color: Category::UNCATEGORIZED_COLOR
end
end
7 changes: 0 additions & 7 deletions app/helpers/transactions/categories_helper.rb

This file was deleted.

4 changes: 2 additions & 2 deletions app/models/transaction/category.rb → app/models/category.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Transaction::Category < ApplicationRecord
class Category < ApplicationRecord
has_many :transactions, dependent: :nullify
belongs_to :family

Expand All @@ -24,7 +24,7 @@ class Transaction::Category < ApplicationRecord
]

def self.create_default_categories(family)
if family.transaction_categories.size > 0
if family.categories.size > 0
raise ArgumentError, "Family already has some categories"
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/family.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Family < ApplicationRecord
has_many :institutions, dependent: :destroy
has_many :transactions, through: :accounts
has_many :imports, through: :accounts
has_many :transaction_categories, dependent: :destroy, class_name: "Transaction::Category"
has_many :categories, dependent: :destroy
has_many :transaction_merchants, dependent: :destroy, class_name: "Transaction::Merchant"

def snapshot(period = Period.all)
Expand Down
2 changes: 1 addition & 1 deletion app/models/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def generate_transactions
tags << tag_cache[tag_string] ||= account.family.tags.find_or_initialize_by(name: tag_string)
end

category = category_cache[category_name] ||= account.family.transaction_categories.find_or_initialize_by(name: category_name) if category_name.present?
category = category_cache[category_name] ||= account.family.categories.find_or_initialize_by(name: category_name) if category_name.present?

txn = account.transactions.build \
name: row["name"].presence || FALLBACK_TRANSACTION_NAME,
Expand Down
2 changes: 1 addition & 1 deletion app/models/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Transaction < ApplicationRecord
scope :inflows, -> { where("amount <= 0") }
scope :outflows, -> { where("amount > 0") }
scope :by_name, ->(name) { where("transactions.name ILIKE ?", "%#{name}%") }
scope :with_categories, ->(categories) { joins(:category).where(transaction_categories: { name: categories }) }
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(transaction_merchants: { name: merchants }) }
Expand Down
2 changes: 1 addition & 1 deletion app/views/accounts/transactions/_transaction.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<p>Transfer</p>
</div>
<% else %>
<%= render "transactions/categories/badge", category: transaction.category %>
<%= render "categories/badge", category: transaction.category %>
<% end %>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<%= form.hidden_field :color, data: { color_select_target: "input" } %>

<ul role="radiogroup" class="flex justify-between items-center py-2">
<% Transaction::Category::COLORS.each do |color| %>
<% Category::COLORS.each do |color| %>
<li tabindex="0"
role="radio"
data-action="click->color-select#select keydown.enter->color-select#select keydown.space->color-select#select"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<%# locals: (transaction:) %>
<div class="relative" data-controller="menu">
<button data-menu-target="button" class="flex cursor-pointer">
<%= render partial: "transactions/categories/badge", locals: { category: transaction.category } %>
<%= render partial: "categories/badge", locals: { category: transaction.category } %>
</button>
<div data-menu-target="content" class="absolute z-10 hidden w-screen mt-2 max-w-min cursor-default">
<div class="w-64 text-sm font-semibold leading-6 text-gray-900 bg-white shadow-lg shrink rounded-xl ring-1 ring-gray-900/5">
<%= turbo_frame_tag "category_dropdown", src: transaction_category_dropdown_path(category_id: transaction.category_id, transaction_id: transaction.id), loading: :lazy do %>
<%= turbo_frame_tag "category_dropdown", src: category_dropdown_path(category_id: transaction.category_id, transaction_id: transaction.id), loading: :lazy do %>
<div class="p-6 flex items-center justify-center">
<p class="text-sm text-gray-500 animate-pulse"><%= t(".loading") %></p>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<div class="flex justify-between mx-4 py-5 border-b last:border-b-0 border-alpha-black-50">
<%= render partial: "transactions/categories/badge", locals: { category: row } %>
<%= render partial: "categories/badge", locals: { category: row } %>

<%= contextual_menu do %>
<div class="w-48 p-1 text-sm leading-6 text-gray-900 bg-white shadow-lg shrink rounded-xl ring-1 ring-gray-900/5">
<%= link_to edit_transaction_category_path(row),
<%= link_to edit_category_path(row),
class: "block w-full py-2 px-3 space-x-2 text-gray-900 hover:bg-gray-50 flex items-center rounded-lg",
data: { turbo_frame: :modal } do %>
<%= lucide_icon "pencil-line", class: "w-5 h-5 text-gray-500" %>

<span><%= t(".edit") %></span>
<% end %>

<%= link_to new_transaction_category_deletion_path(row),
<%= link_to new_category_deletion_path(row),
class: "block w-full py-2 px-3 space-x-2 text-red-600 hover:bg-red-50 flex items-center rounded-lg",
data: { turbo_frame: :modal } do %>
<%= lucide_icon "trash-2", class: "w-5 h-5" %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</p>
</div>

<%= form_with url: transaction_category_deletions_path(@category),
<%= form_with url: category_deletions_path(@category),
data: {
turbo: false,
controller: "deletion",
Expand All @@ -20,7 +20,7 @@
deletion_submit_text_when_not_replacing_value: t(".delete_and_leave_uncategorized", category_name: @category.name),
deletion_submit_text_when_replacing_value: t(".delete_and_recategorize", category_name: @category.name) } do |f| %>
<%= f.collection_select :replacement_category_id,
Current.family.transaction_categories.alphabetically.without(@category),
Current.family.categories.alphabetically.without(@category),
:id, :name,
{ prompt: t(".replacement_category_prompt"), label: t(".category") },
{ data: { deletion_target: "replacementField", action: "deletion#updateSubmitButton" } } %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
<span class="w-5 h-5">
<%= lucide_icon("check", class: "w-5 h-5 text-gray-500") if is_selected %>
</span>
<%= render partial: "transactions/categories/badge", locals: { category: category } %>
<%= render partial: "categories/badge", locals: { category: category } %>
<% end %>

<%= contextual_menu do %>
<div class="w-48 p-1 text-sm leading-6 text-gray-900 bg-white shadow-lg shrink rounded-xl ring-1 ring-gray-900/5">
<%= link_to edit_transaction_category_path(category),
<%= link_to edit_category_path(category),
class: "block w-full py-2 px-3 space-x-2 text-gray-900 hover:bg-gray-50 flex items-center rounded-lg",
data: { turbo_frame: :modal } do %>
<%= lucide_icon "pencil-line", class: "w-5 h-5 text-gray-500" %>

<span><%= t(".edit") %></span>
<% end %>

<%= link_to new_transaction_category_deletion_path(category),
<%= link_to new_category_deletion_path(category),
class: "block w-full py-2 px-3 space-x-2 text-red-600 hover:bg-red-50 flex items-center rounded-lg",
data: { turbo_frame: :modal } do %>
<%= lucide_icon "trash-2", class: "w-5 h-5" %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
<%= t(".no_categories") %>
</div>
<% @categories.each do |category| %>
<%= render partial: "transactions/categories/dropdowns/row", locals: { category: } %>
<%= render partial: "categories/dropdowns/row", locals: { category: } %>
<% end %>
</div>
<hr>
<div class="relative p-1.5 w-full">
<%= link_to new_transaction_category_path(transaction_id: @transaction),
<%= link_to new_category_path(transaction_id: @transaction),
class: "flex text-sm font-medium items-center gap-2 text-gray-500 w-full rounded-lg p-2 hover:bg-gray-100",
data: { turbo_frame: "modal" } do %>
<%= lucide_icon "plus", class: "w-5 h-5" %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<header class="flex items-center justify-between">
<h1 class="text-gray-900 text-xl font-medium"><%= t(".categories") %></h1>

<%= link_to new_transaction_category_path, class: "rounded-lg bg-gray-900 text-white flex items-center gap-1 justify-center hover:bg-gray-700 px-3 py-2", data: { turbo_frame: :modal } do %>
<%= link_to new_category_path, class: "rounded-lg bg-gray-900 text-white flex items-center gap-1 justify-center hover:bg-gray-700 px-3 py-2", data: { turbo_frame: :modal } do %>
<%= lucide_icon "plus", class: "w-5 h-5" %>
<p><%= t(".new") %></p>
<% end %>
Expand All @@ -16,7 +16,7 @@
<h2 class="uppercase px-4 py-2 text-gray-500 text-xs"><%= t(".categories") %> · <%= @categories.size %></h2>

<div class="border border-alpha-gray-100 rounded-lg bg-white shadow-xs">
<%= render collection: @categories, partial: "transactions/categories/row" %>
<%= render collection: @categories, partial: "categories/row" %>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/imports/transactions/_transaction.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</div>

<div class="col-span-2">
<%= render partial: "transactions/categories/badge", locals: { category: transaction.category } %>
<%= render partial: "categories/badge", locals: { category: transaction.category } %>
</div>

<div class="col-span-2 flex items-center gap-1">
Expand Down
2 changes: 1 addition & 1 deletion app/views/settings/_nav.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<%= sidebar_link_to t(".tags_label"), tags_path, icon: "tags" %>
</li>
<li>
<%= sidebar_link_to t(".categories_label"), transaction_categories_path, icon: "tags" %>
<%= sidebar_link_to t(".categories_label"), categories_path, icon: "tags" %>
</li>
<li>
<%= sidebar_link_to t(".merchants_label"), transaction_merchants_path, icon: "store" %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/tags/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@

<footer class="flex justify-between gap-4">
<%= previous_setting("Accounts", accounts_path) %>
<%= next_setting("Categories", transaction_categories_path) %>
<%= next_setting("Categories", categories_path) %>
</footer>
</section>
2 changes: 1 addition & 1 deletion app/views/transactions/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<%= f.text_field :name, label: t(".description"), placeholder: t(".description_placeholder"), required: true %>
<%= f.collection_select :account_id, Current.family.accounts.alphabetically, :id, :name, { prompt: t(".account_prompt"), label: t(".account") }, required: true %>
<%= f.money_field :amount_money, label: t(".amount"), required: true %>
<%= f.collection_select :category_id, Current.family.transaction_categories.alphabetically, :id, :name, { prompt: t(".category_prompt"), label: t(".category") } %>
<%= f.collection_select :category_id, Current.family.categories.alphabetically, :id, :name, { prompt: t(".category_prompt"), label: t(".category") } %>
<%= f.date_field :date, label: t(".date"), required: true, max: Date.today %>
</section>

Expand Down
2 changes: 1 addition & 1 deletion app/views/transactions/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="flex items-center gap-2">
<%= contextual_menu do %>
<div class="w-48 p-1 text-sm leading-6 text-gray-900 bg-white shadow-lg shrink rounded-xl ring-1 ring-gray-900/5">
<%= link_to transaction_categories_path,
<%= link_to categories_path,
class: "block w-full py-2 px-3 space-x-2 text-gray-900 hover:bg-gray-50 flex items-center rounded-lg font-normal" do %>
<%= lucide_icon "tags", class: "w-5 h-5 text-gray-500" %>
<span class="text-black"><%= t(".edit_categories") %></span>
Expand Down
2 changes: 1 addition & 1 deletion app/views/transactions/_transaction.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<% unless unconfirmed_transfer?(transaction) %>
<div class="col-span-3">
<%= render "transactions/categories/menu", transaction: transaction %>
<%= render "categories/menu", transaction: transaction %>
</div>

<%= link_to transaction.account.name,
Expand Down
2 changes: 1 addition & 1 deletion app/views/transactions/bulk_edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<div class="pb-6 space-y-2">
<%= form.date_field :date, label: t(".date_label"), max: Date.current %>
<%= form.collection_select :category_id, Current.family.transaction_categories.alphabetically, :id, :name, { prompt: t(".category_placeholder"), label: t(".category_label"), class: "text-gray-400" } %>
<%= form.collection_select :category_id, Current.family.categories.alphabetically, :id, :name, { prompt: t(".category_placeholder"), label: t(".category_label"), class: "text-gray-400" } %>
<%= form.collection_select :merchant_id, Current.family.transaction_merchants.alphabetically, :id, :name, { prompt: t(".merchant_placeholder"), label: t(".merchant_label"), class: "text-gray-400" } %>
</div>
</details>
Expand Down
2 changes: 1 addition & 1 deletion app/views/transactions/merchants/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<% end %>
</div>
<div class="flex justify-between gap-4">
<%= previous_setting("Categories", transaction_categories_path) %>
<%= previous_setting("Categories", categories_path) %>
<%= next_setting("Rules", transaction_rules_path) %>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
<%= lucide_icon("search", class: "w-5 h-5 text-gray-500 absolute inset-y-0 left-2 top-1/2 transform -translate-y-1/2") %>
</div>
<div class="my-2" id="list" data-list-filter-target="list">
<% Current.family.transaction_categories.alphabetically.each do |transaction_category| %>
<div class="filterable-item flex items-center gap-2 p-2" data-filter-name="<%= transaction_category.name %>">
<% Current.family.categories.alphabetically.each do |category| %>
<div class="filterable-item flex items-center gap-2 p-2" data-filter-name="<%= category.name %>">
<%= form.check_box :categories,
{
multiple: true,
checked: @q[:categories]&.include?(transaction_category.name),
checked: @q[:categories]&.include?(category.name),
class: "rounded-sm border-gray-300 text-indigo-600 shadow-xs focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50"
},
transaction_category.name,
category.name,
nil %>
<%= form.label :categories, transaction_category.name, value: transaction_category.name, class: "text-sm text-gray-900 cursor-pointer" do %>
<%= render partial: "transactions/categories/badge", locals: { category: transaction_category } %>
<%= form.label :categories, category.name, value: category.name, class: "text-sm text-gray-900 cursor-pointer" do %>
<%= render partial: "categories/badge", locals: { category: category } %>
<% end %>
</div>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/transactions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<%= f.date_field :date, label: t(".date_label"), max: Date.today, "data-auto-submit-form-target": "auto" %>

<% unless @transaction.marked_as_transfer %>
<%= f.collection_select :category_id, Current.family.transaction_categories.alphabetically, :id, :name, { prompt: t(".category_placeholder"), label: t(".category_label"), class: "text-gray-400" }, "data-auto-submit-form-target": "auto" %>
<%= f.collection_select :category_id, Current.family.categories.alphabetically, :id, :name, { prompt: t(".category_placeholder"), label: t(".category_label"), class: "text-gray-400" }, "data-auto-submit-form-target": "auto" %>
<%= f.collection_select :merchant_id, Current.family.transaction_merchants.alphabetically, :id, :name, { prompt: t(".merchant_placeholder"), label: t(".merchant_label"), class: "text-gray-400" }, "data-auto-submit-form-target": "auto" %>
<% end %>

Expand Down
Loading