1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-05 05:25:24 +02:00

Account namespace updates: part 4 (transfers, singular namespacing) (#896)

* Move Transfer to Account namespace

* Fix partial resolution due to namespacing plurality

* Make category and tag controllers consistent with namespacing convention

* Update stale partial reference
This commit is contained in:
Zach Gollwitzer 2024-06-20 13:32:44 -04:00 committed by GitHub
parent dc3147c101
commit bddaab0192
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
50 changed files with 227 additions and 127 deletions

View file

@ -1,4 +1,4 @@
class Accounts::LogosController < ApplicationController
class Account::LogosController < ApplicationController
def show
@account = Current.family.accounts.find(params[:account_id])
render_placeholder

View file

@ -1,17 +1,17 @@
class TransfersController < ApplicationController
class Account::TransfersController < ApplicationController
layout "with_sidebar"
before_action :set_transfer, only: :destroy
def new
@transfer = Transfer.new
@transfer = Account::Transfer.new
end
def create
from_account = Current.family.accounts.find(transfer_params[:from_account_id])
to_account = Current.family.accounts.find(transfer_params[:to_account_id])
@transfer = Transfer.build_from_accounts from_account, to_account, \
@transfer = Account::Transfer.build_from_accounts from_account, to_account, \
date: transfer_params[:date],
amount: transfer_params[:amount].to_d,
currency: transfer_params[:currency],
@ -20,7 +20,10 @@ class TransfersController < ApplicationController
if @transfer.save
redirect_to transactions_path, notice: t(".success")
else
render :new, status: :unprocessable_entity
# TODO: this is not an ideal way to handle errors and should eventually be improved.
# See: https://github.com/hotwired/turbo-rails/pull/367
flash[:error] = @transfer.errors.full_messages.to_sentence
redirect_to transactions_path
end
end
@ -32,10 +35,10 @@ class TransfersController < ApplicationController
private
def set_transfer
@transfer = Transfer.find(params[:id])
@transfer = Account::Transfer.find(params[:id])
end
def transfer_params
params.require(:transfer).permit(:from_account_id, :to_account_id, :amount, :currency, :date, :name)
params.require(:account_transfer).permit(:from_account_id, :to_account_id, :amount, :currency, :date, :name)
end
end

View file

@ -1,4 +1,4 @@
class Categories::DeletionsController < ApplicationController
class Category::DeletionsController < ApplicationController
layout "with_sidebar"
before_action :set_category

View file

@ -1,4 +1,4 @@
class Categories::DropdownsController < ApplicationController
class Category::DropdownsController < ApplicationController
before_action :set_from_params
def show

View file

@ -1,4 +1,4 @@
class Tags::DeletionsController < ApplicationController
class Tag::DeletionsController < ApplicationController
layout "with_sidebar"
before_action :set_tag

View file

@ -1,4 +1,4 @@
class Transactions::RowsController < ApplicationController
class Transaction::RowsController < ApplicationController
before_action :set_transaction, only: %i[ show update ]
def show

View file

@ -0,0 +1,6 @@
class Transaction::RulesController < ApplicationController
layout "with_sidebar"
def index
end
end

View file

@ -1,6 +0,0 @@
class Transactions::RulesController < ApplicationController
layout "with_sidebar"
def index
end
end

View file

@ -1,4 +1,4 @@
class Transfer < ApplicationRecord
class Account::Transfer < ApplicationRecord
has_many :transactions, dependent: :nullify
validate :transaction_count, :from_different_accounts, :net_zero_flows, :all_transactions_marked

View file

@ -4,7 +4,7 @@ class Transaction < ApplicationRecord
monetize :amount
belongs_to :account
belongs_to :transfer, optional: true
belongs_to :transfer, optional: true, class_name: "Account::Transfer"
belongs_to :category, optional: true
belongs_to :merchant, optional: true
has_many :taggings, as: :taggable, dependent: :destroy
@ -70,7 +70,7 @@ class Transaction < ApplicationRecord
update_all marked_as_transfer: true
# Attempt to "auto match" and save a transfer if 2 transactions selected
Transfer.new(transactions: all).save if all.count == 2
Account::Transfer.new(transactions: all).save if all.count == 2
end
def daily_totals(transactions, period: Period.last_30_days, currency: Current.family.currency)

View file

Before

Width:  |  Height:  |  Size: 653 B

After

Width:  |  Height:  |  Size: 653 B

Before After
Before After

View file

@ -1,4 +1,4 @@
<%= form_with model: transfer do |f| %>
<%= form_with model: transfer, 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">
<%= link_to new_transaction_path(nature: "expense"), data: { turbo_frame: :modal }, class: "flex px-4 py-1 rounded-lg items-center space-x-2 justify-center text-gray-400" do %>

View file

@ -2,7 +2,7 @@
<details class="group flex items-center text-gray-900 p-4 text-sm font-medium">
<summary class="flex items-center justify-between">
<div class="flex items-center gap-4">
<%= button_to transfer_path(transfer),
<%= button_to account_transfer_path(transfer),
method: :delete,
class: "flex items-center group/transfer",
data: {

View file

@ -78,7 +78,7 @@
<%= f.hidden_field :accountable_type %>
<%= f.text_field :name, placeholder: t(".name.placeholder"), required: "required", label: t(".name.label"), autofocus: true %>
<%= f.collection_select :institution_id, Current.family.institutions.alphabetically, :id, :name, { include_blank: t(".ungrouped"), label: t(".institution") } %>
<%= render "accounts/account/#{permitted_accountable_partial(@account.accountable_type)}", f: f %>
<%= render "accounts/accountables/#{permitted_accountable_partial(@account.accountable_type)}", f: f %>
<%= f.money_field :balance_money, label: t(".balance"), required: "required" %>
<div>

View file

@ -11,7 +11,7 @@
<%= t(".no_categories") %>
</div>
<% @categories.each do |category| %>
<%= render partial: "categories/dropdowns/row", locals: { category: } %>
<%= render partial: "category/dropdowns/row", locals: { category: } %>
<% end %>
</div>
<hr>

View file

@ -1,5 +1,5 @@
<%# locals: (date:, group:) %>
<div class="bg-gray-25 rounded-xl p-1 w-full" data-bulk-select-target="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",

View file

@ -3,7 +3,7 @@
<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? %>
<%= radio_tab_tag form: f, name: :nature, value: :income, label: t(".income"), icon: "plus-circle", checked: params[:nature] == "income" %>
<%= link_to new_transfer_path, data: { turbo_frame: :modal }, class: "flex px-4 py-1 rounded-lg items-center space-x-2 justify-center text-gray-400 group-has-[:checked]:bg-white group-has-[:checked]:text-gray-800 group-has-[:checked]:shadow-sm" do %>
<%= link_to new_account_transfer_path, data: { turbo_frame: :modal }, class: "flex px-4 py-1 rounded-lg items-center space-x-2 justify-center text-gray-400 group-has-[:checked]:bg-white group-has-[:checked]:text-gray-800 group-has-[:checked]:shadow-sm" do %>
<%= lucide_icon "arrow-right-left", class: "w-5 h-5" %>
<%= tag.span t(".transfer") %>
<% end %>

View file

@ -18,7 +18,7 @@
accept: t(".mark_transfers_confirm"),
}
} do |f| %>
<button type="button" data-bulk-select-scope-param="bulk_update" data-action="bulk-select#submitBulkRequest" class="p-1.5 group hover:bg-gray-700 flex items-center justify-center rounded-md" title="Mark as transfer">
<button id="bulk-transfer-btn" type="button" data-bulk-select-scope-param="bulk_update" data-action="bulk-select#submitBulkRequest" class="p-1.5 group hover:bg-gray-700 flex items-center justify-center rounded-md" title="Mark as transfer">
<%= lucide_icon "arrow-right-left", class: "w-5 group-hover:text-white" %>
</button>
<% end %>