mirror of
https://github.com/we-promise/sure.git
synced 2026-04-25 23:14:10 +00:00
Add transaction modal flow (#633)
* Add transaction modal flow * Preserve decimals when creating transactions
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user