[report-utilities] gnc:accounts-get-commodities more efficient

more efficient function
This commit is contained in:
Christopher Lam 2019-07-20 19:05:41 +08:00
parent 273ae720cc
commit 38b2d4708b
2 changed files with 38 additions and 6 deletions

View File

@ -129,11 +129,12 @@ construct gnc:make-gnc-monetary and use gnc:monetary->string instead.")
;; 'accounts', excluding the 'exclude-commodity'.
(define (gnc:accounts-get-commodities accounts exclude-commodity)
(delete exclude-commodity
(delete-duplicates
(sort (map xaccAccountGetCommodity accounts)
(lambda (a b)
(string<? (or (gnc-commodity-get-mnemonic a) "")
(or (gnc-commodity-get-mnemonic b) "")))))))
(sort-and-delete-duplicates
(map xaccAccountGetCommodity accounts)
(lambda (a b)
(string<? (gnc-commodity-get-mnemonic a)
(gnc-commodity-get-mnemonic b)))
gnc-commodity-equiv)))
;; Returns the depth of the current account hierarchy, that is, the

View File

@ -23,6 +23,7 @@
(test-get-account-balances)
(test-monetary-adders)
(test-make-stats-collector)
(test-utility-functions)
(test-end "report-utilities"))
(define (NDayDelta t64 n)
@ -251,7 +252,8 @@
(list "Income" (list (cons 'type ACCT-TYPE-INCOME)))
(list "Income-GBP" (list (cons 'type ACCT-TYPE-INCOME)
(cons 'commodity (mnemonic->commodity "GBP"))))
(list "Expenses" (list (cons 'type ACCT-TYPE-EXPENSE)))
(list "Expenses" (list (cons 'type ACCT-TYPE-EXPENSE))
(list "Fuel"))
(list "Liabilities" (list (cons 'type ACCT-TYPE-LIABILITY)))
(list "Equity" (list (cons 'type ACCT-TYPE-EQUITY)))
))
@ -482,6 +484,35 @@
(gnc:get-assoc-account-balances-total account-balances)))))
(teardown)))
(define (test-utility-functions)
(define (account-lookup str)
(gnc-account-lookup-by-name
(gnc-book-get-root-account (gnc-get-current-book))
str))
(test-group-with-cleanup "utility functions"
(create-test-data)
(test-equal "gnc:accounts-get-commodities"
(list "GBP" "USD")
(map gnc-commodity-get-mnemonic
(gnc:accounts-get-commodities (gnc-account-get-descendants-sorted
(gnc-get-current-root-account))
#f)))
(test-equal "gnc:get-current-account-tree-depth"
5
(gnc:get-current-account-tree-depth))
(test-equal "gnc:acccounts-get-all-subaccounts"
(list (account-lookup "Fuel")
(account-lookup "GBP Savings"))
(gnc:acccounts-get-all-subaccounts
(list (account-lookup "Expenses")
(account-lookup "GBP Bank"))))
(teardown)))
(define (test-monetary-adders)
(define (monetary->pair mon)
(let ((comm (gnc:gnc-monetary-commodity mon))