mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-24 15:49:39 +02:00
* Adds basic validations for required fields Also deletes a few extraneous .keep files Does not add the family_id required field for user, since that breaks the basic test setup * Restore keep files to this branch * Remove Credit model and validate models behind ids * Restore concerns .keep
21 lines
506 B
Ruby
21 lines
506 B
Ruby
class Valuation < ApplicationRecord
|
|
belongs_to :account
|
|
|
|
validates :account, :date, :value, presence: true
|
|
|
|
after_commit :sync_account
|
|
|
|
scope :in_period, ->(period) { period.date_range.nil? ? all : where(date: period.date_range) }
|
|
|
|
def self.to_series(account, period = Period.all)
|
|
MoneySeries.new(
|
|
in_period(period).order(:date),
|
|
{ trend_type: account.classification, amount_accessor: :value }
|
|
)
|
|
end
|
|
|
|
private
|
|
def sync_account
|
|
self.account.sync_later
|
|
end
|
|
end
|