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

Checkpoint

This commit is contained in:
Zach Gollwitzer 2025-07-08 10:25:16 -04:00
parent 15f8d827b5
commit b7acef1e7a
9 changed files with 56 additions and 23 deletions

View file

@ -11,6 +11,7 @@ class Valuation < ApplicationRecord
# Each account can have at most 1 opening anchor and 1 current anchor. All valuations between these anchors should
# be either "recon" or "snapshot". This ensures we can reliably construct the account balance history solely from Entries.
validate :unique_anchor_per_account, if: -> { opening_anchor? || current_anchor? }
validate :manual_accounts_cannot_have_current_anchor
private
def unique_anchor_per_account
@ -26,4 +27,12 @@ class Valuation < ApplicationRecord
errors.add(:kind, "#{kind.humanize} already exists for this account")
end
end
def manual_accounts_cannot_have_current_anchor
return unless entry&.account
if entry.account.unlinked? && current_anchor?
errors.add(:kind, "Manual accounts cannot have a current anchor")
end
end
end