Files
sure/app/models/property.rb
Abhinav Dhiman 139c89d0f4 feat(investments): add India investment subtypes and exchange support (#1659)
* feat(investments): add India investment subtypes and exchange support

* fix(yahoo-finance): scope Indian exchange de-duplication per company instead of globally

Resolves feedback from Codex and CodeRabbit on #1413.

prefer_indian_exchange previously collapsed all Indian securities into a
single entry, silently dropping unrelated tickers. Now groups Indian
listings by name and only de-duplicates within each group, so distinct
companies (e.g. Reliance and Infosys) are preserved while NSE/BSE
dual-listings still prefer NSE.

- Derive India subtype keys dynamically from Investment::SUBTYPES in tests
- Fix missing keyword arguments in Security.new test calls

* refactor(yahoo-finance): generalize exchange config and dual-listing de-duplication

Replaces hardcoded Indian exchange logic with a declarative EXCHANGE_CONFIG
hash that maps ISO MIC codes to Yahoo-specific settings (symbol suffix,
default currency, dual-listing group, and preference rank). This makes
adding new markets a one-line hash entry instead of scattered conditionals.

* fix(yahoo-finance): normalize security names for dual-listing de-duplication

* fix(yahoo-finance): skip dual-listing de-duplication when filtering by exchange

* fix: address PR review feedback for India market support

- fix cache key mismatch in fetch_security_price by normalizing symbol before building cache key
- remove dead YAHOO_EXCHANGE_CURRENCY constant
- tighten normalize_symbol guard to use end_with?(suffix) instead of include?('.')
- remove misleading '# India' comment from Property::SUBTYPES
- remove 'rented' property subtype in favor of 'investment_property'
- rename 'demat' to 'indian_stocks' for clarity
- add INR to CURRENCY_REGION_MAP so India appears first for INR users
- add dotted-symbol regression test for normalize_symbol

* fix(investments): rename 'demat' subtype to 'indian_stocks' and remove trailing comma
2026-05-05 01:04:29 +02:00

62 lines
1.6 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" },
"apartment" => { short: "Apartment", long: "Apartment" },
"plot" => { short: "Plot", long: "Plot / Land" },
"commercial" => { short: "Commercial", long: "Commercial Property" },
"agri_land" => { short: "Agri Land", long: "Agricultural Land" }
}.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