[reports] use new api gnc:account-accumulate-at-dates

queries xaccSplitGetNoclosingBalance (which is a pointer dereference)
instead of a more complex conditional-based snippet for split->amount,
should be faster.

The category-barchart change will choose the appropriate split->elt
function according to the account type. This is more efficient than
the old split->amount function which includes a conditional.

Note we don't need to test for account being income/expense:
asset/liability accounts do not have Closing transactions. Therefore
we can use xaccSplitGetNoclosingBalance for splits from any account
type.
This commit is contained in:
Christopher Lam 2019-11-22 23:38:22 +08:00
parent 68b0abdfa6
commit 101cc91698
2 changed files with 18 additions and 19 deletions

View File

@ -355,18 +355,19 @@ developing over time"))
(define account-balances-alist
(map
(lambda (acc)
(let ((ignore-closing? (not (gnc:account-is-inc-exp? acc))))
(let* ((comm (xaccAccountGetCommodity acc))
(split->elt (if (reverse-balance? acc)
(lambda (s)
(gnc:make-gnc-monetary
comm (- (xaccSplitGetNoclosingBalance s))))
(lambda (s)
(gnc:make-gnc-monetary
comm (xaccSplitGetNoclosingBalance s))))))
(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))))))))
(gnc:account-accumulate-at-dates
acc dates-list
#:split->elt split->elt
#:nosplit->elt (gnc:make-gnc-monetary comm 0)))))
;; all selected accounts (of report-specific type), *and*
;; their descendants (of any type) need to be scanned.
(gnc:accounts-and-all-descendants accounts)))

View File

@ -251,16 +251,14 @@
;; gets an account alist balances
;; output: (list acc bal0 bal1 bal2 ...)
(define (account->balancelist account)
(let ((ignore-closing? (not (gnc:account-is-inc-exp? account))))
(let ((comm (xaccAccountGetCommodity account)))
(cons account
(gnc:account-get-balances-at-dates
(gnc:account-accumulate-at-dates
account dates-list
#:split->amount
(lambda (s)
(and (or ignore-closing?
(not (xaccTransGetIsClosingTxn
(xaccSplitGetParent s))))
(xaccSplitGetAmount s)))))))
#:split->elt (lambda (s)
(gnc:make-gnc-monetary
comm (xaccSplitGetNoclosingBalance s)))
#:nosplit->elt (gnc:make-gnc-monetary comm 0)))))
;; This calculates the balances for all the 'account-balances' for
;; each element of the list 'dates'. Uses the collector->monetary