mirror of
https://github.com/Gnucash/gnucash.git
synced 2024-11-30 20:54:08 -06:00
[report-utilities] gnc:account-get-balances-at-dates adjustment
(Release Note - developer section)
Modification to gnc:account-get-balances-at-dates.
formerly it would accept an optional #:ignore-closing? boolean to skip
closing transactions.
it would be more general to accept a #:split->amount function whose
default is xaccSplitGetAmount. calling (split->amount split) should
return amount from the split. if the function returns #f, it
effectively skips the split. this will allow a more general
account-balance list accumulator, allowing novel balance strategies
e.g. split->amount may test split void status and return the split
xaccSplitVoidFormerAmount, test description/memo and return an amount
depending on description contents, or test the split and return 1 or 0
which will return a tally of splits.
the direct equivalence for the previous #:ignore-closing? keyword
argument is #:split->amount (lambda (s) (and (not (xaccTransGetIsClosingTxn
(xaccSplitGetParent s))) (xaccSplitGetAmount s)))
NOTE: the modifications to category-barchart.scm and net-charts.scm
will use the #:split->amount kwarg as well.
This function is extensively tested in the commit
53cab269f4
This commit is contained in:
parent
11083d6052
commit
b1cd7393b6
@ -432,9 +432,16 @@ flawed. see report-utilities.scm. please update reports.")
|
||||
;; a list of balances along the way at dates specified in dates-list.
|
||||
;; in: account
|
||||
;; dates-list (list of time64)
|
||||
;; ignore-closing? - if #true, will skip closing entries
|
||||
;; split->amount - an unary lambda. calling (split->amount split)
|
||||
;; returns a number, or #f which effectively skips the split.
|
||||
;; out: (list bal0 bal1 ...), each entry is a gnc-monetary object
|
||||
(define* (gnc:account-get-balances-at-dates account dates-list #:key ignore-closing?)
|
||||
;;
|
||||
;; NOTE a prior incarnation accepted a #:ignore-closing? boolean
|
||||
;; keyword which can be reproduced via #:split->amount (lambda (s)
|
||||
;; (and (not (xaccTransGetIsClosingTxn (xaccSplitGetParent s)))
|
||||
;; (xaccSplitGetAmount s)))
|
||||
(define* (gnc:account-get-balances-at-dates
|
||||
account dates-list #:key (split->amount xaccSplitGetAmount))
|
||||
(define (amount->monetary bal)
|
||||
(gnc:make-gnc-monetary (xaccAccountGetCommodity account) bal))
|
||||
(let loop ((splits (xaccAccountGetSplitList account))
|
||||
@ -460,10 +467,7 @@ flawed. see report-utilities.scm. please update reports.")
|
||||
(else
|
||||
(let* ((this (car splits))
|
||||
(rest (cdr splits))
|
||||
(currentbal (if (and ignore-closing?
|
||||
(xaccTransGetIsClosingTxn (xaccSplitGetParent this)))
|
||||
currentbal
|
||||
(+ (xaccSplitGetAmount this) currentbal)))
|
||||
(currentbal (+ (or (split->amount this) 0) currentbal))
|
||||
(next (and (pair? rest) (car rest))))
|
||||
|
||||
(cond
|
||||
|
@ -361,12 +361,18 @@ developing over time"))
|
||||
(define account-balances-alist
|
||||
(map
|
||||
(lambda (acc)
|
||||
(cons acc
|
||||
(map
|
||||
(if (reverse-balance? acc) gnc:monetary-neg identity)
|
||||
(gnc:account-get-balances-at-dates
|
||||
acc dates-list
|
||||
#:ignore-closing? (gnc:account-is-inc-exp? acc)))))
|
||||
(let ((ignore-closing? (not (gnc:account-is-inc-exp? acc))))
|
||||
(cons acc
|
||||
(map
|
||||
(if (reverse-balance? acc) gnc:monetary-neg identity)
|
||||
(gnc:account-get-balances-at-dates
|
||||
acc dates-list
|
||||
#:split->amount
|
||||
(lambda (s)
|
||||
(and (or ignore-closing?
|
||||
(not (xaccTransGetIsClosingTxn
|
||||
(xaccSplitGetParent s))))
|
||||
(xaccSplitGetAmount s))))))))
|
||||
accounts))
|
||||
|
||||
;; Creates the <balance-list> to be used in the function
|
||||
|
@ -251,10 +251,16 @@
|
||||
;; gets an account alist balances
|
||||
;; output: (list acc bal0 bal1 bal2 ...)
|
||||
(define (account->balancelist account)
|
||||
(cons account
|
||||
(gnc:account-get-balances-at-dates
|
||||
account dates-list
|
||||
#:ignore-closing? (gnc:account-is-inc-exp? account))))
|
||||
(let ((ignore-closing? (not (gnc:account-is-inc-exp? account))))
|
||||
(cons account
|
||||
(gnc:account-get-balances-at-dates
|
||||
account dates-list
|
||||
#:split->amount
|
||||
(lambda (s)
|
||||
(and (or ignore-closing?
|
||||
(not (xaccTransGetIsClosingTxn
|
||||
(xaccSplitGetParent s))))
|
||||
(xaccSplitGetAmount s)))))))
|
||||
|
||||
;; This calculates the balances for all the 'account-balances' for
|
||||
;; each element of the list 'dates'. Uses the collector->monetary
|
||||
|
Loading…
Reference in New Issue
Block a user