mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-04 04:55:20 +02:00
Remove redundant amount validation from Account Holding model
This commit is contained in:
parent
cf23673003
commit
60925bd16c
1 changed files with 0 additions and 10 deletions
|
@ -8,7 +8,6 @@ class Account::Holding < ApplicationRecord
|
||||||
|
|
||||||
validates :qty, :currency, :date, :price, :amount, presence: true
|
validates :qty, :currency, :date, :price, :amount, presence: true
|
||||||
validates :qty, :price, :amount, numericality: { greater_than_or_equal_to: 0 }
|
validates :qty, :price, :amount, numericality: { greater_than_or_equal_to: 0 }
|
||||||
validate :amount_matches_qty_and_price
|
|
||||||
|
|
||||||
scope :chronological, -> { order(:date) }
|
scope :chronological, -> { order(:date) }
|
||||||
scope :for, ->(security) { where(security_id: security).order(:date) }
|
scope :for, ->(security) { where(security_id: security).order(:date) }
|
||||||
|
@ -64,13 +63,4 @@ class Account::Holding < ApplicationRecord
|
||||||
current: amount_money,
|
current: amount_money,
|
||||||
previous: start_amount
|
previous: start_amount
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue