1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-05 13:35:21 +02:00

Set minimum supported date for account entries (#1023)

* Set minimum supported date for account entries

* Fix validation proc

* Fix date input in system tests
This commit is contained in:
Zach Gollwitzer 2024-07-26 10:47:27 -04:00 committed by GitHub
parent 701e17829d
commit 76dd5e57fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 16 additions and 4 deletions

View file

@ -11,6 +11,7 @@ class Account::Entry < ApplicationRecord
validates :date, :amount, :currency, presence: true
validates :date, uniqueness: { scope: [ :account_id, :entryable_type ] }, if: -> { account_valuation? }
validates :date, comparison: { greater_than: -> { min_supported_date } }
validate :trade_valid?, if: -> { account_trade? }
scope :chronological, -> { order(:date, :created_at) }
@ -64,6 +65,11 @@ class Account::Entry < ApplicationRecord
end
class << self
# arbitrary cutoff date to avoid expensive sync operations
def min_supported_date
10.years.ago.to_date
end
def daily_totals(entries, currency, period: Period.last_30_days)
# Sum spending and income for each day in the period with the given currency
select(