1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 05:09:38 +02:00
Maybe/app/models/property.rb
Zach Gollwitzer 662f2c04ce
Some checks failed
Publish Docker image / ci (push) Has been cancelled
Publish Docker image / Build docker image (push) Has been cancelled
Multi-step account forms + clearer balance editing (#2427)
* Initial multi-step property form

* Improve form structure, add optional tooltip help icons to form fields

* Add basic inline alert component

* Clean up and improve property form lifecycle

* Implement Account status concept

* Lint fixes

* Remove whitespace

* Balance editing, scope updates for account

* Passing tests

* Fix brakeman warning

* Remove stale columns

* data constraint tweaks

* Redundant property
2025-07-03 09:33:07 -04:00

57 lines
1.3 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
def balance_display_name
"market value"
end
def opening_balance_display_name
"original purchase price"
end
private
def first_valuation_amount
account.entries.valuations.order(:date).first&.amount_money || account.balance_money
end
end