1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-02 20:15:22 +02:00

Remove redundant amount validation from Account Holding model

This commit is contained in:
Josh Pigford 2025-02-07 10:58:41 -06:00
parent cf23673003
commit 60925bd16c

View file

@ -8,7 +8,6 @@ class Account::Holding < ApplicationRecord
validates :qty, :currency, :date, :price, :amount, presence: true
validates :qty, :price, :amount, numericality: { greater_than_or_equal_to: 0 }
validate :amount_matches_qty_and_price
scope :chronological, -> { order(:date) }
scope :for, ->(security) { where(security_id: security).order(:date) }
@ -64,13 +63,4 @@ class Account::Holding < ApplicationRecord
current: amount_money,
previous: start_amount
end
def amount_matches_qty_and_price
return if qty.blank? || price.blank? || amount.blank?
expected_amount = qty * price
return if amount == expected_amount
errors.add(:amount, "must equal qty * price (expected: #{expected_amount})")
end
end