1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-24 15:49:39 +02:00
Maybe/app/models/concerns/accountable.rb
Zach Gollwitzer f904d9d062
Add the ability to "rollup" values in a time series (#554)
* Clean up time series models

* Add value group rollup class for summarizing hierarchical data

* Integrate new classes

* Update UI to use new patterns

* Update D3 charts to expect new data format

* Clean up account model

* More cleanup

* Money improvements

* Use new money fields

* Remove invalid fixture data to avoid orphaned accountables

* Update time series to work better with collections

* Fix tests and UI bugs
2024-03-19 09:10:40 -04:00

29 lines
889 B
Ruby

module Accountable
extend ActiveSupport::Concern
ASSET_TYPES = %w[ Account::Depository Account::Investment Account::OtherAsset Account::Property Account::Vehicle ]
LIABILITY_TYPES = %w[ Account::Credit Account::Loan Account::OtherLiability ]
TYPES = ASSET_TYPES + LIABILITY_TYPES
def self.from_type(type)
return nil unless types.include?(type) || TYPES.include?(type)
"Account::#{type.demodulize}".constantize
end
def self.by_classification
{ assets: ASSET_TYPES, liabilities: LIABILITY_TYPES }
end
def self.types(classification = nil)
types = classification ? (classification.to_sym == :asset ? ASSET_TYPES : LIABILITY_TYPES) : TYPES
types.map { |type| type.demodulize }
end
def self.classification(type)
ASSET_TYPES.include?(type) ? :asset : :liability
end
included do
has_one :account, as: :accountable, touch: true
end
end