[report-utilities] gnc:account-accumulate-at-dates: specify default elt

if acc has no splits before report-date, the nosplit->elt will specify
the default value to be inserted in the result list.

e.g. consider:

dates are (date1 date2 date3 date4 date5)
account has splits starting after date2:

(gnc:account-accumulate-at-dates account dates
 #:split->elt (const 'yea) #:nosplit->elt 'nay)

results in '(nay nay yea yea yea)
This commit is contained in:
Christopher Lam
2019-11-22 23:28:33 +08:00
parent 17d3938866
commit 68b0abdfa6
2 changed files with 13 additions and 1 deletions

View File

@@ -483,6 +483,8 @@ flawed. see report-utilities.scm. please update reports.")
;; of split->elt results along the way at dates specified in dates.
;; in: acc - account
;; dates - a list of time64 -- it will be sorted
;; nosplit->elt - if report-dates occur *before* earliest split, the
;; result list will be padded with this value
;; split->date - an unary lambda. result to compare with dates list.
;; split->elt - an unary lambda. it will be called successfully for each
;; split in the account until the last date. the result
@@ -490,14 +492,16 @@ flawed. see report-utilities.scm. please update reports.")
;; xaccSplitGetBalance makes it similar to
;; gnc:account-get-balances-at-dates.
;; out: (list elt0 elt1 ...), each entry is the result of split->elt
;; or nosplit->elt
(define* (gnc:account-accumulate-at-dates
acc dates #:key
(nosplit->elt #f)
(split->date (compose xaccTransGetDate xaccSplitGetParent))
(split->elt xaccSplitGetBalance))
(let lp ((splits (xaccAccountGetSplitList acc))
(dates (sort dates <))
(result '())
(last-result #f))
(last-result nosplit->elt))
(match dates
;; end of dates. job done!

View File

@@ -709,6 +709,14 @@
'(#f #f #f 10)
(gnc:account-accumulate-at-dates bank3 dates))
(test-equal "1 txn in late slot, tests #:nosplit->elt"
'(x x x 10)
(gnc:account-accumulate-at-dates bank3 dates #:nosplit->elt 'x))
(test-equal "1 txn in late slot, tests #:split->elt"
'(#f #f #f y)
(gnc:account-accumulate-at-dates bank3 dates #:split->elt (const 'y)))
(test-equal "1 txn in early slot"
'(#f 10 10 10)
(gnc:account-accumulate-at-dates bank4 dates)))