2024-06-20 07:26:25 -04:00
|
|
|
class Property < ApplicationRecord
|
|
|
|
include Accountable
|
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"
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2024-10-18 14:37:42 -04:00
|
|
|
def color
|
|
|
|
"#06AED4"
|
|
|
|
end
|
|
|
|
|
2024-10-18 18:25:17 -04:00
|
|
|
def mode_required?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2024-08-23 08:47:08 -04:00
|
|
|
private
|
|
|
|
def first_valuation_amount
|
|
|
|
account.entries.account_valuations.order(:date).first&.amount_money || account.balance_money
|
|
|
|
end
|
2024-06-20 07:26:25 -04:00
|
|
|
end
|