Skip to content

armgit / maybe

Public Imported from GitHub
0

The personal finance app for everyone

Fix account transaction form resetting amount to 0 (#1133)

Zach Gollwitzer166ed4b1ea53
diff --git a/app/controllers/account/transactions_controller.rb b/app/controllers/account/transactions_controller.rb
index 61571cb4..0a0d88a2 100644
--- a/app/controllers/account/transactions_controller.rb
+++ b/app/controllers/account/transactions_controller.rb
@@ -12,8 +12,7 @@ class Account::TransactionsController < ApplicationController
end
def update
- @entry.update!(entry_params.merge(amount: amount))
- @entry.sync_account_later
+ @entry.update!(entry_params)
respond_to do |format|
format.html { redirect_to account_entry_path(@account, @entry), notice: t(".success") }
@@ -34,7 +33,7 @@ class Account::TransactionsController < ApplicationController
def entry_params
params.require(:account_entry)
.permit(
- :name, :date, :amount, :currency, :entryable_type,
+ :name, :date, :amount, :currency, :entryable_type, :nature,
entryable_attributes: [
:id,
:notes,
@@ -43,14 +42,18 @@ class Account::TransactionsController < ApplicationController
:merchant_id,
{ tag_ids: [] }
]
- )
- end
+ ).tap do |permitted_params|
+ nature = permitted_params.delete(:nature)
+
+ if permitted_params[:amount]
+ amount_value = permitted_params[:amount].to_d
+
+ if nature == "income"
+ amount_value *= -1
+ end
- def amount
- if params[:account_entry][:nature] == "income"
- entry_params[:amount].to_d * -1
- else
- entry_params[:amount].to_d
- end
+ permitted_params[:amount] = amount_value
+ end
+ end
end
end