mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 12:04:08 +00: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:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user