[taxtxf] set export-string for export-type='csv

This commit is contained in:
Christopher Lam 2020-08-10 12:58:28 +08:00
parent 0891e117c9
commit b0ab79bed7

View File

@ -2899,69 +2899,32 @@
)) ))
(if (not tax-mode?) ; Do Txf mode (if (not tax-mode?) ; Do Txf mode
(begin
(if tax-entity-type-valid? (if tax-entity-type-valid?
(if file-name ; cancel TXF if no file selected (gnc:html-document-set-export-string
(let ((port (catch #t ;;e.g., system-error doc
(lambda () (open-output-file file-name)) (call-with-output-string
(lambda (key . args) (lambda (port)
(let ((msg (format #f "Could not open the file: ~a. The error is: ~a - ~a" (gnc:display-report-list-item
file-name key (caaddr args))))
(gnc:gui-error msg msg)
#f)))))
(if port ;; port opened successfully
(let* ((output (map (lambda (form-line-acct)
(handle-tax-code form-line-acct))
selected-accounts-sorted-by-form-line-acct))
(output-txf
(list (list
"V042" crlf "V042" crlf "AGnuCash " gnc:version crlf
"AGnuCash " gnc:version crlf today-date crlf "^" crlf
today-date crlf (map handle-tax-code selected-accounts-sorted-by-form-line-acct)
"^" crlf (if (or (zero? tax-code-USD-total) (not prior-account))
output
(if (or
(gnc-numeric-zero-p tax-code-USD-total)
(not prior-account))
'() '()
(render-txf-account (render-txf-account
prior-account prior-account
(if (= 4 (get-acct-txf-info (if (= 4 (get-acct-txf-info
'format 'format (xaccAccountGetType prior-account)
(xaccAccountGetType (gnc:account-get-txf-code prior-account)))
prior-account) (- tax-code-cap-gain-sales-USD-total)
(gnc:account-get-txf-code
prior-account)))
(gnc-numeric-neg
tax-code-cap-gain-sales-USD-total)
tax-code-USD-total-as-dr) tax-code-USD-total-as-dr)
#f #f #f #f #f #f #f #f (xaccAccountGetType prior-account)
(xaccAccountGetType prior-account) (gnc:account-get-txf-code prior-account)
(gnc:account-get-txf-code prior-account-copy tax-entity-type #f)))
prior-account) port "taxtxf.scm - "))))
prior-account-copy (gnc:html-document-set-export-error doc "tax-entity-type is invalid"))
tax-entity-type #f)) doc)
))
)
;; prior-account can be #f if selected accounts are
;; marked as 'tax-related' in the account edit
;; dialog but not actually assigned to a tax code
;; using the 'Tax Options' dialog (UI bug?).
;; An empty file is unfortunately put out with
;; no user warning other than message on report.
(if prior-account
(gnc:display-report-list-item output-txf port
"taxtxf.scm - ")
#f)
(close-output-port port)
#t
) ; end of let
;; Could not open port successfully
#t ;; to prevent 2nd error dialog in
;; gnc_plugin_page_report_export_cb
) ;; end of if
) ;; end of let*
#f) ;;end of if
#f) ;;end of if
(begin ; else do tax report (begin ; else do tax report
(gnc:html-document-set-style! (gnc:html-document-set-style!
doc "header-just-top" doc "header-just-top"