mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-24 23:59:40 +02:00
Enable updating Account::Entry#amount (#942)
- Enable updating transaction type income/expense - Enable updating transaction amount
This commit is contained in:
parent
3089e3c81d
commit
f1d0a62ac7
3 changed files with 27 additions and 1 deletions
|
@ -40,7 +40,9 @@ class Account::EntriesController < ApplicationController
|
|||
end
|
||||
|
||||
def update
|
||||
@entry.update! entry_params
|
||||
@entry.assign_attributes entry_params
|
||||
@entry.amount = amount if nature.present?
|
||||
@entry.save!
|
||||
@entry.sync_account_later
|
||||
|
||||
respond_to do |format|
|
||||
|
@ -84,6 +86,18 @@ class Account::EntriesController < ApplicationController
|
|||
.permit(:name, :date, :amount, :currency, :entryable_type, entryable_attributes: permitted_entryable_attributes)
|
||||
end
|
||||
|
||||
def amount
|
||||
if nature.income?
|
||||
entry_params[:amount].to_d.abs * -1
|
||||
else
|
||||
entry_params[:amount].to_d.abs
|
||||
end
|
||||
end
|
||||
|
||||
def nature
|
||||
params[:account_entry][:nature].to_s.inquiry
|
||||
end
|
||||
|
||||
# entryable_type is required here because Rails expects both of these params in this exact order (potential upstream bug)
|
||||
def entry_params_with_defaults(params)
|
||||
params.with_defaults(entryable_type: params[:entryable_type], entryable_attributes: {})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue