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/property.rb
Eirik H 7265f58518
Add cabin / cottage as a property type (#1658)
* Add cabin / cottage as property type

Signed-off-by: Eirik H <post@eirikh.no>

* Update app/models/property.rb

Signed-off-by: Zach Gollwitzer <zach.gollwitzer@gmail.com>

---------

Signed-off-by: Eirik H <post@eirikh.no>
Signed-off-by: Zach Gollwitzer <zach.gollwitzer@gmail.com>
Co-authored-by: Zach Gollwitzer <zach.gollwitzer@gmail.com>
2025-01-27 13:04:36 -05:00

43 lines
958 B
Ruby

class Property < ApplicationRecord
include Accountable
SUBTYPES = [
[ "Single Family Home", "single_family_home" ],
[ "Multi-Family Home", "multi_family_home" ],
[ "Condominium", "condominium" ],
[ "Townhouse", "townhouse" ],
[ "Investment Property", "investment_property" ],
[ "Second Home", "second_home" ]
]
has_one :address, as: :addressable, dependent: :destroy
accepts_nested_attributes_for :address
attribute :area_unit, :string, default: "sqft"
def area
Measurement.new(area_value, area_unit) if area_value.present?
end
def purchase_price
first_valuation_amount
end
def trend
TimeSeries::Trend.new(current: account.balance_money, previous: first_valuation_amount)
end
def color
"#06AED4"
end
def icon
"home"
end
private
def first_valuation_amount
account.entries.account_valuations.order(:date).first&.amount_money || account.balance_money
end
end