[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
(gnc:accounts-get-commodities accounts #f)
to-date #f #f))
(iso-date (qof-date-format-get-string QOF-DATE-FORMAT-ISO))
(accounts-balancelist
(map
(lambda (acc)
@ -281,11 +282,10 @@ date point, a projected minimum balance including scheduled transactions."))
(gnc:html-chart-set-y-axis-label!
chart (gnc-commodity-get-mnemonic currency))
;; Set series labels
(let ((old-fmt (qof-date-format-get)))
(qof-date-format-set QOF-DATE-FORMAT-ISO)
(gnc:html-chart-set-data-labels!
chart (map qof-print-date (map cadr intervals)))
(qof-date-format-set old-fmt))
(gnc:html-chart-set-data-labels!
chart (map (lambda (data)
(gnc-print-time64 (cadr data) iso-date))
intervals))
;; Set currency symbol
(gnc:html-chart-set-currency-iso!

View File

@ -26,6 +26,7 @@
(define-module (gnucash reports standard category-barchart))
(use-modules (srfi srfi-1))
(use-modules (srfi srfi-9))
(use-modules (srfi srfi-26))
(use-modules (ice-9 match))
(use-modules (gnucash engine))
(use-modules (gnucash utilities))
@ -640,8 +641,7 @@ developing over time"))
(cond
((eq? export-type 'csv)
(let ((old-fmt (qof-date-format-get)))
(qof-date-format-set QOF-DATE-FORMAT-ISO)
(let ((iso-date (qof-date-format-get-string QOF-DATE-FORMAT-ISO)))
(gnc:html-document-set-export-string
document
(gnc:lists->csv
@ -665,9 +665,8 @@ developing over time"))
(if (pair? (cdr all-data))
(list (apply gnc:monetary+ row))
'())))
(map qof-print-date dates-list)
(apply zip (map cadr all-data))))))
(qof-date-format-set old-fmt)))))
(map (cut gnc-print-time64 <> iso-date) dates-list)
(apply zip (map cadr all-data))))))))))
;; else if empty data
(gnc:html-document-add-object!

View File

@ -444,8 +444,7 @@
(cond
((eq? export-type 'csv)
(let ((old-fmt (qof-date-format-get)))
(qof-date-format-set QOF-DATE-FORMAT-ISO)
(let ((iso-date (qof-date-format-get-string QOF-DATE-FORMAT-ISO)))
(gnc:html-document-set-export-string
document
(gnc:lists->csv
@ -453,10 +452,9 @@
(map G_ '("Date" "Income" "Expense" "Net Profit"))
(map G_ '("Date" "Assets" "Liabilities" "Net Worth")))
(map list
(map qof-print-date dates-list)
(map (cut gnc-print-time64 <> iso-date) dates-list)
minuend-balances
subtrahend-balances difference-balances))))
(qof-date-format-set old-fmt)))))
subtrahend-balances difference-balances))))))))
(gnc:html-document-add-object!
document
(gnc:html-make-empty-data-warning

View File

@ -885,37 +885,32 @@
(test-end "subtotal table")
(test-begin "csv-export")
(test-assert "csv output is valid"
(let ((options (default-testing-options)))
(set-option! options "Accounts" "Accounts"
(list bank usd-bank gbp-bank gbp-income income expense))
(set-option! options "General" "Start Date"
(cons 'absolute (gnc-dmy2time64 01 01 1969)))
(set-option! options "General" "End Date"
(cons 'absolute (gnc-dmy2time64 31 12 1970)))
(set-option! options "Display" "Subtotal Table" #t)
(set-option! options "General" "Common Currency" #t)
(set-option! options "General" "Report Currency" foreign2)
(set-option! options "General" "Show original currency amount" #t)
(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)
(let ((options (default-testing-options)))
(set-option! options "Accounts" "Accounts"
(list bank usd-bank gbp-bank gbp-income income expense))
(set-option! options "General" "Start Date"
(cons 'absolute (gnc-dmy2time64 01 01 1969)))
(set-option! options "General" "End Date"
(cons 'absolute (gnc-dmy2time64 31 12 1970)))
(set-option! options "Display" "Subtotal Table" #t)
(set-option! options "General" "Common Currency" #t)
(set-option! options "General" "Report Currency" foreign2)
(set-option! options "General" "Show original currency amount" #t)
(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)
(let* ((template (gnc:find-report-template trep-uuid))
(constructor (record-constructor <report>))
(report (constructor trep-uuid "bar" options #t #t #f #f ""))
(renderer (gnc:report-template-renderer template)))
;; run the renderer, ignore its output. we'll query the csv export.
(renderer report #:export-type 'csv #:filename "/tmp/export.csv"))
(let ((call-with-input-file "/tmp/export.csv"))
(lambda (f)
(let lp ((c (read-char f)) (out '()))
(if (eof-object? c)
(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))))))))
(let* ((template (gnc:find-report-template trep-uuid))
(constructor (record-constructor <report>))
(report (constructor trep-uuid "bar" options #t #t #f #f ""))
(renderer (gnc:report-template-renderer template))
(document (renderer report #:export-type 'csv)))
(test-assert "csv output has no export error"
(not (gnc:html-document-export-error document)))
(test-equal "csv output is valid"
"\"from\",\"1969-01-01\"\n\"to\",\"1970-12-31\"\n\"Amount (GBP)\",2.15\n\"Amount\",3.0"
(gnc:html-document-export-string document))))
(test-end "csv-export")))
(define (reconcile-tests)

View File

@ -2266,20 +2266,19 @@ warning will be removed in GnuCash 5.0"))
(cond
((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
((list? csvlist)
(cond
((pair? csvlist)
(let ((iso-date (qof-date-format-get-string QOF-DATE-FORMAT-ISO)))
(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
(gnc:html-document-set-export-error document csvlist)))))))))))
(else
(gnc:html-document-set-export-error document csvlist))))))))))
(gnc:report-finished)