gnucash maint: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Sat Aug 15 20:33:25 EDT 2020


Updated	 via  https://github.com/Gnucash/gnucash/commit/3e0eda4b (commit)
	 via  https://github.com/Gnucash/gnucash/commit/3eaeda39 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/21925c18 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/6d217a7b (commit)
	 via  https://github.com/Gnucash/gnucash/commit/469ef580 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/4de646b1 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/e84b404b (commit)
	 via  https://github.com/Gnucash/gnucash/commit/fee142b2 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/aa9602f0 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/37c1bd47 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/31185c96 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/b0ab79be (commit)
	 via  https://github.com/Gnucash/gnucash/commit/0891e117 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/f6450952 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/8b270725 (commit)
	from  https://github.com/Gnucash/gnucash/commit/a2375055 (commit)



commit 3e0eda4b15b5e35505bda1203e29320606c0524d
Merge: a23750550 3eaeda39f
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Aug 16 08:27:30 2020 +0800

    Merge branch 'maint-C-exports' into maint #768


commit 3eaeda39fa33fce93f3a468948a0f6a66f481e90
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Aug 16 08:26:48 2020 +0800

    [gnc-plugin-page-report] handle invalid renderer output
    
    - renderer doesn't return an html-document object
    - or, the html-document has no export-string nor export-error

diff --git a/gnucash/gnome/gnc-plugin-page-report.c b/gnucash/gnome/gnc-plugin-page-report.c
index 8521df4a0..cb6096290 100644
--- a/gnucash/gnome/gnc-plugin-page-report.c
+++ b/gnucash/gnome/gnc-plugin-page-report.c
@@ -1668,26 +1668,37 @@ gnc_plugin_page_report_export_cb( GtkAction *action, GncPluginPageReport *report
     {
         SCM type = scm_cdr (choice);
         SCM document = scm_call_3 (export_thunk, priv->cur_report, type, SCM_BOOL_F);
+        SCM query_result = scm_c_eval_string ("gnc:html-document?");
         SCM get_export_string = scm_c_eval_string ("gnc:html-document-export-string");
         SCM get_export_error = scm_c_eval_string ("gnc:html-document-export-error");
-        SCM export_string = scm_call_1 (get_export_string, document);
-        SCM export_error = scm_call_1 (get_export_error, document);
 
-        if (scm_is_string (export_string))
+        if (scm_is_false (scm_call_1 (query_result, document)))
+            gnc_error_dialog (parent, _("This report must be upgraded to \
+return a document object with export-string or export-error."));
+        else
         {
-            GError *err = NULL;
-            gchar *exported = scm_to_utf8_string (export_string);
-            if (!g_file_set_contents (filepath, exported, -1, &err))
-                gnc_error_dialog (parent, "Error during export: %s", err->message);
-            g_free (exported);
-            if (err)
-                g_error_free (err);
-        }
-        else if (scm_is_string (export_error))
-        {
-            gchar *str = scm_to_utf8_string (export_error);
-            gnc_error_dialog (parent, "error during export: %s", str);
-            g_free (str);
+            SCM export_string = scm_call_1 (get_export_string, document);
+            SCM export_error = scm_call_1 (get_export_error, document);
+
+            if (scm_is_string (export_string))
+            {
+                GError *err = NULL;
+                gchar *exported = scm_to_utf8_string (export_string);
+                if (!g_file_set_contents (filepath, exported, -1, &err))
+                    gnc_error_dialog (parent, "Error during export: %s", err->message);
+                g_free (exported);
+                if (err)
+                    g_error_free (err);
+            }
+            else if (scm_is_string (export_error))
+            {
+                gchar *str = scm_to_utf8_string (export_error);
+                gnc_error_dialog (parent, "error during export: %s", str);
+                g_free (str);
+            }
+            else
+                gnc_error_dialog (parent, _("This report must be upgraded to \
+return a document object with export-string or export-error."));
         }
         result = TRUE;
     }

commit 21925c18beb66caed0864d4cd297c03744aa5b49
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Aug 16 08:25:50 2020 +0800

    [gnucash-commands] handle invalid renderer return
    
    - renderer doesn't return an html-document object
    - or, the html-document has no export-string nor export-error

diff --git a/gnucash/gnucash-commands.cpp b/gnucash/gnucash-commands.cpp
index a20a5de67..4b1bd8448 100644
--- a/gnucash/gnucash-commands.cpp
+++ b/gnucash/gnucash-commands.cpp
@@ -193,7 +193,6 @@ scm_run_report (void *data,
     auto type = !args->export_type.empty() ?
                 scm_from_locale_string (args->export_type.c_str()) : SCM_BOOL_F;
 
-    /* dry-run? is #t: try report, check validity of options */
     if (scm_is_false (scm_call_2 (check_report_cmd, report, type)))
         scm_cleanup_and_exit_with_failure (nullptr);
 
@@ -216,8 +215,17 @@ scm_run_report (void *data,
     if (!args->export_type.empty())
     {
         SCM retval = scm_call_2 (run_export_cmd, report, type);
+        SCM query_result = scm_c_eval_string ("gnc:html-document?");
         SCM get_export_string = scm_c_eval_string ("gnc:html-document-export-string");
         SCM get_export_error = scm_c_eval_string ("gnc:html-document-export-error");
+
+        if (scm_is_false (scm_call_1 (query_result, retval)))
+        {
+            std::cerr << _("This report must be upgraded to \
+return a document object with export-string or export-error.") << std::endl;
+            scm_cleanup_and_exit_with_failure (nullptr);
+        }
+
         SCM export_string = scm_call_1 (get_export_string, retval);
         SCM export_error = scm_call_1 (get_export_error, retval);
 
@@ -236,7 +244,13 @@ scm_run_report (void *data,
         else if (scm_is_string (export_error))
         {
             auto err = scm_to_utf8_string (export_error);
-            std::cout << err << std::endl;
+            std::cerr << err << std::endl;
+            scm_cleanup_and_exit_with_failure (nullptr);
+        }
+        else
+        {
+            std::cerr << _("This report must be upgraded to \
+return a document object with export-string or export-error.") << std::endl;
             scm_cleanup_and_exit_with_failure (nullptr);
         }
     }

commit 6d217a7bcfdc1ea4e7a6bdbb3a6a2be643ec76a4
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Aug 15 18:33:47 2020 +0800

    [gnc-plugin-page-report] remove compatibility path

diff --git a/gnucash/gnome/gnc-plugin-page-report.c b/gnucash/gnome/gnc-plugin-page-report.c
index 31fda934c..8521df4a0 100644
--- a/gnucash/gnome/gnc-plugin-page-report.c
+++ b/gnucash/gnome/gnc-plugin-page-report.c
@@ -1689,17 +1689,6 @@ gnc_plugin_page_report_export_cb( GtkAction *action, GncPluginPageReport *report
             gnc_error_dialog (parent, "error during export: %s", str);
             g_free (str);
         }
-        else
-        {
-            /* compatibility path -- old report which does not effect
-               export-string and export-error during export code- call
-               with filepath */
-            SCM file = scm_from_locale_string (filepath);
-            scm_c_eval_string ("(issue-deprecation-warning \"Old report \
-with export-thunk encountered. Please upgrade report to ignore filename \
-and sets html-document export-string and/or export-error instead.\")");
-            scm_call_3 (export_thunk, priv->cur_report, type, file);
-        }
         result = TRUE;
     }
     else

commit 469ef58026ace614e73d9c59bb7e2d360839e6b1
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Aug 15 18:32:48 2020 +0800

    [gnucash-commands] remove compatibility path

diff --git a/gnucash/gnucash-commands.cpp b/gnucash/gnucash-commands.cpp
index 5d45e5277..a20a5de67 100644
--- a/gnucash/gnucash-commands.cpp
+++ b/gnucash/gnucash-commands.cpp
@@ -193,8 +193,8 @@ scm_run_report (void *data,
     auto type = !args->export_type.empty() ?
                 scm_from_locale_string (args->export_type.c_str()) : SCM_BOOL_F;
 
-/* dry-run? is #t: try report, check validity of options */
-    if (scm_is_false (scm_call_3 (check_report_cmd, report, type, SCM_BOOL_F)))
+    /* dry-run? is #t: try report, check validity of options */
+    if (scm_is_false (scm_call_2 (check_report_cmd, report, type)))
         scm_cleanup_and_exit_with_failure (nullptr);
 
     PINFO ("Loading datafile %s...\n", datafile);
@@ -215,7 +215,7 @@ scm_run_report (void *data,
 
     if (!args->export_type.empty())
     {
-        SCM retval = scm_call_3 (run_export_cmd, report, type, SCM_BOOL_F);
+        SCM retval = scm_call_2 (run_export_cmd, report, type);
         SCM get_export_string = scm_c_eval_string ("gnc:html-document-export-string");
         SCM get_export_error = scm_c_eval_string ("gnc:html-document-export-error");
         SCM export_string = scm_call_1 (get_export_string, retval);
@@ -223,7 +223,7 @@ scm_run_report (void *data,
 
         if (scm_is_string (export_string))
         {
-            output = scm_to_utf8_string (retval);
+            output = scm_to_utf8_string (export_string);
             if (!args->output_file.empty())
             {
                 write_report_file(output, args->output_file.c_str());
@@ -239,12 +239,6 @@ scm_run_report (void *data,
             std::cout << err << std::endl;
             scm_cleanup_and_exit_with_failure (nullptr);
         }
-        else
-        {
-            // compatibility path for old reports
-            auto file = scm_from_locale_string (args->output_file.c_str());
-            scm_call_3 (run_export_cmd, report, type, file);
-        }
     }
     else
     {

commit 4de646b1c7e7611ad19201568da28abf0f4249fd
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Aug 15 18:25:37 2020 +0800

    [report-core] remove output-file in gnc:cmdline-* fns

diff --git a/gnucash/report/report-core.scm b/gnucash/report/report-core.scm
index c9b621b0c..fe596f568 100644
--- a/gnucash/report/report-core.scm
+++ b/gnucash/report/report-core.scm
@@ -737,7 +737,7 @@ not found.")))
   (apply format (current-error-port) tmpl args)
   #f)
 
-(define (template-export report template export-type output-file dry-run?)
+(define (template-export report template export-type dry-run?)
   (let* ((report-guid (gnc:report-template-report-guid template))
          (parent-template-guid (gnc:report-template-parent-type template))
          (template (if parent-template-guid
@@ -757,7 +757,7 @@ not found.")))
       (display "Running export..." (current-error-port))
       (let ((output (export-thunk
                      (gnc-report-find (gnc:make-report report-guid))
-                     (assoc-ref export-types export-type) output-file)))
+                     (assoc-ref export-types export-type))))
         (display "done!\n" (current-error-port))
         output)))))
 
@@ -809,9 +809,8 @@ not found.")))
 
 ;; In: report - string matching reportname
 ;; In: export-type - string matching export type (eg CSV TXF etc)
-;; In: output-file - string for export file name
 ;; Out: if args are valid and runs a single report: #t, otherwise: #f
-(define-public (gnc:cmdline-check-report report export-type output-file)
+(define-public (gnc:cmdline-check-report report export-type)
   (let ((templates (reportname->templates report)))
     (cond
      ((null? templates)
@@ -825,16 +824,15 @@ not found.")))
       (stderr-log "\n"))
 
      (export-type (template-export report (car templates)
-                                   export-type output-file #t))
+                                   export-type #t))
      (else #t))))
 
 ;; In: report - string matching reportname
 ;; In: export-type - string matching export type (eg CSV TXF etc)
-;; In: output-file - string for export file name
 ;; Out: if error, #f
-(define-public (gnc:cmdline-template-export report export-type output-file)
+(define-public (gnc:cmdline-template-export report export-type)
   (match (reportname->templates report)
-    ((template) (template-export report template export-type output-file #f))
+    ((template) (template-export report template export-type #f))
     (_ (gnc:error report " does not match unique report") #f)))
 
 ;; In: report - string matching reportname

commit e84b404b74094bc869c64ccb47a676b24dd708b2
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Aug 15 18:25:22 2020 +0800

    [income-gst-statement] deprecate file-name argument in renderer

diff --git a/gnucash/report/reports/standard/income-gst-statement.scm b/gnucash/report/reports/standard/income-gst-statement.scm
index 76f34c808..ab56e5bc1 100644
--- a/gnucash/report/reports/standard/income-gst-statement.scm
+++ b/gnucash/report/reports/standard/income-gst-statement.scm
@@ -82,8 +82,11 @@ accounts may be tagged with *EUGOODS* in the account description."))
      #:custom-calculated-cells gst-calculated-cells
      #:custom-source-accounts sales-purch-accounts
      #:custom-split-filter gst-custom-split-filter
-     #:export-type export-type
-     #:filename file-name))
+     #:export-type export-type))
+  (when file-name
+    (issue-deprecation-warning "gst-statement-renderer filename is \
+obsolete, and not supported for exports. please set html-document \
+export-string instead. this warning will be removed in GnuCash 5.0"))
   (when (null? (opt-val "Accounts" "Tax Accounts"))
     (gnc:html-document-add-object! document TAX-SETUP-DESC))
   document)

commit fee142b27afa5d5e319737f1666b85171e86e451
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Aug 15 18:24:57 2020 +0800

    [trep-engine] deprecate #:filename argument in renderer

diff --git a/gnucash/report/trep-engine.scm b/gnucash/report/trep-engine.scm
index 726caf829..6410a1c58 100644
--- a/gnucash/report/trep-engine.scm
+++ b/gnucash/report/trep-engine.scm
@@ -1954,7 +1954,7 @@ be excluded from periodic reporting.")
   ;;     split->date returns #f. useful to include unreconciled splits in reconcile
   ;;     report. it can be useful for alternative date filtering, e.g. filter by
   ;;     transaction->invoice->payment date.
-  ;; #:export-type and #:filename - are provided for CSV export
+  ;; #:export-type - are provided for CSV export
   ;; #:custom-source-accounts - alternate list-of-accounts to retrieve splits from
 
   (define options (gnc:report-options report-obj))
@@ -1972,6 +1972,11 @@ be excluded from periodic reporting.")
         (((? from-account?) . _) #t)
         ((_ . rest) (lp rest)))))
 
+  (when filename
+    (issue-deprecation-warning "trep-renderer filename is obsolete, and not \
+supported for exports. please set html-document export-string instead. this \
+warning will be removed in GnuCash 5.0"))
+
   (gnc:report-starting (opt-val gnc:pagename-general gnc:optname-reportname))
 
   (let* ((document (gnc:make-html-document))

commit aa9602f0ed141a4c9f05f1f7002374f9101a00c3
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Wed Aug 12 18:27:53 2020 +0800

    [gnucash-commands] use export-string/error

diff --git a/gnucash/gnucash-commands.cpp b/gnucash/gnucash-commands.cpp
index 44b02b245..5d45e5277 100644
--- a/gnucash/gnucash-commands.cpp
+++ b/gnucash/gnucash-commands.cpp
@@ -192,11 +192,9 @@ scm_run_report (void *data,
     auto report = scm_from_locale_string (args->run_report.c_str());
     auto type = !args->export_type.empty() ?
                 scm_from_locale_string (args->export_type.c_str()) : SCM_BOOL_F;
-    auto file = !args->output_file.empty() ?
-                scm_from_locale_string (args->output_file.c_str()) : SCM_BOOL_F;
 
 /* dry-run? is #t: try report, check validity of options */
-    if (scm_is_false (scm_call_3 (check_report_cmd, report, type, file)))
+    if (scm_is_false (scm_call_3 (check_report_cmd, report, type, SCM_BOOL_F)))
         scm_cleanup_and_exit_with_failure (nullptr);
 
     PINFO ("Loading datafile %s...\n", datafile);
@@ -213,12 +211,40 @@ scm_run_report (void *data,
     if (qof_session_get_error (session) != ERR_BACKEND_NO_ERR)
         scm_cleanup_and_exit_with_failure (session);
 
+    char *output;
+
     if (!args->export_type.empty())
     {
-        SCM retval = scm_call_3(run_export_cmd, report, type, file);
+        SCM retval = scm_call_3 (run_export_cmd, report, type, SCM_BOOL_F);
+        SCM get_export_string = scm_c_eval_string ("gnc:html-document-export-string");
+        SCM get_export_error = scm_c_eval_string ("gnc:html-document-export-error");
+        SCM export_string = scm_call_1 (get_export_string, retval);
+        SCM export_error = scm_call_1 (get_export_error, retval);
 
-        if (scm_is_false (retval))
+        if (scm_is_string (export_string))
+        {
+            output = scm_to_utf8_string (retval);
+            if (!args->output_file.empty())
+            {
+                write_report_file(output, args->output_file.c_str());
+            }
+            else
+            {
+                std::cout << output << std::endl;
+            }
+        }
+        else if (scm_is_string (export_error))
+        {
+            auto err = scm_to_utf8_string (export_error);
+            std::cout << err << std::endl;
             scm_cleanup_and_exit_with_failure (nullptr);
+        }
+        else
+        {
+            // compatibility path for old reports
+            auto file = scm_from_locale_string (args->output_file.c_str());
+            scm_call_3 (run_export_cmd, report, type, file);
+        }
     }
     else
     {

commit 37c1bd47de8166e7306bfb37417c5927d9c331df
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Mon Aug 10 19:38:25 2020 +0800

    [gnc-plugin-page-report] use export-string/error

diff --git a/gnucash/gnome/gnc-plugin-page-report.c b/gnucash/gnome/gnc-plugin-page-report.c
index b797b1cf1..31fda934c 100644
--- a/gnucash/gnome/gnc-plugin-page-report.c
+++ b/gnucash/gnome/gnc-plugin-page-report.c
@@ -1666,15 +1666,41 @@ gnc_plugin_page_report_export_cb( GtkAction *action, GncPluginPageReport *report
 
     if (scm_is_pair (choice))
     {
-        SCM file_scm;
-        SCM res;
-
-        choice = SCM_CDR (choice);
-        file_scm = scm_from_locale_string (filepath);
-
-        res = scm_call_3 (export_thunk, priv->cur_report, choice, file_scm);
-
-        result = (res != SCM_BOOL_F);
+        SCM type = scm_cdr (choice);
+        SCM document = scm_call_3 (export_thunk, priv->cur_report, type, SCM_BOOL_F);
+        SCM get_export_string = scm_c_eval_string ("gnc:html-document-export-string");
+        SCM get_export_error = scm_c_eval_string ("gnc:html-document-export-error");
+        SCM export_string = scm_call_1 (get_export_string, document);
+        SCM export_error = scm_call_1 (get_export_error, document);
+
+        if (scm_is_string (export_string))
+        {
+            GError *err = NULL;
+            gchar *exported = scm_to_utf8_string (export_string);
+            if (!g_file_set_contents (filepath, exported, -1, &err))
+                gnc_error_dialog (parent, "Error during export: %s", err->message);
+            g_free (exported);
+            if (err)
+                g_error_free (err);
+        }
+        else if (scm_is_string (export_error))
+        {
+            gchar *str = scm_to_utf8_string (export_error);
+            gnc_error_dialog (parent, "error during export: %s", str);
+            g_free (str);
+        }
+        else
+        {
+            /* compatibility path -- old report which does not effect
+               export-string and export-error during export code- call
+               with filepath */
+            SCM file = scm_from_locale_string (filepath);
+            scm_c_eval_string ("(issue-deprecation-warning \"Old report \
+with export-thunk encountered. Please upgrade report to ignore filename \
+and sets html-document export-string and/or export-error instead.\")");
+            scm_call_3 (export_thunk, priv->cur_report, type, file);
+        }
+        result = TRUE;
     }
     else
         result = gnc_html_export_to_file (priv->html, filepath);

commit 31185c963a3203f5a20b672e74fafdadddb223b1
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Mon Aug 10 19:15:15 2020 +0800

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

diff --git a/gnucash/report/reports/locale-specific/de_DE/taxtxf.scm b/gnucash/report/reports/locale-specific/de_DE/taxtxf.scm
index f729f2316..cd2fd5faf 100644
--- a/gnucash/report/reports/locale-specific/de_DE/taxtxf.scm
+++ b/gnucash/report/reports/locale-specific/de_DE/taxtxf.scm
@@ -74,6 +74,7 @@
 (use-modules (gnucash locale de_DE tax))
 (use-modules (gnucash report))
 (use-modules (srfi srfi-1))
+(use-modules (srfi srfi-26))
 
 (define reportname (N_ "Tax Report / TXF Export"))
 
@@ -771,34 +772,20 @@
 
       (if (not tax-mode?)		; Do Txf mode
           (begin
-            (if file-name		; cancel TXF if no file selected
-                (let* ((port (open-output-file file-name))    
-                       (output
-                        (map (lambda (x) (handle-level-x-account 1 x))
-                             selected-accounts))
-		       ;; FIXME: Print the leading and trailing bits here
-                       (output-txf (list
-                                    "<WinstonAusgang>" crlf
-				    "  <Formular Typ=\"UST\"></Formular>" crlf
-				    ;; FIXME: Get this Ordnungsnummer somehow
-				    "  <Ordnungsnummer>"
-				    tax-nr
-				    "</Ordnungsnummer>" crlf
-                                    ;;"<software>GnuCash</software>" crlf
-				    ;;"<version>" gnc:version "</version>" crlf
-                                    ;; today-date crlf
-				    "  <AnmeldeJahr>" to-year "</AnmeldeJahr>" crlf
-				    ;; FIXME: Find out what this should mean
-				    "  <AnmeldeZeitraum>" "1" "</AnmeldeZeitraum>" crlf
-                                    output
-				    "</WinstonAusgang>")))
-
-                  (gnc:display-report-list-item output-txf port
-                                                "taxtxf-de.scm - ")
-                  (close-output-port port)
-                  #t)
-                #f))
-
+            (gnc:html-document-set-export-string
+             doc (call-with-output-string
+                   (lambda (port)
+                     (gnc:display-report-list-item
+                      (list
+                       "<WinstonAusgang>" crlf
+                       "  <Formular Typ=\"UST\"></Formular>" crlf
+                       "  <Ordnungsnummer>" tax-nr "</Ordnungsnummer>" crlf
+                       "  <AnmeldeJahr>" to-year "</AnmeldeJahr>" crlf
+                       "  <AnmeldeZeitraum>1</AnmeldeZeitraum>" crlf
+                       (map (cut handle-level-x-account 1 <>) selected-accounts)
+                       "</WinstonAusgang>")
+                      port "taxtxf-de.scm - "))))
+            doc)
           (begin			; else do tax report
             (gnc:html-document-set-style! 
              doc "blue"

commit b0ab79bed7e6f149a7b4e105e6f88ce655dfd79d
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Mon Aug 10 12:58:28 2020 +0800

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

diff --git a/gnucash/report/reports/locale-specific/us/taxtxf.scm b/gnucash/report/reports/locale-specific/us/taxtxf.scm
index 3a8181157..c6cd6527a 100644
--- a/gnucash/report/reports/locale-specific/us/taxtxf.scm
+++ b/gnucash/report/reports/locale-specific/us/taxtxf.scm
@@ -2899,69 +2899,32 @@
           ))
 
       (if (not tax-mode?) ; Do Txf mode
-          (if tax-entity-type-valid?
-              (if file-name		; cancel TXF if no file selected
-                  (let ((port (catch #t ;;e.g., system-error
-                                (lambda () (open-output-file file-name))
-                                (lambda (key . args)
-                                  (let ((msg (format #f "Could not open the file: ~a. The error is: ~a - ~a"
-                                                     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
-                                      "V042" crlf
-                                      "AGnuCash " gnc:version crlf
-                                      today-date crlf
-                                      "^" crlf
-                                      output
-                                      (if (or
-                                             (gnc-numeric-zero-p tax-code-USD-total)
-                                             (not prior-account))
-                                          '()
-                                          (render-txf-account
-                                              prior-account
-                                              (if (= 4 (get-acct-txf-info
-                                                          'format
-                                                          (xaccAccountGetType
-                                                                  prior-account)
-                                                          (gnc:account-get-txf-code
-                                                                prior-account)))
-                                                  (gnc-numeric-neg
-                                                   tax-code-cap-gain-sales-USD-total)
-                                                  tax-code-USD-total-as-dr)
-                                              #f #f #f #f
-                                              (xaccAccountGetType prior-account)
-                                              (gnc:account-get-txf-code
-                                                                prior-account)
-                                              prior-account-copy
-                                              tax-entity-type #f))
-                                    ))
-                                 )
-                                 ;; 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
+            (if tax-entity-type-valid?
+                (gnc:html-document-set-export-string
+                 doc
+                 (call-with-output-string
+                   (lambda (port)
+                     (gnc:display-report-list-item
+                      (list
+                       "V042" crlf "AGnuCash " gnc:version crlf
+                       today-date crlf "^" crlf
+                       (map handle-tax-code selected-accounts-sorted-by-form-line-acct)
+                       (if (or (zero? tax-code-USD-total) (not prior-account))
+                           '()
+                           (render-txf-account
+                            prior-account
+                            (if (= 4 (get-acct-txf-info
+                                      'format (xaccAccountGetType prior-account)
+                                      (gnc:account-get-txf-code prior-account)))
+                                (- tax-code-cap-gain-sales-USD-total)
+                                tax-code-USD-total-as-dr)
+                            #f #f #f #f (xaccAccountGetType prior-account)
+                            (gnc:account-get-txf-code prior-account)
+                            prior-account-copy tax-entity-type #f)))
+                      port "taxtxf.scm - "))))
+                (gnc:html-document-set-export-error doc "tax-entity-type is invalid"))
+            doc)
           (begin  ; else do tax report
                   (gnc:html-document-set-style!
                    doc "header-just-top"

commit 0891e117c93c1dd2db794c5c9666be6c2479e6d4
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Mon Aug 10 12:41:29 2020 +0800

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

diff --git a/gnucash/report/trep-engine.scm b/gnucash/report/trep-engine.scm
index 26d2b7a6d..726caf829 100644
--- a/gnucash/report/trep-engine.scm
+++ b/gnucash/report/trep-engine.scm
@@ -2124,6 +2124,8 @@ be excluded from periodic reporting.")
           (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
       ;; the renderer, display it here.
       (when empty-report-message
@@ -2207,6 +2209,8 @@ be excluded from periodic reporting.")
           report-title (gnc:report-id report-obj)
           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))
           (gnc:html-document-add-object!
            document
@@ -2249,10 +2253,12 @@ be excluded from periodic reporting.")
               (gnc:html-document-add-object!
                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
-           ((and (eq? export-type 'csv)
-                 (string? filename)
-                 (not (string-null? filename)))
+           ((eq? export-type 'csv)
             (let ((old-date-fmt (qof-date-format-get))
                   (dummy (qof-date-format-set QOF-DATE-FORMAT-ISO))
                   (infolist
@@ -2260,22 +2266,13 @@ be excluded from periodic reporting.")
                     (list "from" (qof-print-date begindate))
                     (list "to" (qof-print-date enddate)))))
               (qof-date-format-set old-date-fmt)
-              (if (list? csvlist)
-                  (catch #t
-                    (lambda ()
-                      (call-with-output-file filename
-                        (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))))))
+              (cond
+               ((list? csvlist)
+                (gnc:html-document-set-export-string
+                 document (lists->csv (append infolist csvlist))))
 
-          (unless (and subtotal-table?
-                       (opt-val pagename-sorting optname-show-subtotals-only))
-            (gnc:html-document-add-object! document table)))))))
+               (else
+                (gnc:html-document-set-export-error document csvlist)))))))))))
 
     (gnc:report-finished)
 

commit f6450952423e269516e01703eca8236a9d9562aa
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Wed Aug 12 18:27:10 2020 +0800

    [report-core] don't barf when output-file is #false

diff --git a/gnucash/report/report-core.scm b/gnucash/report/report-core.scm
index a1529bb9c..c9b621b0c 100644
--- a/gnucash/report/report-core.scm
+++ b/gnucash/report/report-core.scm
@@ -752,14 +752,14 @@ not found.")))
      ((not (assoc export-type export-types))
       (stderr-log "Export-type disallowed: ~a. Allowed types: ~a\n"
                   export-type (string-join (map car export-types) ", ")))
-     ((not output-file) (stderr-log "No output file specified\n"))
      (dry-run? #t)
      (else
       (display "Running export..." (current-error-port))
-      (export-thunk
-       (gnc-report-find (gnc:make-report report-guid))
-       (assoc-ref export-types export-type) output-file)
-      (display "done!\n" (current-error-port))))))
+      (let ((output (export-thunk
+                     (gnc-report-find (gnc:make-report report-guid))
+                     (assoc-ref export-types export-type) output-file)))
+        (display "done!\n" (current-error-port))
+        output)))))
 
 (define (reportname->templates report)
   (or (and=> (gnc:find-report-template report) list)

commit 8b2707254f6b3596cddf915c5b3026083df0f0f6
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Fri Aug 14 20:41:49 2020 +0800

    [html-document] add export-string|error fields in html-document

diff --git a/gnucash/report/html-document.scm b/gnucash/report/html-document.scm
index 47f544f31..daf15dfa6 100644
--- a/gnucash/report/html-document.scm
+++ b/gnucash/report/html-document.scm
@@ -32,7 +32,8 @@
 
 (define-record-type <html-document>
   (make-html-document-internal style-sheet style-stack style
-                               style-text title headline objects)
+                               style-text title headline objects
+                               export-string export-error)
   html-document?
   (style-sheet html-document-style-sheet html-document-set-style-sheet)
   (style-stack html-document-style-stack html-document-set-style-stack)
@@ -40,7 +41,9 @@
   (style-text html-document-style-text html-document-set-style-text)
   (title html-document-title html-document-set-title)
   (headline html-document-headline html-document-set-headline)
-  (objects html-document-objects html-document-set-objects))
+  (objects html-document-objects html-document-set-objects)
+  (export-string html-document-export-string html-document-set-export-string)
+  (export-error html-document-export-error html-document-set-export-error))
 
 (define gnc:html-document-set-title! html-document-set-title)
 (define gnc:html-document-title html-document-title)
@@ -59,6 +62,10 @@
 (define gnc:html-document-objects html-document-objects)
 (define gnc:html-document? html-document?)
 (define gnc:make-html-document-internal make-html-document-internal)
+(define gnc:html-document-export-string html-document-export-string)
+(define gnc:html-document-set-export-string html-document-set-export-string)
+(define gnc:html-document-export-error html-document-export-error)
+(define gnc:html-document-set-export-error html-document-set-export-error)
 
 (define (gnc:make-html-document)
   (gnc:make-html-document-internal
@@ -69,6 +76,8 @@
    ""                    ;; document title
    #f                    ;; headline
    '()                   ;; subobjects
+   #f                    ;; export-string -- must be #f by default
+   #f                    ;; export-error -- must be #f by default
    ))
 
 (define (gnc:html-document-set-style! doc tag . rest)
diff --git a/gnucash/report/report.scm b/gnucash/report/report.scm
index c5de10b9b..b01515e4c 100644
--- a/gnucash/report/report.scm
+++ b/gnucash/report/report.scm
@@ -275,6 +275,10 @@
 (export gnc:html-document-markup-start)
 (export gnc:html-document-markup-end)
 (export gnc:html-document-render-data)
+(export gnc:html-document-export-string)
+(export gnc:html-document-set-export-string)
+(export gnc:html-document-export-error)
+(export gnc:html-document-set-export-error)
 (export <html-object>)
 (export gnc:html-object?)
 (export gnc:make-html-object-internal)



Summary of changes:
 gnucash/gnome/gnc-plugin-page-report.c             | 42 ++++++++--
 gnucash/gnucash-commands.cpp                       | 46 +++++++++--
 gnucash/report/html-document.scm                   | 13 +++-
 gnucash/report/report-core.scm                     | 22 +++---
 gnucash/report/report.scm                          |  4 +
 .../reports/locale-specific/de_DE/taxtxf.scm       | 43 ++++-------
 .../report/reports/locale-specific/us/taxtxf.scm   | 89 +++++++---------------
 .../reports/standard/income-gst-statement.scm      |  7 +-
 gnucash/report/trep-engine.scm                     | 40 +++++-----
 9 files changed, 166 insertions(+), 140 deletions(-)



More information about the gnucash-changes mailing list