gnucash maint: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Mon Nov 25 05:46:17 EST 2019


Updated	 via  https://github.com/Gnucash/gnucash/commit/0973d54d (commit)
	 via  https://github.com/Gnucash/gnucash/commit/9adf8db1 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/aa451bc8 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/d6a5c8ba (commit)
	from  https://github.com/Gnucash/gnucash/commit/a261c8aa (commit)



commit 0973d54d6cb50772de05b4f3ab607e0644ebeb13
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Mon Nov 25 08:07:11 2019 +0800

    [report-utilities] make gnc:owner-splits->aging-list less noisy
    
    invoice processing messages dumped in debug mode. use gnc:msg

diff --git a/gnucash/report/report-system/report-utilities.scm b/gnucash/report/report-system/report-utilities.scm
index ac73a83dd..3422fdeaa 100644
--- a/gnucash/report/report-system/report-utilities.scm
+++ b/gnucash/report/report-system/report-utilities.scm
@@ -1124,7 +1124,8 @@ flawed. see report-utilities.scm. please update reports.")
 ;; Outputs: aging list of numbers
 (define-public (gnc:owner-splits->aging-list splits num-buckets
                                              to-date date-type receivable?)
-  (gnc:pk 'processing: (qof-print-date to-date) date-type 'receivable? receivable?)
+  (gnc:msg "processing " (qof-print-date to-date) " date-type " date-type
+           "receivable? " receivable?)
   (let ((bucket-dates (make-extended-interval-list to-date (- num-buckets 2)))
         (buckets (make-vector num-buckets 0)))
     (define (addbucket! idx amt)
@@ -1148,7 +1149,8 @@ flawed. see report-utilities.scm. please update reports.")
                (date (if (eq? date-type 'postdate)
                          (gncInvoiceGetDatePosted invoice)
                          (gncInvoiceGetDateDue invoice))))
-          (gnc:pk 'next=invoice (car splits) invoice bal)
+          (gnc:msg "next " (gnc:strify (car splits))
+                   " invoice " (gnc:strify invoice) " bal " bal)
           (let loop ((idx 0) (bucket-dates bucket-dates))
             (if (< date (car bucket-dates))
                 (addbucket! idx bal)
@@ -1170,14 +1172,15 @@ flawed. see report-utilities.scm. please update reports.")
                        (- payment-left (gncInvoiceGetTotal (car inv-and-splits)))
                        payment-left))
                  (if receivable? (- payment) payment) invoices-and-splits)))
-          (gnc:pk 'payment (car splits) payment "->" overpayment)
+          (gnc:msg "next " (gnc:strify (car splits)) " payment " payment
+                   " overpayment " overpayment)
           (when (positive? overpayment)
             (addbucket! (1- num-buckets) (- overpayment)))
           (lp (cdr splits) invoices-and-splits)))
 
        ;; not invoice/prepayment. regular or payment split.
        (else
-        (gnc:pk 'next=skipped (car splits))
+        (gnc:msg "next " (gnc:strify (car splits)) " skipped")
         (lp (cdr splits) invoices-and-splits))))))
 
 ;; ***************************************************************************

commit 9adf8db1a2910f637d5773ae3f4ff34d1a7b317a
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Nov 24 21:01:04 2019 +0800

    [report-utilities] gnc:strify can render vectors too

diff --git a/gnucash/report/report-system/report-utilities.scm b/gnucash/report/report-system/report-utilities.scm
index 20cf23c15..ac73a83dd 100644
--- a/gnucash/report/report-system/report-utilities.scm
+++ b/gnucash/report/report-system/report-utilities.scm
@@ -1260,6 +1260,10 @@ flawed. see report-utilities.scm. please update reports.")
                       "(list "
                       (string-join (map gnc:strify d) " ")
                       ")"))
+      (and (vector? d) (string-append
+                        "(vector "
+                        (string-join (map gnc:strify (vector->list d)) " ")
+                        ")"))
       (and (pair? d) (format #f "(~a . ~a)"
                              (gnc:strify (car d))
                              (if (eq? (car d) 'absolute)

commit aa451bc89d5d1a5a1e66df4501e90e533683cb0b
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Nov 24 21:57:00 2019 +0800

    [balsheet-pnl] compact functions
    
    readability fixes

diff --git a/gnucash/report/standard-reports/balsheet-pnl.scm b/gnucash/report/standard-reports/balsheet-pnl.scm
index 0a19293ab..de0d44e49 100644
--- a/gnucash/report/standard-reports/balsheet-pnl.scm
+++ b/gnucash/report/standard-reports/balsheet-pnl.scm
@@ -814,24 +814,20 @@ also show overall period profit & loss."))
          ;; into report-currency if the latter exists. The price
          ;; applicable the the col-idx column is used. If the monetary
          ;; cannot be converted (eg. missing price) then it is not converted.
-         (convert-curr-fn (lambda (monetary col-idx)
-                            (and common-currency
-                                 (not (gnc-commodity-equal
-                                       (gnc:gnc-monetary-commodity monetary)
-                                       common-currency))
-                                 (has-price? (gnc:gnc-monetary-commodity monetary))
-                                 (let ((date
-                                        (cond
-                                         ((eq? price-source 'pricedb-latest)
-                                          (current-time))
-                                         ((eq? col-idx 'overall-period)
-                                          (last report-dates))
-                                         (else
-                                          (list-ref report-dates
-                                                    (case report-type
-                                                      ((balsheet) col-idx)
-                                                      ((pnl) (1+ col-idx))))))))
-                                   (exchange-fn monetary common-currency date)))))
+         (convert-curr-fn
+          (lambda (monetary col-idx)
+            (and common-currency
+                 (not (gnc-commodity-equal
+                       (gnc:gnc-monetary-commodity monetary)
+                       common-currency))
+                 (has-price? (gnc:gnc-monetary-commodity monetary))
+                 (exchange-fn
+                  monetary common-currency
+                  (cond
+                   ((eq? price-source 'pricedb-latest) (current-time))
+                   ((eq? col-idx 'overall-period) (last report-dates))
+                   ((eq? report-type 'balsheet) (list-ref report-dates col-idx))
+                   ((eq? report-type 'pnl) (list-ref report-dates (1+ col-idx))))))))
 
          ;; the following function generates an gnc:html-text object
          ;; to dump exchange rate for a particular column. From the
@@ -930,9 +926,7 @@ also show overall period profit & loss."))
      ((eq? report-type 'balsheet)
       (let* ((get-cell-monetary-fn
               (lambda (account col-idx)
-                (let ((account-balance-list (assoc-ref accounts-balances account)))
-                  (and account-balance-list
-                       (list-ref account-balance-list col-idx)))))
+                (list-ref (assoc-ref accounts-balances account) col-idx)))
 
              ;; an alist of (cons account vector-of-splits) where each
              ;; split is the last one at date boundary
@@ -1017,6 +1011,7 @@ also show overall period profit & loss."))
                       (map
                        gnc:monetary-neg
                        (income-expense-balance 'format gnc:make-gnc-monetary #f))))))
+
              (chart (and include-chart? incr
                          (gnc:make-report-anchor
                           networth-barchart-uuid report-obj

commit d6a5c8ba5409138901bf451588531827d31172b3
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Nov 24 21:38:42 2019 +0800

    [balsheet-pnl] accumulate column data report-dates
    
    Previous would call gnc:account-get-balances-at-dates and
    gnc:account-accumulate-at-dates to retrieve balances and
    last-split. This commit reduces the O(2*N) operation to O(N) which
    becomes significant with accounts with large number of splits.
    
    Maybe we can reduce other account splitlist scans in the future; these
    will be easier and would only require augmenting the record.

diff --git a/gnucash/report/standard-reports/balsheet-pnl.scm b/gnucash/report/standard-reports/balsheet-pnl.scm
index 2cf5d745a..0a19293ab 100644
--- a/gnucash/report/standard-reports/balsheet-pnl.scm
+++ b/gnucash/report/standard-reports/balsheet-pnl.scm
@@ -31,9 +31,18 @@
 (use-modules (gnucash gettext))
 (use-modules (srfi srfi-1))
 (use-modules (srfi srfi-2))
+(use-modules (srfi srfi-9))
 
 (gnc:module-load "gnucash/report/report-system" 0)
 
+;; the column-data record. the gnc:account-accumulate-at-dates will
+;; create a record for each report-date with split-data as follows:
+(define-record-type :col-datum
+  (make-datum last-split split-balance)
+  col-datum?
+  (last-split col-datum-get-last-split)
+  (split-balance col-datum-get-split-balance))
+
 (define FOOTER-TEXT
   (gnc:make-html-text
    (_ "WARNING: Foreign currency conversions, and unrealized gains
@@ -770,12 +779,31 @@ also show overall period profit & loss."))
            ((eq? report-type 'pnl) (list startdate enddate))
            (else (list enddate))))
 
-         (accounts-balances (map
-                             (lambda (acc)
-                               (cons acc
-                                     (gnc:account-get-balances-at-dates
-                                      acc report-dates)))
-                             accounts))
+         ;; an alist of (cons account account-cols-data) whereby
+         ;; account-cols-data is a list of col-datum records
+         (accounts-cols-data
+          (map
+           (lambda (acc)
+             (let* ((comm (xaccAccountGetCommodity acc))
+                    (amt->monetary (lambda (amt) (gnc:make-gnc-monetary comm amt))))
+               (cons acc
+                     (gnc:account-accumulate-at-dates
+                      acc report-dates
+                      #:nosplit->elt (make-datum #f (amt->monetary 0))
+                      #:split->elt
+                      (lambda (s)
+                        (make-datum s (amt->monetary (xaccSplitGetBalance s))))))))
+           accounts))
+
+         ;; an alist of (cons account account-balances) whereby
+         ;; account-balances is a list of monetary amounts
+         (accounts-balances
+          (map
+           (lambda (acc)
+             (cons acc (let ((cols-data (assoc-ref accounts-cols-data acc)))
+                         (map col-datum-get-split-balance cols-data))))
+           accounts))
+
          (exchange-fn (and common-currency
                            (gnc:case-exchange-time-fn
                             price-source common-currency
@@ -906,13 +934,14 @@ also show overall period profit & loss."))
                   (and account-balance-list
                        (list-ref account-balance-list col-idx)))))
 
-             ;; an alist of account->last-split at date boundary
+             ;; an alist of (cons account vector-of-splits) where each
+             ;; split is the last one at date boundary
              (accounts-splits-dates
               (map
                (lambda (acc)
-                 (cons acc (list->vector
-                            (gnc:account-accumulate-at-dates
-                             acc report-dates #:split->elt identity))))
+                 (cons acc (let ((cols-data (assoc-ref accounts-cols-data acc)))
+                             (list->vector
+                              (map col-datum-get-last-split cols-data)))))
                accounts))
 
              (get-cell-anchor-fn



Summary of changes:
 gnucash/report/report-system/report-utilities.scm | 15 ++--
 gnucash/report/standard-reports/balsheet-pnl.scm  | 86 +++++++++++++++--------
 2 files changed, 66 insertions(+), 35 deletions(-)



More information about the gnucash-changes mailing list