mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
[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:
parent
68b0abdfa6
commit
101cc91698
@ -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)))
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user