gnucash maint: [report-utilities.scm] gnc:budget-account-get-rolledup-net bugfix

Christopher Lam clam at code.gnucash.org
Thu Jan 13 10:45:45 EST 2022


Updated	 via  https://github.com/Gnucash/gnucash/commit/ebfe0a47 (commit)
	from  https://github.com/Gnucash/gnucash/commit/b1176b46 (commit)



commit ebfe0a4716e3bfde6d4da0c69e0d5db34532c4d6
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Thu Jan 13 23:06:15 2022 +0800

    [report-utilities.scm] gnc:budget-account-get-rolledup-net bugfix
    
    This function accepts start-period and end-period, either/both can
    be #f which signifies budget start and end respectively.
    
    If end-period of #f, numperiods was then defined
    as (budget->num_periods + 1) which was incorrect.
    
    Bugfix and refactor to be cleaner.

diff --git a/gnucash/report/report-utilities.scm b/gnucash/report/report-utilities.scm
index cbb87301b..126e2aaae 100644
--- a/gnucash/report/report-utilities.scm
+++ b/gnucash/report/report-utilities.scm
@@ -940,14 +940,12 @@ query instead.")
 ;;
 ;; Returns a gnc-numeric value
 (define (gnc:budget-account-get-rolledup-net budget account start-period end-period)
-  (let* ((start (or start-period 0))
-         (end (or end-period (gnc-budget-get-num-periods budget)))
-         (numperiods (- end start -1)))
-  (apply +
-         (map
-          (lambda (period)
-            (gnc:get-account-period-rolledup-budget-value budget account period))
-          (iota numperiods start 1)))))
+  (define end (or end-period (1- (gnc-budget-get-num-periods budget))))
+  (let lp ((period (or start-period 0)) (sum 0))
+    (cond
+     ((> period end) sum)
+     (else (lp (1+ period) (+ sum (gnc:get-account-period-rolledup-budget-value
+                                   budget account period)))))))
 
 ;; ***************************************************************************
 ;; The following 3 functions belong together



Summary of changes:
 gnucash/report/report-utilities.scm | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)



More information about the gnucash-changes mailing list