[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:
Christopher Lam 2020-08-29 19:30:37 +08:00
parent 094b4ba842
commit f503f708f5
5 changed files with 48 additions and 57 deletions

View File

@ -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)))
(qof-date-format-set QOF-DATE-FORMAT-ISO)
(gnc:html-chart-set-data-labels! (gnc:html-chart-set-data-labels!
chart (map qof-print-date (map cadr intervals))) chart (map (lambda (data)
(qof-date-format-set old-fmt)) (gnc-print-time64 (cadr data) iso-date))
intervals))
;; Set currency symbol ;; Set currency symbol
(gnc:html-chart-set-currency-iso! (gnc:html-chart-set-currency-iso!

View File

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

View File

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

View File

@ -885,7 +885,6 @@
(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))
@ -905,17 +904,13 @@
(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)

View File

@ -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))
(dummy (qof-date-format-set QOF-DATE-FORMAT-ISO))
(infolist
(list
(list "from" (qof-print-date begindate))
(list "to" (qof-print-date enddate)))))
(qof-date-format-set old-date-fmt)
(cond (cond
((list? csvlist) ((pair? csvlist)
(let ((iso-date (qof-date-format-get-string QOF-DATE-FORMAT-ISO)))
(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)