diff --git a/app/controllers/transactions/categories/deletions_controller.rb b/app/controllers/categories/deletions_controller.rb similarity index 60% rename from app/controllers/transactions/categories/deletions_controller.rb rename to app/controllers/categories/deletions_controller.rb index 3e67a762..678823f2 100644 --- a/app/controllers/transactions/categories/deletions_controller.rb +++ b/app/controllers/categories/deletions_controller.rb @@ -1,4 +1,4 @@ -class Transactions::Categories::DeletionsController < ApplicationController +class Categories::DeletionsController < ApplicationController layout "with_sidebar" before_action :set_category @@ -15,12 +15,12 @@ class Transactions::Categories::DeletionsController < ApplicationController 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 diff --git a/app/controllers/transactions/categories/dropdowns_controller.rb b/app/controllers/categories/dropdowns_controller.rb similarity index 77% rename from app/controllers/transactions/categories/dropdowns_controller.rb rename to app/controllers/categories/dropdowns_controller.rb index 80654467..3da1bfe6 100644 --- a/app/controllers/transactions/categories/dropdowns_controller.rb +++ b/app/controllers/categories/dropdowns_controller.rb @@ -1,4 +1,4 @@ -class Transactions::Categories::DropdownsController < ApplicationController +class Categories::DropdownsController < ApplicationController before_action :set_from_params def show @@ -17,6 +17,6 @@ class Transactions::Categories::DropdownsController < ApplicationController end def categories_scope - Current.family.transaction_categories.alphabetically + Current.family.categories.alphabetically end end diff --git a/app/controllers/transactions/categories_controller.rb b/app/controllers/categories_controller.rb similarity index 58% rename from app/controllers/transactions/categories_controller.rb rename to app/controllers/categories_controller.rb index 99bcf6fc..dfbe63e4 100644 --- a/app/controllers/transactions/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -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 @@ -32,7 +32,7 @@ class Transactions::CategoriesController < ApplicationController private def set_category - @category = Current.family.transaction_categories.find(params[:id]) + @category = Current.family.categories.find(params[:id]) end def set_transaction @@ -42,6 +42,6 @@ class Transactions::CategoriesController < ApplicationController end def category_params - params.require(:transaction_category).permit(:name, :color) + params.require(:category).permit(:name, :color) end end diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 714fbb5e..3a18477d 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -16,7 +16,7 @@ class RegistrationsController < ApplicationController @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 diff --git a/app/helpers/categories_helper.rb b/app/helpers/categories_helper.rb new file mode 100644 index 00000000..83bddbf3 --- /dev/null +++ b/app/helpers/categories_helper.rb @@ -0,0 +1,7 @@ +module CategoriesHelper + def null_category + Category.new \ + name: "Uncategorized", + color: Category::UNCATEGORIZED_COLOR + end +end diff --git a/app/helpers/transactions/categories_helper.rb b/app/helpers/transactions/categories_helper.rb deleted file mode 100644 index 19d77a23..00000000 --- a/app/helpers/transactions/categories_helper.rb +++ /dev/null @@ -1,7 +0,0 @@ -module Transactions::CategoriesHelper - def null_category - Transaction::Category.new \ - name: "Uncategorized", - color: Transaction::Category::UNCATEGORIZED_COLOR - end -end diff --git a/app/models/transaction/category.rb b/app/models/category.rb similarity index 94% rename from app/models/transaction/category.rb rename to app/models/category.rb index 58955720..b846ca51 100644 --- a/app/models/transaction/category.rb +++ b/app/models/category.rb @@ -1,4 +1,4 @@ -class Transaction::Category < ApplicationRecord +class Category < ApplicationRecord has_many :transactions, dependent: :nullify belongs_to :family @@ -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 diff --git a/app/models/family.rb b/app/models/family.rb index d7ccafd9..a86980ff 100644 --- a/app/models/family.rb +++ b/app/models/family.rb @@ -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) diff --git a/app/models/import.rb b/app/models/import.rb index cbe93697..49fc4f96 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -124,7 +124,7 @@ class Import < ApplicationRecord 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, diff --git a/app/models/transaction.rb b/app/models/transaction.rb index 1d6b304e..7f534839 100644 --- a/app/models/transaction.rb +++ b/app/models/transaction.rb @@ -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 }) } diff --git a/app/views/accounts/transactions/_transaction.html.erb b/app/views/accounts/transactions/_transaction.html.erb index 5adc5817..e725c818 100644 --- a/app/views/accounts/transactions/_transaction.html.erb +++ b/app/views/accounts/transactions/_transaction.html.erb @@ -10,7 +10,7 @@

Transfer

<% else %> - <%= render "transactions/categories/badge", category: transaction.category %> + <%= render "categories/badge", category: transaction.category %> <% end %> diff --git a/app/views/transactions/categories/_badge.html.erb b/app/views/categories/_badge.html.erb similarity index 100% rename from app/views/transactions/categories/_badge.html.erb rename to app/views/categories/_badge.html.erb diff --git a/app/views/transactions/categories/_form.html.erb b/app/views/categories/_form.html.erb similarity index 96% rename from app/views/transactions/categories/_form.html.erb rename to app/views/categories/_form.html.erb index 0e12b4e7..b5fba349 100644 --- a/app/views/transactions/categories/_form.html.erb +++ b/app/views/categories/_form.html.erb @@ -14,7 +14,7 @@ <%= form.hidden_field :color, data: { color_select_target: "input" } %>