mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-24 07:39:39 +02:00
Add start balance to manual accounts (#735)
* Add start_balance to accounts * Add tests * Cleanup * Refactor code and add tests * Update physical cash demo account to be manual * Do not populate start_balance in migration * Cleanup * Review fixes * Revert calc change * Update app/models/exchange_rate.rb Co-authored-by: Zach Gollwitzer <zach.gollwitzer@gmail.com> Signed-off-by: Jakub Kottnauer <jk@jakubkottnauer.com> * Add test * Fix syncable bug and update csv tests --------- Signed-off-by: Jakub Kottnauer <jk@jakubkottnauer.com> Co-authored-by: Zach Gollwitzer <zach.gollwitzer@gmail.com>
This commit is contained in:
parent
daf7ff8ef4
commit
3d9ff3ad2a
13 changed files with 50 additions and 17 deletions
|
@ -53,10 +53,13 @@ class AccountsController < ApplicationController
|
|||
end
|
||||
|
||||
def create
|
||||
@account = Current.family.accounts.build(account_params.except(:accountable_type))
|
||||
@account = Current.family.accounts.build(account_params.except(:accountable_type, :start_date))
|
||||
@account.accountable = Accountable.from_type(account_params[:accountable_type])&.new
|
||||
|
||||
if @account.save
|
||||
@valuation = @account.valuations.new(date: account_params[:start_date] || Date.today, value: @account.balance, currency: @account.currency)
|
||||
@valuation.save!
|
||||
|
||||
redirect_to accounts_path, notice: t(".success")
|
||||
else
|
||||
render "new", status: :unprocessable_entity
|
||||
|
@ -86,6 +89,6 @@ class AccountsController < ApplicationController
|
|||
end
|
||||
|
||||
def account_params
|
||||
params.require(:account).permit(:name, :accountable_type, :balance, :currency, :subtype, :is_active)
|
||||
params.require(:account).permit(:name, :accountable_type, :balance, :start_date, :currency, :subtype, :is_active)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue