mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-05 05:25:24 +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:
parent
701e17829d
commit
76dd5e57fb
6 changed files with 16 additions and 4 deletions
|
@ -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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue