[trep-engine.scm] Display only columns with subtotals

when "Show subtotals only" is selected
This commit is contained in:
Vincent Dawans 2023-05-25 18:50:21 -07:00
parent 2cc4cb8bda
commit 6d07f41d57
2 changed files with 42 additions and 9 deletions

View File

@ -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")

View File

@ -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))