mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 20:14:08 +00:00
Make balance editing easier (#976)
* Make balance editing easier * Translations * Fix money input option * Fix balance sync logic * Rework balance update flow
This commit is contained in:
@@ -93,4 +93,18 @@ class Account < ApplicationRecord
|
||||
rescue Money::ConversionError
|
||||
TimeSeries.new([])
|
||||
end
|
||||
|
||||
def update_balance!(balance)
|
||||
valuation = entries.account_valuations.find_by(date: Date.current)
|
||||
|
||||
if valuation
|
||||
valuation.update! amount: balance
|
||||
else
|
||||
entries.create! \
|
||||
date: Date.current,
|
||||
amount: balance,
|
||||
currency: currency,
|
||||
entryable: Account::Valuation.new
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user