[report-utilities][API] gnc:accounts-and-all-descendants

return a list of accounts and their descendant accounts
This commit is contained in:
Christopher Lam 2019-07-20 19:17:56 +08:00
parent 38b2d4708b
commit ae4b7e1582
3 changed files with 19 additions and 0 deletions

View File

@ -686,6 +686,7 @@
(export gnc:account-get-type-string-plural)
(export gnc:accounts-get-commodities)
(export gnc:get-current-account-tree-depth)
(export gnc:accounts-and-all-descendants)
(export gnc:acccounts-get-all-subaccounts)
(export gnc:make-stats-collector) ;deprecated
(export gnc:make-drcr-collector) ;deprecated

View File

@ -149,6 +149,15 @@ construct gnc:make-gnc-monetary and use gnc:monetary->string instead.")
(append-map gnc-account-get-descendants-sorted
accountlist))
;; Return accountslist *and* their descendant accounts
(define (gnc:accounts-and-all-descendants accountslist)
(sort-and-delete-duplicates
(append accountslist
(gnc:acccounts-get-all-subaccounts accountslist))
(lambda (a b)
(string<? (gnc-account-get-full-name a) (gnc-account-get-full-name b)))
equal?))
;;; Here's a statistics collector... Collects max, min, total, and makes
;;; it easy to get at the mean.

View File

@ -511,6 +511,15 @@
(list (account-lookup "Expenses")
(account-lookup "GBP Bank"))))
(test-equal "gnc:accounts-and-all-descendants"
(list (account-lookup "GBP Bank")
(account-lookup "GBP Savings")
(account-lookup "Expenses")
(account-lookup "Fuel"))
(gnc:accounts-and-all-descendants
(list (account-lookup "Expenses")
(account-lookup "GBP Bank"))))
(teardown)))
(define (test-monetary-adders)