mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-24 15:49:39 +02:00
Add transaction modal flow (#633)
* Add transaction modal flow * Preserve decimals when creating transactions
This commit is contained in:
parent
a22c7a0e9c
commit
cd8d741fe1
12 changed files with 137 additions and 22 deletions
|
@ -49,16 +49,20 @@ class TransactionsController < ApplicationController
|
|||
end
|
||||
|
||||
def new
|
||||
@transaction = Transaction.new
|
||||
@transaction = 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
|
||||
account = Current.family.accounts.find(params[:transaction][:account_id])
|
||||
|
||||
@transaction = account.transactions.build(transaction_params)
|
||||
@transaction = Current.family.accounts
|
||||
.find(params[:transaction][:account_id])
|
||||
.transactions.build(transaction_params.merge(amount: amount))
|
||||
|
||||
respond_to do |format|
|
||||
if @transaction.save
|
||||
|
@ -118,6 +122,18 @@ class TransactionsController < ApplicationController
|
|||
@transaction = Transaction.find(params[:id])
|
||||
end
|
||||
|
||||
def amount
|
||||
if nature.income?
|
||||
transaction_params[:amount].to_d * -1
|
||||
else
|
||||
transaction_params[:amount].to_d
|
||||
end
|
||||
end
|
||||
|
||||
def nature
|
||||
params[:transaction][:nature].to_s.inquiry
|
||||
end
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def transaction_params
|
||||
params.require(:transaction).permit(:name, :date, :amount, :currency, :notes, :excluded, :category_id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue