[trep-engine] set export-string or export-error for export-type 'csv

This commit is contained in:
Christopher Lam 2020-08-10 12:41:29 +08:00
parent f645095242
commit 0891e117c9

View File

@ -2124,6 +2124,8 @@ be excluded from periodic reporting.")
(string-append (G_ "Error") " " (symbol->string transaction-matcher-regexp)) (string-append (G_ "Error") " " (symbol->string transaction-matcher-regexp))
"")))) ""))))
(gnc:html-document-set-export-error document "No accounts, or regexp error")
;; if an empty-report-message is passed by a derived report to ;; if an empty-report-message is passed by a derived report to
;; the renderer, display it here. ;; the renderer, display it here.
(when empty-report-message (when empty-report-message
@ -2207,6 +2209,8 @@ be excluded from periodic reporting.")
report-title (gnc:report-id report-obj) report-title (gnc:report-id report-obj)
NO-MATCHING-TRANS-HEADER NO-MATCHING-TRANS-TEXT)) NO-MATCHING-TRANS-HEADER NO-MATCHING-TRANS-TEXT))
(gnc:html-document-set-export-error document "No splits found")
(when (memq infobox-display '(always no-match)) (when (memq infobox-display '(always no-match))
(gnc:html-document-add-object! (gnc:html-document-add-object!
document document
@ -2249,10 +2253,12 @@ be excluded from periodic reporting.")
(gnc:html-document-add-object! (gnc:html-document-add-object!
document (grid->html-table grid list-of-rows list-of-cols)))) document (grid->html-table grid list-of-rows list-of-cols))))
(unless (and subtotal-table?
(opt-val pagename-sorting optname-show-subtotals-only))
(gnc:html-document-add-object! document table))
(cond (cond
((and (eq? export-type 'csv) ((eq? export-type 'csv)
(string? filename)
(not (string-null? filename)))
(let ((old-date-fmt (qof-date-format-get)) (let ((old-date-fmt (qof-date-format-get))
(dummy (qof-date-format-set QOF-DATE-FORMAT-ISO)) (dummy (qof-date-format-set QOF-DATE-FORMAT-ISO))
(infolist (infolist
@ -2260,22 +2266,13 @@ be excluded from periodic reporting.")
(list "from" (qof-print-date begindate)) (list "from" (qof-print-date begindate))
(list "to" (qof-print-date enddate))))) (list "to" (qof-print-date enddate)))))
(qof-date-format-set old-date-fmt) (qof-date-format-set old-date-fmt)
(if (list? csvlist) (cond
(catch #t ((list? csvlist)
(lambda () (gnc:html-document-set-export-string
(call-with-output-file filename document (lists->csv (append infolist csvlist))))
(lambda (p)
(display (lists->csv (append infolist csvlist)) p))))
(lambda (key . args)
;; Translators: ~a error type, ~a filename, ~s error details
(let ((fmt (N_ "error ~a during csv output to ~a: ~s")))
(gnc:gui-error (format #f fmt key filename args)
(format #f (G_ fmt) key filename args)))))
(gnc:gui-error csvlist (G_ csvlist))))))
(unless (and subtotal-table? (else
(opt-val pagename-sorting optname-show-subtotals-only)) (gnc:html-document-set-export-error document csvlist)))))))))))
(gnc:html-document-add-object! document table)))))))
(gnc:report-finished) (gnc:report-finished)