diff --git a/gnucash/report/eguile-utilities.scm b/gnucash/report/eguile-utilities.scm index 8058d9ddbb5..09bb27a50e6 100644 --- a/gnucash/report/eguile-utilities.scm +++ b/gnucash/report/eguile-utilities.scm @@ -46,11 +46,13 @@ ;; 'Safe' versions of cdr and cadr that don't crash ;; if the list is empty (is there a better way?) (define-public safe-cdr + ;; deprecate (match-lambda ((_ . x) x) (_ '()))) (define-public safe-cadr + ;; deprecate (match-lambda ((_ x . y) x) (_ '()))) diff --git a/gnucash/report/reports/standard/balsheet-eg.scm b/gnucash/report/reports/standard/balsheet-eg.scm index 15f7d42c92b..ee35e76f68b 100644 --- a/gnucash/report/reports/standard/balsheet-eg.scm +++ b/gnucash/report/reports/standard/balsheet-eg.scm @@ -458,13 +458,12 @@ (>= (gnc-account-get-current-depth (car account-list)) curr-depth)) (let* ((account (car account-list)) + (accrest (cdr account-list)) + (accnext (and (pair? accrest) (car accrest))) (comm (xaccAccountGetCommodity account)) (bal (xaccAccountGetBalanceAsOfDate account opt-date)) (depth (flattened-acc-depth account)) (treedepth 1) - ;; Next account only qualifies as 'deeper' if we're not flattening - (next-acc-deeper (and (not (null? (safe-cadr account-list))) - (> (flattened-acc-depth (safe-cadr account-list)) depth))) (newacc (newaccrec-clean))) (accrec-set-account! newacc account) (accrec-set-code! newacc (xaccAccountGetCode account)) @@ -483,11 +482,11 @@ (add-to-cc total-cc comm bal neg?) (add-to-cc (accrec-subtotal-cc newacc) comm bal neg?) - (if next-acc-deeper + ;; Next account only qualifies as 'deeper' if we're not flattening + (if (and accnext (> (flattened-acc-depth accnext) depth)) ;; recurse to deal with deeper level accounts, ;; then store the resulting list - (let* ((result-v (process-acc-list-r - (safe-cdr account-list) (1+ curr-depth) neg?)) + (let* ((result-v (process-acc-list-r accrest (1+ curr-depth) neg?)) (subtree (vector-ref result-v 0)) (subtotal-cc (vector-ref result-v 2)) (subtreedepth (vector-ref result-v 3))