From 6d07f41d57deb3e8c0ba67c273b898c120758c9c Mon Sep 17 00:00:00 2001 From: Vincent Dawans Date: Thu, 25 May 2023 18:50:21 -0700 Subject: [PATCH] [trep-engine.scm] Display only columns with subtotals when "Show subtotals only" is selected --- .../standard/test/test-transaction.scm | 30 ++++++++++++++++++- gnucash/report/trep-engine.scm | 21 ++++++++----- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/gnucash/report/reports/standard/test/test-transaction.scm b/gnucash/report/reports/standard/test/test-transaction.scm index fa62835b59..2839d8a497 100644 --- a/gnucash/report/reports/standard/test/test-transaction.scm +++ b/gnucash/report/reports/standard/test/test-transaction.scm @@ -909,7 +909,35 @@ (test-equal "No running total columns are present" (list "Date" "Num" "Description" "Memo/Notes" "Account" "Amount") (get-row-col sxml 0 #f))) - ) + + ;; test that only columns with subtotals are displayed when + ;; "Show subtotals only (hide transactional data)" is selected + (set! options (default-testing-options)) + (for-each + (lambda (name) + (set-option! options "Display" name #t)) + (list "Date" "Reconciled Date" "Num" "Description" "Memo" "Notes" + "Account Name" "Other Account Name" "Shares" "Price" "Account Balance" + "Totals" "Use Full Other Account Name" "Use Full Account Name")) + (set-option! options "Display" "Running Totals" 'all) + (set-option! options "Sorting" "Primary Key" 'account-name) + (set-option! options "Sorting" "Primary Subtotal" #t) + (set-option! options "Sorting" "Secondary Key" 'date) + (set-option! options "Sorting" "Secondary Subtotal for Date Key" 'monthly) + (set-option! options "Sorting" "Show subtotals only (hide transactional data)" #t) + (set-option! options "Currency" "Common Currency" #t) + (set-option! options "Currency" "Show original currency amount" #t) + (let* ((sxml (options->sxml options "show subtotals only, single column"))) + (test-equal "all display columns on with single amount; show subtotals only, so only amount columns are shown" + (list "Amount (USD)" "Amount") + (get-row-col sxml 0 #f))) + + (set-option! options "Display" "Amount" 'double) + (let* ((sxml (options->sxml options "show subtotals only, dual column"))) + (test-equal "all display columns on with dual amount; show subtotals only, so only debit/credit columns are shown" + (list "Debit (USD)" "Credit (USD)" "Debit" "Credit") + (get-row-col sxml 0 #f))) + ) (test-end "sorting options") diff --git a/gnucash/report/trep-engine.scm b/gnucash/report/trep-engine.scm index 40cc93f57d..fb7d550257 100644 --- a/gnucash/report/trep-engine.scm +++ b/gnucash/report/trep-engine.scm @@ -1636,14 +1636,19 @@ be excluded from periodic reporting.") ;; this part will check whether custom-calculated-cells were specified. this ;; describes a custom function which consumes an options list, and generates ;; an association list similar to default-calculated-cells as above. - (if custom-calculated-cells - (let ((cc (custom-calculated-cells options))) - (cond - ((not (pair? cc)) (gnc:error "welp" cc) default-calculated-cells) - ((vector? (car cc)) (upgrade-vector-to-assoclist cc)) - ((any invalid-cell? cc) (gnc:error "welp" cc) default-calculated-cells) - (else cc))) - default-calculated-cells)) + (let ((cc (if custom-calculated-cells + (let ((ccc (custom-calculated-cells options))) + (cond + ((not (pair? ccc)) (gnc:error "welp" ccc) + default-calculated-cells) + ((vector? (car ccc)) (upgrade-vector-to-assoclist ccc)) + ((any invalid-cell? ccc) (gnc:error "welp" ccc) + default-calculated-cells) + (else ccc))) + default-calculated-cells))) + ;; Only keep cells with subtotals when "Show subtotals only" is selected + ;; otherwise leave all calculated-cells as is. + (if (column-uses? 'subtotals-only) (filter cell-with-subtotals? cc) cc))) (define headings-left-columns (map (cut assq-ref <> 'heading) left-columns))