1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-24 07:39:39 +02:00
Maybe/app/models/vehicle.rb
Zach Gollwitzer e657c40d19
Account:: namespace simplifications and cleanup (#2110)
* Flatten Holding model

* Flatten balance model

* Entries domain renames

* Fix valuations reference

* Fix trades stream

* Fix brakeman warnings

* Fix tests

* Replace existing entryable type references in DB
2025-04-14 11:40:34 -04:00

36 lines
649 B
Ruby

class Vehicle < ApplicationRecord
include Accountable
attribute :mileage_unit, :string, default: "mi"
def mileage
Measurement.new(mileage_value, mileage_unit) if mileage_value.present?
end
def purchase_price
first_valuation_amount
end
def trend
Trend.new(current: account.balance_money, previous: first_valuation_amount)
end
class << self
def color
"#F23E94"
end
def icon
"car-front"
end
def classification
"asset"
end
end
private
def first_valuation_amount
account.entries.valuations.order(:date).first&.amount_money || account.balance_money
end
end