r17873 - gnucash/branches/2.2/src/report - [17851] Bug #568327: Budget reports without a budget will crash

Christian Stimming cstim at cvs.gnucash.org
Tue Feb 3 16:05:07 EST 2009


Author: cstim
Date: 2009-02-03 16:05:07 -0500 (Tue, 03 Feb 2009)
New Revision: 17873
Trac: http://svn.gnucash.org/trac/changeset/17873

Modified:
   gnucash/branches/2.2/src/report/report-system/html-utilities.scm
   gnucash/branches/2.2/src/report/report-system/report-system.scm
   gnucash/branches/2.2/src/report/standard-reports/budget.scm
Log:
[17851] Bug #568327: Budget reports without a budget will crash

Fixes crashes and also improves error message when no budgets exists (for all
budget reports).

Patch by Forest Bond.

Modified: gnucash/branches/2.2/src/report/report-system/html-utilities.scm
===================================================================
--- gnucash/branches/2.2/src/report/report-system/html-utilities.scm	2009-02-03 21:04:57 UTC (rev 17872)
+++ gnucash/branches/2.2/src/report/report-system/html-utilities.scm	2009-02-03 21:05:07 UTC (rev 17873)
@@ -785,6 +785,17 @@
     table))
 
 
+(define (gnc:html-make-generic-budget-warning report-title-string)
+  (let ((p (gnc:make-html-text)))
+    (gnc:html-text-append!
+     p
+     (gnc:html-markup-h2 (string-append (_ report-title-string) ":"))
+     (gnc:html-markup-h2 "")
+     (gnc:html-markup-p
+       (_ "No budgets exist.  You must create at least one budget.")))
+    p))
+
+
 ;; TODO: How 'bout factoring the "Edit report options" stuff out of
 ;; these 3 functions?
 

Modified: gnucash/branches/2.2/src/report/report-system/report-system.scm
===================================================================
--- gnucash/branches/2.2/src/report/report-system/report-system.scm	2009-02-03 21:04:57 UTC (rev 17872)
+++ gnucash/branches/2.2/src/report/report-system/report-system.scm	2009-02-03 21:05:07 UTC (rev 17873)
@@ -90,6 +90,7 @@
 (export gnc:first-html-build-acct-table)
 (export gnc:html-make-exchangerates)
 (export gnc:html-make-no-account-warning)
+(export gnc:html-make-generic-budget-warning)
 (export gnc:html-make-generic-options-warning)
 (export gnc:html-make-empty-data-warning)
 

Modified: gnucash/branches/2.2/src/report/standard-reports/budget.scm
===================================================================
--- gnucash/branches/2.2/src/report/standard-reports/budget.scm	2009-02-03 21:04:57 UTC (rev 17872)
+++ gnucash/branches/2.2/src/report/standard-reports/budget.scm	2009-02-03 21:05:07 UTC (rev 17873)
@@ -293,6 +293,7 @@
 
   ;; get all option's values
   (let* ((budget (get-option gnc:pagename-general optname-budget))
+         (budget-valid? (and budget (not (null? budget))))
          (display-depth (get-option gnc:pagename-accounts
                                     optname-display-depth))
          (show-subaccts? (get-option gnc:pagename-accounts
@@ -363,8 +364,18 @@
                   (set! accounts (append accounts sub-accounts))))
             sub-accounts)))
 
-    (if (not (or (null? accounts) (null? budget) (not budget)))
-
+    (cond
+      ((null? accounts)
+        ;; No accounts selected.
+        (gnc:html-document-add-object! 
+         doc 
+         (gnc:html-make-no-account-warning 
+	  reportname (gnc:report-id report-obj))))
+      ((not budget-valid?)
+        ;; No budget selected.
+        (gnc:html-document-add-object!
+          doc (gnc:html-make-generic-budget-warning reportname)))
+      (else (begin
         (let* ((tree-depth (if (equal? display-depth 'all)
                                (accounts-get-children-depth accounts)
                                display-depth))
@@ -418,15 +429,9 @@
           ;; table width, since the add-account-balance had put stuff
           ;; there, but it doesn't seem to matter.
 
-          (gnc:html-document-add-object! doc html-table)
-          )
+          (gnc:html-document-add-object! doc html-table))))
+      ) ;; end cond
 
-        ;; error condition: either no accounts or no budgets specified
-        (gnc:html-document-add-object!
-         doc
-         (gnc:html-make-generic-options-warning
-	  reportname (gnc:report-id report-obj))))
-
     (gnc:report-finished)
     doc))
 



More information about the gnucash-changes mailing list