Skip to content

Commit f95136d

Browse files
[trial-balance] speedup by retrieving closing/adjusting splits once
only 2 qof-query, instead of 2 per account
1 parent a3ae97c commit f95136d

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

gnucash/report/standard-reports/trial-balance.scm

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -763,32 +763,37 @@
763763
;; it stores a two-element list of commodity collectors:
764764
;; (list debit-collector credit-collector)
765765
(let* ((row 0)
766-
(rows (gnc:html-acct-table-num-rows acct-table)))
766+
(rows (gnc:html-acct-table-num-rows acct-table))
767+
(closing-splits
768+
(gnc:account-get-trans-type-splits-interval
769+
all-accounts (list (list 'str closing-str)
770+
(list 'cased closing-cased)
771+
(list 'regexp closing-regexp)
772+
(list 'closing #t))
773+
start-date end-date))
774+
(adjusting-splits
775+
(gnc:account-get-trans-type-splits-interval
776+
all-accounts (list (list 'str adjusting-str)
777+
(list 'cased adjusting-cased)
778+
(list 'regexp adjusting-regexp))
779+
start-date end-date)))
780+
781+
(define (sum-account-splits account splits)
782+
(let ((total (gnc:make-commodity-collector))
783+
(comm (xaccAccountGetCommodity account)))
784+
(for-each
785+
(lambda (s) (total 'add comm (xaccSplitGetAmount s)))
786+
(filter (lambda (s) (equal? (xaccSplitGetAccount s) account))
787+
splits))
788+
total))
767789

768790
(while (< row rows)
769791
(let* ((env (gnc:html-acct-table-get-row-env acct-table row))
770792
(acct (get-val env 'account))
771793
(group (list acct))
772794
(curr-bal (get-val env 'account-bal))
773-
(closing
774-
(gnc:account-get-trans-type-balance-interval-with-closing
775-
group
776-
(list (list 'str closing-str)
777-
(list 'cased closing-cased)
778-
(list 'regexp closing-regexp)
779-
(list 'closing #t)
780-
)
781-
start-date end-date
782-
))
783-
(adjusting
784-
(gnc:account-get-trans-type-balance-interval-with-closing
785-
group
786-
(list (list 'str adjusting-str)
787-
(list 'cased adjusting-cased)
788-
(list 'regexp adjusting-regexp)
789-
)
790-
start-date end-date
791-
))
795+
(closing (sum-account-splits acct closing-splits))
796+
(adjusting (sum-account-splits acct adjusting-splits))
792797
(is? (member acct all-is-accounts))
793798
(ga-or-is? (or (member acct all-ga-accounts) is?))
794799
(pos-adjusting

0 commit comments

Comments
 (0)