1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-29 18:19:39 +02:00

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

This commit is contained in:
Zach Gollwitzer 2024-08-26 19:10:17 -04:00 committed by GitHub
parent 0c0db44b7f
commit 166ed4b1ea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

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