gnucash maint: Bug 797506 - New Aging errors out with guile backtrace in case of a few uncommon transactions

Christopher Lam clam at code.gnucash.org
Sun Nov 24 19:04:35 EST 2019


Updated	 via  https://github.com/Gnucash/gnucash/commit/e83f5b05 (commit)
	from  https://github.com/Gnucash/gnucash/commit/287b857a (commit)



commit e83f5b05688db27ac6b7d4298c7fd084004abb51
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Nov 24 09:49:14 2019 +0800

    Bug 797506 - New Aging errors out with guile backtrace in case of a few uncommon transactions
    
    Some invalid txns with splits in the wrong APAR account can be
    processed, creating cases whereby split->owner returns an invalid
    freshly-allocated owner.

diff --git a/gnucash/report/business-reports/new-aging.scm b/gnucash/report/business-reports/new-aging.scm
index 231d9c333..cd5362a99 100644
--- a/gnucash/report/business-reports/new-aging.scm
+++ b/gnucash/report/business-reports/new-aging.scm
@@ -213,6 +213,7 @@ exist but have no suitable transactions."))
          (show-zeros (op-value gnc:pagename-general optname-show-zeros))
          (date-type (op-value gnc:pagename-general optname-date-driver))
          (query (qof-query-create-for-splits))
+         (invalid-splits '())
          (document (gnc:make-html-document)))
 
     ;; for sorting and delete-duplicates. compare GUIDs
@@ -224,6 +225,10 @@ exist but have no suitable transactions."))
       ((if (eq? sort-order 'increasing) string<? string>?)
        (gncOwnerGetName a) (gncOwnerGetName b)))
 
+    (define (html-markup-ol lst)
+      (apply gnc:html-markup "ol"
+             (map (lambda (elt) (gnc:html-markup "li" elt)) lst)))
+
     ;; set default title
     (gnc:html-document-set-title! document report-title)
 
@@ -325,14 +330,45 @@ exist but have no suitable transactions."))
                  (reverse accounts-and-owners))
 
                 (for-each gncOwnerFree tofree)
-                (gnc:html-document-add-object! document table)))))
+                (gnc:html-document-add-object! document table)
+
+                (unless (null? invalid-splits)
+                  (gnc:html-document-add-object!
+                   document (gnc:make-html-text (gnc:html-markup-br)))
+
+                  (gnc:html-document-add-object!
+                   document
+                   (gnc:make-html-text
+                    (_ "Please note some transactions were not processed")
+                    (html-markup-ol
+                     (map
+                      (lambda (invalid-split)
+                        (gnc:html-markup-anchor
+                         (gnc:split-anchor-text (cadr invalid-split))
+                         (car invalid-split)))
+                      invalid-splits)))))))))
 
            (else
             (let* ((account (car accounts))
                    (splits-acc-others (list-split splits split-from-acct? account))
                    (acc-splits (car splits-acc-others))
                    (other-acc-splits (cdr splits-acc-others))
-                   (split-owners (map split->owner acc-splits))
+                   (split-owners
+                    (fold
+                     (lambda (a b)
+                       (let ((owner (split->owner a)))
+                         (cond
+                          ((gncOwnerIsValid owner) (cons owner b))
+                          ;; some payment splits may have no owner in
+                          ;; this account. skip. see bug 797506.
+                          (else
+                           (gnc:warn "split " (gnc:strify a) " has no owner")
+                           (set! invalid-splits
+                             (cons (list (_ "Payment has no owner") a)
+                                   invalid-splits))
+                           (gncOwnerFree owner)
+                           b))))
+                     '() acc-splits))
                    (acc-owners (sort (sort-and-delete-duplicates
                                       split-owners ownerGUID<? gnc-owner-equal?)
                                      owner<?)))



Summary of changes:
 gnucash/report/business-reports/new-aging.scm | 40 +++++++++++++++++++++++++--
 1 file changed, 38 insertions(+), 2 deletions(-)



More information about the gnucash-changes mailing list