gnucash master: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Fri May 29 09:51:15 EDT 2020


Updated	 via  https://github.com/Gnucash/gnucash/commit/def9a161 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/c434239b (commit)
	 via  https://github.com/Gnucash/gnucash/commit/8717c5c3 (commit)
	from  https://github.com/Gnucash/gnucash/commit/efb9abfb (commit)



commit def9a1610c048fee9598076066f26224ca6604fc
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Fri May 29 21:11:39 2020 +0800

    Use gnc:split->owner instead of gnc:owner-from-split

diff --git a/gnucash/report/reports/standard/new-owner-report.scm b/gnucash/report/reports/standard/new-owner-report.scm
index 34e2b3683..d222388b7 100644
--- a/gnucash/report/reports/standard/new-owner-report.scm
+++ b/gnucash/report/reports/standard/new-owner-report.scm
@@ -1219,12 +1219,11 @@ invoices and amounts.")))))
 (define (gnc:owner-report-create-internal
          account split query journal? double? title debit-string credit-string)
 
-  (let* ((temp-owner (gncOwnerNew))
-         (owner (gnc:owner-from-split split temp-owner))
-         (res (if (null? owner)
-                  -1
-                  (owner-report-create owner account))))
-    (gncOwnerFree temp-owner)
+  (let* ((owner (gnc:split->owner split))
+         (res (if (gncOwnerIsValid owner)
+                  (owner-report-create owner account)
+                  -1)))
+    (gnc:split->owner #f)
     res))
 
 (gnc:register-report-hook ACCT-TYPE-RECEIVABLE #t gnc:owner-report-create-internal)

commit c434239b7d9213095de3f00b2e6bdf042ec425f1
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Fri May 29 21:11:15 2020 +0800

    Upgrade split->owner to gnc:split->owner

diff --git a/bindings/guile/business-core.scm b/bindings/guile/business-core.scm
index 3093cb8f5..30c56d73e 100644
--- a/bindings/guile/business-core.scm
+++ b/bindings/guile/business-core.scm
@@ -99,6 +99,8 @@
 ;; result-owner argument is mutated to it.
 (define (gnc:owner-from-split split result-owner)
   (define (notnull x) (and (not (null? x)) x))
+  (issue-deprecation-warning
+   "gnc:owner-from-split is deprecated. use gnc:split->owner instead.")
   (let* ((trans (xaccSplitGetParent split))
 	 (invoice (notnull (gncInvoiceGetInvoiceFromTxn trans)))
 	 (temp (gncOwnerNew))
@@ -114,3 +116,27 @@
     (cond (owner (gncOwnerCopy (gncOwnerGetEndOwner owner) result-owner)
                  result-owner)
           (else  '()))))
+
+
+;; optimized from above, and simpler: does not search all transaction
+;; splits. It will allocate and memoize (cache) the owners because
+;; gncOwnerGetOwnerFromLot is slow. after use, it must be called with
+;; #f to free the owners.
+(define gnc:split->owner
+  (let ((ht (make-hash-table)))
+    (lambda (split)
+      (cond
+       ((not split)
+        (hash-for-each (lambda (k v) (gncOwnerFree v)) ht)
+        (hash-clear! ht))
+       ((hashv-ref ht (string-hash (gncSplitGetGUID split))) => identity)
+       (else
+        (let ((lot (xaccSplitGetLot split))
+              (owner (gncOwnerNew)))
+          (unless (gncOwnerGetOwnerFromLot lot owner)
+            (gncOwnerCopy (gncOwnerGetEndOwner
+                           (gncInvoiceGetOwner
+                            (gncInvoiceGetInvoiceFromLot lot)))
+                          owner))
+          (hashv-set! ht (string-hash (gncSplitGetGUID split)) owner)
+          owner))))))
diff --git a/bindings/guile/engine.scm b/bindings/guile/engine.scm
index 06f8d0af4..da91cf47c 100644
--- a/bindings/guile/engine.scm
+++ b/bindings/guile/engine.scm
@@ -73,6 +73,7 @@
 (export gnc:owner-get-name-and-address-dep)
 (export gnc:owner-get-owner-id)
 (export gnc:owner-from-split)
+(export gnc:split->owner)
 
 (load-from-path "gnucash/engine/gnc-numeric")
 (load-from-path "gnucash/engine/commodity-table")
diff --git a/gnucash/report/reports/standard/new-aging.scm b/gnucash/report/reports/standard/new-aging.scm
index fa8858c00..a03483b0f 100644
--- a/gnucash/report/reports/standard/new-aging.scm
+++ b/gnucash/report/reports/standard/new-aging.scm
@@ -171,10 +171,10 @@ exist but have no suitable transactions."))
              (eqv? type TXN-TYPE-PAYMENT)))))
 
 (define (split-has-owner? split owner)
-  (gncOwnerEqual (split->owner split) owner))
+  (gncOwnerEqual (gnc:split->owner split) owner))
 
 (define (split-owner-is-invalid? split)
-  (not (gncOwnerIsValid (split->owner split))))
+  (not (gncOwnerIsValid (gnc:split->owner split))))
 
 (define (split-from-acct? split acct)
   (equal? acct (xaccSplitGetAccount split)))
@@ -183,28 +183,6 @@ exist but have no suitable transactions."))
   (let-values (((list-yes list-no) (partition (lambda (elt) (fn elt cmp)) lst)))
     (cons list-yes list-no)))
 
-;; optimized from gnc:owner-from-split. It will allocate and memoize
-;; (cache) the owners because gncOwnerGetOwnerFromLot is slow. after
-;; use, it must be called with #f to free the owners.
-(define split->owner
-  (let ((ht (make-hash-table)))
-    (lambda (split)
-      (cond
-       ((not split)
-        (hash-for-each (lambda (k v) (gncOwnerFree v)) ht)
-        (hash-clear! ht))
-       ((hashv-ref ht (string-hash (gncSplitGetGUID split))) => identity)
-       (else
-        (let ((lot (xaccSplitGetLot split))
-              (owner (gncOwnerNew)))
-          (unless (gncOwnerGetOwnerFromLot lot owner)
-            (gncOwnerCopy (gncOwnerGetEndOwner
-                           (gncInvoiceGetOwner
-                            (gncInvoiceGetInvoiceFromLot lot)))
-                          owner))
-          (hashv-set! ht (string-hash (gncSplitGetGUID split)) owner)
-          owner))))))
-
 (define (aging-renderer report-obj receivable)
   (define options (gnc:report-options report-obj))
   (define (op-value section name)
@@ -264,6 +242,10 @@ exist but have no suitable transactions."))
       (let* ((splits (xaccQueryGetSplitsUniqueTrans query)))
         (qof-query-destroy query)
 
+        ;; split->owner hashtable should be empty at the start of
+        ;; report renderer. clear it anyway.
+        (gnc:split->owner #f)
+
         ;; loop into each APAR account
         (let loop ((accounts accounts)
                    (splits splits)
@@ -345,7 +327,7 @@ exist but have no suitable transactions."))
                         acc-totals)))))
                  (reverse accounts-and-owners))
 
-                (split->owner #f)       ;free the gncOwners
+                (gnc:split->owner #f)       ;free the gncOwners
                 (gnc:html-document-add-object! document table)
 
                 (unless (null? invalid-splits)
@@ -402,7 +384,7 @@ exist but have no suitable transactions."))
                        owners-and-aging))
 
                   ((this . _)
-                   (match-let* ((owner (split->owner this))
+                   (match-let* ((owner (gnc:split->owner this))
                                 ((owner-splits . other-owner-splits)
                                  (list-split acc-splits split-has-owner? owner))
                                 (aging (gnc:owner-splits->aging-list

commit 8717c5c3ccc8e86d03b01844aeb6a767a37a60db
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Fri May 29 21:01:13 2020 +0800

    Bugfix new reports

diff --git a/gnucash/report/reports/standard/new-aging.scm b/gnucash/report/reports/standard/new-aging.scm
index c2e1eb36d..fa8858c00 100644
--- a/gnucash/report/reports/standard/new-aging.scm
+++ b/gnucash/report/reports/standard/new-aging.scm
@@ -483,11 +483,11 @@ exist but have no suitable transactions."))
 
 (define (gnc:receivables-create-internal
          account split query journal? double? title debit-string credit-string)
-  (receivables-report-create-internal #f #f))
+  (receivables-report-create-internal account #f #f))
 
 (define (gnc:payables-create-internal
          account split query journal? double? title debit-string credit-string)
-  (payables-report-create-internal #f #f))
+  (payables-report-create-internal account #f #f))
 
 (gnc:register-report-hook ACCT-TYPE-RECEIVABLE #f gnc:receivables-create-internal)
 (gnc:register-report-hook ACCT-TYPE-PAYABLE #f gnc:payables-create-internal)
diff --git a/gnucash/report/reports/standard/new-owner-report.scm b/gnucash/report/reports/standard/new-owner-report.scm
index a745589a0..34e2b3683 100644
--- a/gnucash/report/reports/standard/new-owner-report.scm
+++ b/gnucash/report/reports/standard/new-owner-report.scm
@@ -1223,7 +1223,7 @@ invoices and amounts.")))))
          (owner (gnc:owner-from-split split temp-owner))
          (res (if (null? owner)
                   -1
-                  (owner-report-create owner))))
+                  (owner-report-create owner account))))
     (gncOwnerFree temp-owner)
     res))
 



Summary of changes:
 bindings/guile/business-core.scm                   | 26 +++++++++++++++
 bindings/guile/engine.scm                          |  1 +
 gnucash/report/reports/standard/new-aging.scm      | 38 ++++++----------------
 .../report/reports/standard/new-owner-report.scm   | 11 +++----
 4 files changed, 42 insertions(+), 34 deletions(-)



More information about the gnucash-changes mailing list