mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
[reports] use gnc-print-time64
removes the need to store and reset the current QofDateFormat via qof-date-format-set and qof-date-format-get. also fix test-transaction csv output test.
This commit is contained in:
parent
094b4ba842
commit
f503f708f5
@ -169,6 +169,7 @@ date point, a projected minimum balance including scheduled transactions."))
|
|||||||
price currency
|
price currency
|
||||||
(gnc:accounts-get-commodities accounts #f)
|
(gnc:accounts-get-commodities accounts #f)
|
||||||
to-date #f #f))
|
to-date #f #f))
|
||||||
|
(iso-date (qof-date-format-get-string QOF-DATE-FORMAT-ISO))
|
||||||
(accounts-balancelist
|
(accounts-balancelist
|
||||||
(map
|
(map
|
||||||
(lambda (acc)
|
(lambda (acc)
|
||||||
@ -281,11 +282,10 @@ date point, a projected minimum balance including scheduled transactions."))
|
|||||||
(gnc:html-chart-set-y-axis-label!
|
(gnc:html-chart-set-y-axis-label!
|
||||||
chart (gnc-commodity-get-mnemonic currency))
|
chart (gnc-commodity-get-mnemonic currency))
|
||||||
;; Set series labels
|
;; Set series labels
|
||||||
(let ((old-fmt (qof-date-format-get)))
|
(gnc:html-chart-set-data-labels!
|
||||||
(qof-date-format-set QOF-DATE-FORMAT-ISO)
|
chart (map (lambda (data)
|
||||||
(gnc:html-chart-set-data-labels!
|
(gnc-print-time64 (cadr data) iso-date))
|
||||||
chart (map qof-print-date (map cadr intervals)))
|
intervals))
|
||||||
(qof-date-format-set old-fmt))
|
|
||||||
|
|
||||||
;; Set currency symbol
|
;; Set currency symbol
|
||||||
(gnc:html-chart-set-currency-iso!
|
(gnc:html-chart-set-currency-iso!
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
(define-module (gnucash reports standard category-barchart))
|
(define-module (gnucash reports standard category-barchart))
|
||||||
(use-modules (srfi srfi-1))
|
(use-modules (srfi srfi-1))
|
||||||
(use-modules (srfi srfi-9))
|
(use-modules (srfi srfi-9))
|
||||||
|
(use-modules (srfi srfi-26))
|
||||||
(use-modules (ice-9 match))
|
(use-modules (ice-9 match))
|
||||||
(use-modules (gnucash engine))
|
(use-modules (gnucash engine))
|
||||||
(use-modules (gnucash utilities))
|
(use-modules (gnucash utilities))
|
||||||
@ -640,8 +641,7 @@ developing over time"))
|
|||||||
|
|
||||||
(cond
|
(cond
|
||||||
((eq? export-type 'csv)
|
((eq? export-type 'csv)
|
||||||
(let ((old-fmt (qof-date-format-get)))
|
(let ((iso-date (qof-date-format-get-string QOF-DATE-FORMAT-ISO)))
|
||||||
(qof-date-format-set QOF-DATE-FORMAT-ISO)
|
|
||||||
(gnc:html-document-set-export-string
|
(gnc:html-document-set-export-string
|
||||||
document
|
document
|
||||||
(gnc:lists->csv
|
(gnc:lists->csv
|
||||||
@ -665,9 +665,8 @@ developing over time"))
|
|||||||
(if (pair? (cdr all-data))
|
(if (pair? (cdr all-data))
|
||||||
(list (apply gnc:monetary+ row))
|
(list (apply gnc:monetary+ row))
|
||||||
'())))
|
'())))
|
||||||
(map qof-print-date dates-list)
|
(map (cut gnc-print-time64 <> iso-date) dates-list)
|
||||||
(apply zip (map cadr all-data))))))
|
(apply zip (map cadr all-data))))))))))
|
||||||
(qof-date-format-set old-fmt)))))
|
|
||||||
|
|
||||||
;; else if empty data
|
;; else if empty data
|
||||||
(gnc:html-document-add-object!
|
(gnc:html-document-add-object!
|
||||||
|
@ -444,8 +444,7 @@
|
|||||||
|
|
||||||
(cond
|
(cond
|
||||||
((eq? export-type 'csv)
|
((eq? export-type 'csv)
|
||||||
(let ((old-fmt (qof-date-format-get)))
|
(let ((iso-date (qof-date-format-get-string QOF-DATE-FORMAT-ISO)))
|
||||||
(qof-date-format-set QOF-DATE-FORMAT-ISO)
|
|
||||||
(gnc:html-document-set-export-string
|
(gnc:html-document-set-export-string
|
||||||
document
|
document
|
||||||
(gnc:lists->csv
|
(gnc:lists->csv
|
||||||
@ -453,10 +452,9 @@
|
|||||||
(map G_ '("Date" "Income" "Expense" "Net Profit"))
|
(map G_ '("Date" "Income" "Expense" "Net Profit"))
|
||||||
(map G_ '("Date" "Assets" "Liabilities" "Net Worth")))
|
(map G_ '("Date" "Assets" "Liabilities" "Net Worth")))
|
||||||
(map list
|
(map list
|
||||||
(map qof-print-date dates-list)
|
(map (cut gnc-print-time64 <> iso-date) dates-list)
|
||||||
minuend-balances
|
minuend-balances
|
||||||
subtrahend-balances difference-balances))))
|
subtrahend-balances difference-balances))))))))
|
||||||
(qof-date-format-set old-fmt)))))
|
|
||||||
(gnc:html-document-add-object!
|
(gnc:html-document-add-object!
|
||||||
document
|
document
|
||||||
(gnc:html-make-empty-data-warning
|
(gnc:html-make-empty-data-warning
|
||||||
|
@ -885,37 +885,32 @@
|
|||||||
(test-end "subtotal table")
|
(test-end "subtotal table")
|
||||||
|
|
||||||
(test-begin "csv-export")
|
(test-begin "csv-export")
|
||||||
(test-assert "csv output is valid"
|
(let ((options (default-testing-options)))
|
||||||
(let ((options (default-testing-options)))
|
(set-option! options "Accounts" "Accounts"
|
||||||
(set-option! options "Accounts" "Accounts"
|
(list bank usd-bank gbp-bank gbp-income income expense))
|
||||||
(list bank usd-bank gbp-bank gbp-income income expense))
|
(set-option! options "General" "Start Date"
|
||||||
(set-option! options "General" "Start Date"
|
(cons 'absolute (gnc-dmy2time64 01 01 1969)))
|
||||||
(cons 'absolute (gnc-dmy2time64 01 01 1969)))
|
(set-option! options "General" "End Date"
|
||||||
(set-option! options "General" "End Date"
|
(cons 'absolute (gnc-dmy2time64 31 12 1970)))
|
||||||
(cons 'absolute (gnc-dmy2time64 31 12 1970)))
|
(set-option! options "Display" "Subtotal Table" #t)
|
||||||
(set-option! options "Display" "Subtotal Table" #t)
|
(set-option! options "General" "Common Currency" #t)
|
||||||
(set-option! options "General" "Common Currency" #t)
|
(set-option! options "General" "Report Currency" foreign2)
|
||||||
(set-option! options "General" "Report Currency" foreign2)
|
(set-option! options "General" "Show original currency amount" #t)
|
||||||
(set-option! options "General" "Show original currency amount" #t)
|
(set-option! options "Sorting" "Primary Key" 'account-name)
|
||||||
(set-option! options "Sorting" "Primary Key" 'account-name)
|
(set-option! options "Sorting" "Primary Subtotal" #t)
|
||||||
(set-option! options "Sorting" "Primary Subtotal" #t)
|
(set-option! options "Sorting" "Secondary Key" 'date)
|
||||||
(set-option! options "Sorting" "Secondary Key" 'date)
|
(set-option! options "Sorting" "Secondary Subtotal for Date Key" 'monthly)
|
||||||
(set-option! options "Sorting" "Secondary Subtotal for Date Key" 'monthly)
|
|
||||||
|
|
||||||
(let* ((template (gnc:find-report-template trep-uuid))
|
(let* ((template (gnc:find-report-template trep-uuid))
|
||||||
(constructor (record-constructor <report>))
|
(constructor (record-constructor <report>))
|
||||||
(report (constructor trep-uuid "bar" options #t #t #f #f ""))
|
(report (constructor trep-uuid "bar" options #t #t #f #f ""))
|
||||||
(renderer (gnc:report-template-renderer template)))
|
(renderer (gnc:report-template-renderer template))
|
||||||
;; run the renderer, ignore its output. we'll query the csv export.
|
(document (renderer report #:export-type 'csv)))
|
||||||
(renderer report #:export-type 'csv #:filename "/tmp/export.csv"))
|
(test-assert "csv output has no export error"
|
||||||
(let ((call-with-input-file "/tmp/export.csv"))
|
(not (gnc:html-document-export-error document)))
|
||||||
(lambda (f)
|
(test-equal "csv output is valid"
|
||||||
(let lp ((c (read-char f)) (out '()))
|
"\"from\",\"1969-01-01\"\n\"to\",\"1970-12-31\"\n\"Amount (GBP)\",2.15\n\"Amount\",3.0"
|
||||||
(if (eof-object? c)
|
(gnc:html-document-export-string document))))
|
||||||
(string=?
|
|
||||||
"\"from\",\"01/01/69\"\n\"to\",\"12/31/70\"\n\"Amount (GBP)\",2.15\n\"Amount\",3.0"
|
|
||||||
(reverse-list->string out))
|
|
||||||
(lp (read-char f) (cons c out))))))))
|
|
||||||
(test-end "csv-export")))
|
(test-end "csv-export")))
|
||||||
|
|
||||||
(define (reconcile-tests)
|
(define (reconcile-tests)
|
||||||
|
@ -2266,20 +2266,19 @@ warning will be removed in GnuCash 5.0"))
|
|||||||
|
|
||||||
(cond
|
(cond
|
||||||
((eq? export-type 'csv)
|
((eq? export-type 'csv)
|
||||||
(let ((old-date-fmt (qof-date-format-get))
|
(cond
|
||||||
(dummy (qof-date-format-set QOF-DATE-FORMAT-ISO))
|
((pair? csvlist)
|
||||||
(infolist
|
(let ((iso-date (qof-date-format-get-string QOF-DATE-FORMAT-ISO)))
|
||||||
(list
|
|
||||||
(list "from" (qof-print-date begindate))
|
|
||||||
(list "to" (qof-print-date enddate)))))
|
|
||||||
(qof-date-format-set old-date-fmt)
|
|
||||||
(cond
|
|
||||||
((list? csvlist)
|
|
||||||
(gnc:html-document-set-export-string
|
(gnc:html-document-set-export-string
|
||||||
document (lists->csv (append infolist csvlist))))
|
document
|
||||||
|
(lists->csv
|
||||||
|
(cons*
|
||||||
|
`("from" ,(gnc-print-time64 begindate iso-date))
|
||||||
|
`("to" ,(gnc-print-time64 enddate iso-date))
|
||||||
|
csvlist)))))
|
||||||
|
|
||||||
(else
|
(else
|
||||||
(gnc:html-document-set-export-error document csvlist)))))))))))
|
(gnc:html-document-set-export-error document csvlist))))))))))
|
||||||
|
|
||||||
(gnc:report-finished)
|
(gnc:report-finished)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user