1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-22 06:39:39 +02:00
Maybe/app/models/security.rb
Zach Gollwitzer fa0248056d
Show UI warning to user when they need provider data but have not setup Synth yet (#1926)
* Simplify provider concerns

* Update tests

* Add UI warning for missing Synth key if family requires external data
2025-02-28 11:35:10 -05:00

38 lines
947 B
Ruby

class Security < ApplicationRecord
include Provided
before_save :upcase_ticker
has_many :trades, dependent: :nullify, class_name: "Account::Trade"
has_many :prices, dependent: :destroy
validates :ticker, presence: true
validates :ticker, uniqueness: { scope: :exchange_operating_mic, case_sensitive: false }
def current_price
@current_price ||= Security::Price.find_price(security: self, date: Date.current)
return nil if @current_price.nil?
Money.new(@current_price.price, @current_price.currency)
end
def to_combobox_option
SynthComboboxOption.new(
symbol: ticker,
name: name,
logo_url: logo_url,
exchange_acronym: exchange_acronym,
exchange_operating_mic: exchange_operating_mic,
exchange_country_code: country_code
)
end
def has_prices?
exchange_operating_mic.present?
end
private
def upcase_ticker
self.ticker = ticker.upcase
end
end