2024-06-20 07:26:25 -04:00
|
|
|
class Property < ApplicationRecord
|
|
|
|
include Accountable
|
2024-08-23 08:47:08 -04:00
|
|
|
|
2025-04-22 13:10:50 -05:00
|
|
|
SUBTYPES = {
|
|
|
|
"single_family_home" => { short: "Single Family Home", long: "Single Family Home" },
|
|
|
|
"multi_family_home" => { short: "Multi-Family Home", long: "Multi-Family Home" },
|
|
|
|
"condominium" => { short: "Condo", long: "Condominium" },
|
|
|
|
"townhouse" => { short: "Townhouse", long: "Townhouse" },
|
|
|
|
"investment_property" => { short: "Investment Property", long: "Investment Property" },
|
|
|
|
"second_home" => { short: "Second Home", long: "Second Home" }
|
|
|
|
}.freeze
|
2024-11-04 20:27:31 -05:00
|
|
|
|
2024-08-23 08:47:08 -04:00
|
|
|
has_one :address, as: :addressable, dependent: :destroy
|
|
|
|
|
|
|
|
accepts_nested_attributes_for :address
|
|
|
|
|
|
|
|
attribute :area_unit, :string, default: "sqft"
|
|
|
|
|
2025-02-21 11:57:59 -05:00
|
|
|
class << self
|
|
|
|
def icon
|
|
|
|
"home"
|
|
|
|
end
|
|
|
|
|
|
|
|
def color
|
|
|
|
"#06AED4"
|
|
|
|
end
|
|
|
|
|
|
|
|
def classification
|
|
|
|
"asset"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-08-23 08:47:08 -04:00
|
|
|
def area
|
|
|
|
Measurement.new(area_value, area_unit) if area_value.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def purchase_price
|
|
|
|
first_valuation_amount
|
|
|
|
end
|
|
|
|
|
|
|
|
def trend
|
2025-02-21 11:57:59 -05:00
|
|
|
Trend.new(current: account.balance_money, previous: first_valuation_amount)
|
2024-10-18 18:25:17 -04:00
|
|
|
end
|
|
|
|
|
2025-07-03 09:33:07 -04:00
|
|
|
def balance_display_name
|
|
|
|
"market value"
|
|
|
|
end
|
|
|
|
|
|
|
|
def opening_balance_display_name
|
|
|
|
"original purchase price"
|
|
|
|
end
|
|
|
|
|
2024-08-23 08:47:08 -04:00
|
|
|
private
|
|
|
|
def first_valuation_amount
|
2025-04-14 11:40:34 -04:00
|
|
|
account.entries.valuations.order(:date).first&.amount_money || account.balance_money
|
2024-08-23 08:47:08 -04:00
|
|
|
end
|
2024-06-20 07:26:25 -04:00
|
|
|
end
|