gnucash stable: Multiple changes pushed
Christopher Lam
clam at code.gnucash.org
Mon Jun 29 07:20:25 EDT 2026
Updated via https://github.com/Gnucash/gnucash/commit/c3a74e6a (commit)
via https://github.com/Gnucash/gnucash/commit/6070bac8 (commit)
from https://github.com/Gnucash/gnucash/commit/b6e4672a (commit)
commit c3a74e6a80186b4bdbba7d5a37879f2a757c22cc
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sun Jun 28 11:08:41 2026 +0800
[investment-lots] use faster gnc-account-foreach-split-between-dates
to generate list of splits
diff --git a/gnucash/report/reports/standard/investment-lots.scm b/gnucash/report/reports/standard/investment-lots.scm
index 7d38425637..58d2067127 100644
--- a/gnucash/report/reports/standard/investment-lots.scm
+++ b/gnucash/report/reports/standard/investment-lots.scm
@@ -878,20 +878,15 @@ Returns #t if held >= long-term-years, #f otherwise."
;; before from-date are also included (needed to calculate running
;; balance and basis during the report date window).
(define (get-all-splits account)
- (let ((query (qof-query-create-for-splits)))
- (qof-query-set-book query (gnc-get-current-book))
- (xaccQueryAddClearedMatch query
- (logand CLEARED-ALL (lognot CLEARED-VOIDED)) QOF-QUERY-AND)
- (xaccQueryAddSingleAccountMatch query account QOF-QUERY-AND)
- (xaccQueryAddDateMatchTT query
- #f ; use_start.
- 0 ; start. Note: Intentionally not using from-date.
- #t ; use-end
- to-date QOF-QUERY-AND)
- (let ((result (qof-query-run query)))
- (qof-query-destroy query)
- (gnc:debug (format #f "Found ~a splits." (length result)))
- result)))
+ (let ((splits '()) (len 0))
+ (gnc-account-foreach-split-between-dates
+ account #f to-date #f
+ (lambda (split)
+ (unless (xaccTransGetVoidStatus (xaccSplitGetParent split))
+ (set! len (1+ len))
+ (set! splits (cons split splits)))))
+ (gnc:debug "Found " len " splits.")
+ (reverse! splits)))
;; Returns a pair where the first item is a list of lots for the given
;; splits. The second item is the number of splits that are not assigned
commit 6070bac87b39172f2e3911fbd72a9273c03daa10
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Sun Jun 28 00:52:59 2026 +0800
[report-utilities.scm] convert account value accumulator to c++
diff --git a/bindings/engine.i b/bindings/engine.i
index 8e9bce0d6e..5a6d3e4b40 100644
--- a/bindings/engine.i
+++ b/bindings/engine.i
@@ -84,6 +84,10 @@ SCM gnc_account_accumulate_to_dates (const Account *acc, SCM dates,
AccountVec gnc_accounts_and_all_descendants (AccountVec accounts);
+void gnc_account_foreach_split_between_dates (const Account* account,
+ SCM start_date, SCM end_date,
+ bool include_children, SCM scm_cb);
+
extern "C"
{
SCM scm_init_sw_engine_module (void);
@@ -240,6 +244,31 @@ gnc_accounts_and_all_descendants (AccountVec accounts)
return AccountVec (accset.begin(), accset.end());
}
+void
+gnc_account_foreach_split_between_dates (const Account* account,
+ SCM start_date, SCM end_date,
+ bool include_children, SCM scm_cb)
+{
+ std::optional<time64> start, end;
+ if (scm_is_exact_integer (start_date)) start = scm_to_int64 (start_date);
+ if (scm_is_exact_integer (end_date)) end = scm_to_int64 (end_date);
+ auto maybe_call = [&](const Split* s)
+ {
+ if (!start || *start <= xaccTransGetDate (xaccSplitGetParent (s)))
+ scm_call_1 (scm_cb, gnc_split_to_scm (s));
+ };
+ std::function<void(const Account*)> scan_account;
+ if (end)
+ scan_account = [end, maybe_call](auto acc)
+ { gnc_account_foreach_split_until_date (acc, *end, maybe_call); };
+ else
+ scan_account = [maybe_call](auto acc)
+ { gnc_account_foreach_split (acc, maybe_call); };
+ scan_account (account);
+ if (include_children)
+ gnc_account_foreach_descendant (account, scan_account);
+}
+
%}
/* NB: The object ownership annotations should already cover all the
diff --git a/gnucash/report/report-utilities.scm b/gnucash/report/report-utilities.scm
index b8bac38efe..eb61a555f5 100644
--- a/gnucash/report/report-utilities.scm
+++ b/gnucash/report/report-utilities.scm
@@ -525,34 +525,13 @@
;; are returned in a commodity collector.
(define (gnc:account-get-comm-value-interval account start-date end-date
include-children?)
- (let ((value-collector (gnc:make-commodity-collector))
- (query (qof-query-create-for-splits))
- (accounts (cons account
- (if include-children?
- (gnc-account-get-descendants account)
- '()))))
-
- ;; Build a query to find all splits between the indicated dates.
- (qof-query-set-book query (gnc-get-current-book))
- (xaccQueryAddAccountMatch query accounts
- QOF-GUID-MATCH-ANY
- QOF-QUERY-AND)
- (xaccQueryAddDateMatchTT query
- (and start-date #t) (or start-date 0)
- (and end-date #t) (or end-date 0)
- QOF-QUERY-AND)
-
- ;; Get the query results.
- (let ((splits (qof-query-run query)))
- (qof-query-destroy query)
- ;; Add the "value" of each split returned (which is measured
- ;; in the transaction currency).
- (for-each
- (lambda (split)
- (value-collector 'add
- (xaccTransGetCurrency (xaccSplitGetParent split))
- (xaccSplitGetValue split)))
- splits))
+ (let ((value-collector (gnc:make-commodity-collector)))
+ (gnc-account-foreach-split-between-dates
+ account start-date end-date include-children?
+ (lambda (split)
+ (value-collector 'add
+ (xaccTransGetCurrency (xaccSplitGetParent split))
+ (xaccSplitGetValue split))))
value-collector))
;; Calculate the balance of the account in terms of "value" (rather
Summary of changes:
bindings/engine.i | 29 ++++++++++++++++++
gnucash/report/report-utilities.scm | 35 +++++-----------------
.../report/reports/standard/investment-lots.scm | 23 ++++++--------
3 files changed, 45 insertions(+), 42 deletions(-)
More information about the gnucash-changes
mailing list