1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-21 06:09:38 +02:00
Maybe/app/models/concerns/accountable.rb

30 lines
681 B
Ruby
Raw Normal View History

2024-02-02 23:09:35 +00:00
module Accountable
extend ActiveSupport::Concern
ASSET_TYPES = %w[Depository Investment Crypto Property Vehicle OtherAsset]
LIABILITY_TYPES = %w[CreditCard Loan OtherLiability]
TYPES = ASSET_TYPES + LIABILITY_TYPES
def self.from_type(type)
return nil unless TYPES.include?(type)
type.constantize
end
def self.by_classification
{ assets: ASSET_TYPES, liabilities: LIABILITY_TYPES }
end
2024-02-02 23:09:35 +00:00
included do
has_one :account, as: :accountable, touch: true
end
def post_sync
broadcast_replace_to(
account,
target: "chart_account_#{account.id}",
partial: "accounts/show/chart",
locals: { account: account }
)
end
2024-02-02 23:09:35 +00:00
end