mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-23 07:09:39 +02:00
* Add nice formatting for subtypes on account list * Fix rubocop linting errors * Implement better mapping * Fix rubocop linting * Add short and long versions of subtypes * Simplify subtype reference Co-authored-by: Zach Gollwitzer <zach.gollwitzer@gmail.com> Signed-off-by: Alex Hatzenbuhler <hatz@hey.com> * Simplify reference logic, add a small test * Fix test * Fix tests --------- Signed-off-by: Alex Hatzenbuhler <hatz@hey.com> Co-authored-by: Zach Gollwitzer <zach.gollwitzer@gmail.com>
49 lines
1.2 KiB
Ruby
49 lines
1.2 KiB
Ruby
class Property < ApplicationRecord
|
|
include Accountable
|
|
|
|
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
|
|
|
|
has_one :address, as: :addressable, dependent: :destroy
|
|
|
|
accepts_nested_attributes_for :address
|
|
|
|
attribute :area_unit, :string, default: "sqft"
|
|
|
|
class << self
|
|
def icon
|
|
"home"
|
|
end
|
|
|
|
def color
|
|
"#06AED4"
|
|
end
|
|
|
|
def classification
|
|
"asset"
|
|
end
|
|
end
|
|
|
|
def area
|
|
Measurement.new(area_value, area_unit) if area_value.present?
|
|
end
|
|
|
|
def purchase_price
|
|
first_valuation_amount
|
|
end
|
|
|
|
def trend
|
|
Trend.new(current: account.balance_money, previous: first_valuation_amount)
|
|
end
|
|
|
|
private
|
|
def first_valuation_amount
|
|
account.entries.valuations.order(:date).first&.amount_money || account.balance_money
|
|
end
|
|
end
|