mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-19 05:09:38 +02:00
Account namespace updates: part 6 (transactions) (#904)
* Move Transaction to Account namespace * Fix improper routes, improve separation of concerns * Replace account transactions list partial with view * Remove logs * Consolidate transaction views * Remove unused code * Transfer style tweaks * Remove more unused code * Add back totals by currency helper
This commit is contained in:
parent
cb3fd34f90
commit
da18c3d850
72 changed files with 575 additions and 522 deletions
|
@ -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))
|
||||
.find(params[:transaction][:account_id])
|
||||
.transactions
|
||||
.create!(transaction_params.merge(amount: amount))
|
||||
|
||||
@transaction.save!
|
||||
@transaction.sync_account_later
|
||||
redirect_to transactions_url, notice: t(".success")
|
||||
end
|
||||
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue