Add account balance anchors
This commit is contained in:
@@ -291,6 +291,20 @@ func Validate(d Dataset) error {
|
||||
if a.Kind != "" && a.Kind != AccountCash && a.Kind != AccountInvestment {
|
||||
return fmt.Errorf("account %q: kind must be %q or %q", a.ID, AccountCash, AccountInvestment)
|
||||
}
|
||||
// An anchor is one figure and the day it was true: neither half means
|
||||
// anything alone, and anchoring an investment account would mask an
|
||||
// incomplete broker history instead of exposing it.
|
||||
if (a.AnchorBalance == "") != (a.AnchorDate == "") {
|
||||
return fmt.Errorf("account %q: an anchor needs both a balance and its date", a.ID)
|
||||
}
|
||||
if a.AnchorDate != "" {
|
||||
if a.Investing() {
|
||||
return fmt.Errorf("account %q: a balance anchor belongs to a cash account; a broker export carries its complete history", a.ID)
|
||||
}
|
||||
if _, err := a.AnchorBalance.Minor(); err != nil || !validDate(a.AnchorDate) {
|
||||
return fmt.Errorf("account %q: invalid anchor balance or date", a.ID)
|
||||
}
|
||||
}
|
||||
accounts[a.ID] = a
|
||||
}
|
||||
for _, c := range d.Categories {
|
||||
|
||||
Reference in New Issue
Block a user