gnucash maint: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Sat Jul 6 11:16:02 EDT 2019


Updated	 via  https://github.com/Gnucash/gnucash/commit/bb6d84e0 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/463c3124 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/b9382d2c (commit)
	 via  https://github.com/Gnucash/gnucash/commit/e783335c (commit)
	 via  https://github.com/Gnucash/gnucash/commit/dd1873eb (commit)
	 via  https://github.com/Gnucash/gnucash/commit/4214f7eb (commit)
	 via  https://github.com/Gnucash/gnucash/commit/1e66d3b2 (commit)
	from  https://github.com/Gnucash/gnucash/commit/bc1bcc71 (commit)



commit bb6d84e03d5920d79c63e446eb145050f741c715
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Fri Jul 5 21:54:38 2019 +0800

    [html-utilities] [API] further deprecations
    
    * gnc:html-build-acct-table -- unused for decades
    * gnc:html-table-append-ruler/markup
    * gnc:html-acct-table-row-helper!
    * gnc:html-acct-table-comm-row-helper!

diff --git a/gnucash/report/report-system/html-utilities.scm b/gnucash/report/report-system/html-utilities.scm
index 3e94d5aa3..dd569413c 100644
--- a/gnucash/report/report-system/html-utilities.scm
+++ b/gnucash/report/report-system/html-utilities.scm
@@ -153,6 +153,8 @@
   (gnc:html-table-append-ruler/at! table 0 colspan))
 
 (define (gnc:html-table-append-ruler/markup! table markup colspan)
+  (issue-deprecation-warning
+   "gnc:html-table-append-ruler/markup! is unused.")
   (gnc:html-table-append-ruler/at/markup! table markup 0 colspan))
 
 ;; Creates a table cell with some text in it. The cell will be created
@@ -181,6 +183,8 @@
 	 table tree-depth
 	 current-depth my-name my-balance 
 	 reverse-balance? row-style boldface? group-header-line?)
+  (issue-deprecation-warning
+   "gnc:html-acct-table-row-helper! is unused.")
   (gnc:html-table-append-row/markup! 
    table
    row-style
@@ -223,6 +227,8 @@
 	 current-depth my-name my-commodity balance 
 	 reverse-balance? is-stock-account? main-row-style other-rows-style 
 	 boldface? group-header-line?) 
+  (issue-deprecation-warning
+   "gnc:html-acct-table-comm-row-helper! is unused.")
   (let ((already-printed #f))
     ;; Adds one row to the table. my-name is the html-object
     ;; displayed in the name column; foreign-balance is the
@@ -402,6 +408,8 @@
 	 show-total? get-total-fn
 	 total-name group-types? show-parent-balance? show-parent-total? 
 	 show-other-curr? report-commodity exchange-fn show-zero-entries?)
+  (issue-deprecation-warning
+   "gnc:html-build-acct-table is unused.")
   (let ((table (gnc:make-html-table))
 	(work-to-do 0)
 	(work-done 0)

commit 463c3124ef51fc5d7ec4c349dd2646f7b9ad1ffa
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Fri Jul 5 21:50:52 2019 +0800

    [commodity-utilities] [API] deprecate gnc:sum-collector-stocks
    
    this function is never reachable in code

diff --git a/gnucash/report/report-system/commodity-utilities.scm b/gnucash/report/report-system/commodity-utilities.scm
index 29d6aac58..592da3648 100644
--- a/gnucash/report/report-system/commodity-utilities.scm
+++ b/gnucash/report/report-system/commodity-utilities.scm
@@ -939,6 +939,8 @@ construct with gnc:make-gnc-monetary and gnc:monetary->string instead.")
 ;; which (still) may have several different commodities in it -- if
 ;; there have been different *currencies*, not only stocks.
 (define (gnc:sum-collector-stocks foreign domestic exchange-fn)
+  (issue-deprecation-warning
+   "gnc:sum-collector-stocks is never used in code.")
   (and foreign
        (let ((balance (gnc:make-commodity-collector)))
          (foreign
diff --git a/gnucash/report/standard-reports/balance-sheet.scm b/gnucash/report/standard-reports/balance-sheet.scm
index 807ebb5e7..de1ba8fd9 100644
--- a/gnucash/report/standard-reports/balance-sheet.scm
+++ b/gnucash/report/standard-reports/balance-sheet.scm
@@ -406,11 +406,7 @@
 	 1 "total-number-cell")
 	)
       )
-    ;; (gnc:sum-collector-stocks balance report-commodity exchange-fn)
-    ;; Hey! Look at that! This rolls the stocks into the balance!
-    ;; Can anyone think of a reason why this would be desirable?
-    ;; None come to (my) mind.  Perhaps this should be a report option?
-    
+
     ;; Wrapper around gnc:html-table-append-ruler! since we call it so
     ;; often.
     (define (add-rule table)

commit b9382d2cf22ae1549f144bd64b1fe9b7bfcaa3f5
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Jul 6 18:20:18 2019 +0800

    [commodity-utilities] move gnc:debug to less CPU critical code
    
    pricealist is a long list generated once, yet is dumped via gnc:debug
    for every call to gnc:exchange-by-pricealist-nearest. This change
    moves gnc:debug to the initial pricealist generation, ensuring that
    gnc:exchange-by-pricealist-nearest is much faster.

diff --git a/gnucash/report/report-system/commodity-utilities.scm b/gnucash/report/report-system/commodity-utilities.scm
index c64ca0efa..29d6aac58 100644
--- a/gnucash/report/report-system/commodity-utilities.scm
+++ b/gnucash/report/report-system/commodity-utilities.scm
@@ -803,7 +803,6 @@ construct with gnc:make-gnc-monetary and gnc:monetary->string instead.")
   ;;Used in weighted-average gnc:case-exchange-time-fn only.
   (gnc:debug "foreign " (gnc:monetary->string foreign))
   (gnc:debug "domestic " (gnc-commodity-get-printname domestic))
-  (gnc:debug "pricealist " pricealist)
   (and (record? foreign)
        (gnc:gnc-monetary? foreign)
        date
@@ -873,6 +872,7 @@ construct with gnc:make-gnc-monetary and gnc:monetary->string instead.")
                                (gnc:get-commoditylist-totalavg-prices
                                 commodity-list report-currency to-date-tp
                                 start-percent delta-percent)))
+                          (gnc:debug "weighted-average pricealist " pricealist)
                           (lambda (foreign domestic date)
                             (gnc:exchange-by-pricealist-nearest
                              pricealist foreign domestic date))))

commit e783335cf26521fd9faa5854d3393e51bd880a43
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Fri Jul 5 23:09:19 2019 +0800

    [commodity-utilities] compact gnc:sum-collector-commodity
    
    This function converted to purely functional approach.
    
    Note that commodity-collectors always round amounts to the currency
    SCU therefore we replicate the behaviour here.

diff --git a/gnucash/report/report-system/commodity-utilities.scm b/gnucash/report/report-system/commodity-utilities.scm
index 65c203259..c64ca0efa 100644
--- a/gnucash/report/report-system/commodity-utilities.scm
+++ b/gnucash/report/report-system/commodity-utilities.scm
@@ -924,21 +924,15 @@ construct with gnc:make-gnc-monetary and gnc:monetary->string instead.")
 (define (gnc:sum-collector-commodity foreign domestic exchange-fn)
   (and foreign
        exchange-fn
-       (let ((balance (gnc:make-commodity-collector)))
-         (foreign
-          'format
-          (lambda (curr val)
-            (if (gnc-commodity-equiv domestic curr)
-                (balance 'add domestic val)
-                (balance 'add domestic
-                         (gnc:gnc-monetary-amount
-                          ;; BUG?: this bombs if the exchange-fn
-                          ;; returns #f instead of an actual
-                          ;; <gnc:monetary>.  Better to just return #f.
-                          (exchange-fn (gnc:make-gnc-monetary curr val)
-                                       domestic)))))
-          #f)
-         (balance 'getmonetary domestic #f))))
+       (gnc:make-gnc-monetary
+        domestic
+        (apply + (map
+                  (lambda (mon)
+                    (gnc-numeric-convert
+                     (gnc:gnc-monetary-amount (exchange-fn mon domestic))
+                     (gnc-commodity-get-fraction domestic)
+                     GNC-RND-ROUND))
+                  (foreign 'format gnc:make-gnc-monetary #f))))))
 
 ;; As above, but adds only the commodities of other stocks and
 ;; mutual-funds. Returns a commodity-collector, (not a <gnc:monetary>)

commit dd1873eb0571848d1e40be5316ae8155372c82dd
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Fri Jul 5 23:09:12 2019 +0800

    [test-cash-flow] fix test which was badly designed
    
    this test had confused 2 functions:
    
    (exchange-fn monetary currency) --> monetary
      and
    (to-report-currency currency amount date) --> amount
    
    this flaw surfaces with the shortened gnc:sum-collector-commodity definition.

diff --git a/gnucash/report/standard-reports/test/test-cash-flow.scm b/gnucash/report/standard-reports/test/test-cash-flow.scm
index 8061376ed..09a5a10a7 100644
--- a/gnucash/report/standard-reports/test/test-cash-flow.scm
+++ b/gnucash/report/standard-reports/test/test-cash-flow.scm
@@ -23,6 +23,10 @@
          (new-secs (- t64 day-secs)))
     new-secs))
 
+(define (to-report-currency curr amt date) amt)
+
+(define (exchange-fn mon comm) mon)
+
 (define (test-one-tx-in-cash-flow)
   (let* ((env (create-test-env))
 	 (account-alist (env-create-account-structure-alist env structure))
@@ -32,7 +36,6 @@
 	 (today (gnc-localtime (current-time)))
          (to-date-t64 (gnc-dmy2time64-end (tm:mday today) (+ 1 (tm:mon today)) (+ 1900 (tm:year today))))
          (from-date-t64 (NDayDelta to-date-t64 1))
-	 (exchange-fn (lambda (currency amount date) amount))
 	 (report-currency (gnc-default-report-currency))
 	 )
     (env-create-transaction env to-date-t64 bank-account expense-account 100/1)
@@ -41,7 +44,7 @@
 						     (cons 'from-date-t64 from-date-t64)
 						     (cons 'report-currency report-currency)
 						     (cons 'include-trading-accounts #f)
-						     (cons 'to-report-currency exchange-fn)))))
+						     (cons 'to-report-currency to-report-currency)))))
       (let* ((money-in-collector (cdr (assq 'money-in-collector result)))
 	     (money-out-collector (cdr (assq 'money-out-collector result)))
 	     (money-in-alist (cdr (assq 'money-in-alist result)))
@@ -76,7 +79,6 @@
 	 (today (gnc-localtime (current-time)))
          (to-date-t64 (gnc-dmy2time64-end (tm:mday today) (+ 1 (tm:mon today)) (+ 1900 (tm:year today))))
          (from-date-t64 (NDayDelta to-date-t64 1))
-	 (exchange-fn (lambda (currency amount date) amount))
 	 (report-currency (gnc-default-report-currency))
 	 )
     (env-create-transaction env to-date-t64 bank-account wallet-account 100/1)
@@ -85,7 +87,7 @@
 						     (cons 'from-date-t64 from-date-t64)
 						     (cons 'report-currency report-currency)
 						     (cons 'include-trading-accounts #f)
-						     (cons 'to-report-currency exchange-fn)))))
+						     (cons 'to-report-currency to-report-currency)))))
       (let* ((money-in-collector (cdr (assq 'money-in-collector result)))
 	     (money-out-collector (cdr (assq 'money-out-collector result)))
 	     (money-in-alist (cdr (assq 'money-in-alist result)))
@@ -110,7 +112,6 @@
 	 (today (gnc-localtime (current-time)))
          (to-date-t64 (gnc-dmy2time64-end (tm:mday today) (+ 1 (tm:mon today)) (+ 1900 (tm:year today))))
          (from-date-t64 (NDayDelta to-date-t64 1))
-	 (exchange-fn (lambda (currency amount date) amount))
 	 (report-currency (gnc-default-report-currency))
 	 )
     (env-create-transaction env to-date-t64 bank-account expense-account 100/1)
@@ -120,7 +121,7 @@
 						     (cons 'from-date-t64 from-date-t64)
 						     (cons 'report-currency report-currency)
 						     (cons 'include-trading-accounts #f)
-						     (cons 'to-report-currency exchange-fn)))))
+						     (cons 'to-report-currency to-report-currency)))))
       (let* ((money-in-collector (cdr (assq 'money-in-collector result)))
 	     (money-out-collector (cdr (assq 'money-out-collector result)))
 	     (money-in-alist (cdr (assq 'money-in-alist result)))

commit 4214f7eb76cc899e475b9af3b2790d8528a269dd
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Jul 6 14:32:53 2019 +0800

    [balsheet-pnl] bugfix prevent crash on missing accts
    
    When asset/liability/income/expense accounts are either missing or
    deselected, the report would crash. This commit will ensure the
    date-specific balance calculators do not crash.
    
    The reason for crash is the form (apply map gnc:monetaries-add lists)
    where lists is usually a list-of-list-of-monetaries, e.g.
    (list (list $1.00 $2.00 $3.00)
          (list $2.35 $3.44 $4.45))
    
    and (apply map gnc:monetaries-add lists) will return a list of the
    matched sums, i.e. commodity-collectors (list (list <$3.35> <$5.44>
    <$7.45>)), whereby each commodity-collector is denoted by <...>
    
    When there are missing account-types (or deselected) the lists are
    empty-lists, therefore mapping will fail. This change ensures that
    null-lists are handled by returning (list (list <> <> <>)), with null
    commodity-collectors.

diff --git a/gnucash/report/standard-reports/balsheet-pnl.scm b/gnucash/report/standard-reports/balsheet-pnl.scm
index 5c2f7885e..2dbadf1eb 100644
--- a/gnucash/report/standard-reports/balsheet-pnl.scm
+++ b/gnucash/report/standard-reports/balsheet-pnl.scm
@@ -905,31 +905,42 @@ also show overall period profit & loss."))
                        (valid-splits (filter valid-split? splits)))
                   (and (pair? valid-splits)
                        (gnc:split-anchor-text (last valid-splits))))))
+
              (asset-liability-balances
-              (apply map gnc:monetaries-add
+              (let ((asset-liab-balances
                      (map cdr (filter
                                (lambda (acc-balances)
                                  (member (car acc-balances)
                                          (append asset-accounts liability-accounts)))
                                accounts-balances))))
+                (if (null? asset-liab-balances)
+                    (map (const (gnc:make-commodity-collector)) report-dates)
+                    (apply map gnc:monetaries-add asset-liab-balances))))
+
              (income-expense-balances
-              (map gnc:commodity-collector-get-negated
-                   (apply map gnc:monetaries-add
-                          (map cdr
-                               (filter
-                                (lambda (acc-balances)
-                                  (member (car acc-balances)
-                                          (append income-accounts expense-accounts)))
-                                accounts-balances)))))
+              (let ((inc-exp-balances
+                     (map cdr
+                          (filter
+                           (lambda (acc-balances)
+                             (member (car acc-balances)
+                                     (append income-accounts expense-accounts)))
+                           accounts-balances))))
+                (if (null? inc-exp-balances)
+                    (map (const (gnc:make-commodity-collector)) report-dates)
+                    (map gnc:commodity-collector-get-negated
+                         (apply map gnc:monetaries-add inc-exp-balances)))))
+
              (monetaries->exchanged
               (lambda (monetaries target-currency price-source date)
                 (let ((exchange-fn (gnc:case-exchange-fn
                                     price-source target-currency date)))
                   (apply gnc:monetary+
-                         (map
-                          (lambda (mon)
-                            (exchange-fn mon target-currency))
-                          (monetaries 'format gnc:make-gnc-monetary #f))))))
+                         (cons (gnc:make-gnc-monetary target-currency 0)
+                               (map
+                                (lambda (mon)
+                                  (exchange-fn mon target-currency))
+                                (monetaries 'format gnc:make-gnc-monetary #f)))))))
+
              (unrealized-gain-fn
               (lambda (col-idx)
                 (and common-currency

commit 1e66d3b2f6406814efa185bc62cea4252fd79d45
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Fri Jul 5 21:45:44 2019 +0800

    [balsheet-pnl] cosmetic: improve maxindent calc
    
    75ab45ac3 without 1+ some alignment is incorrect

diff --git a/gnucash/report/standard-reports/balsheet-pnl.scm b/gnucash/report/standard-reports/balsheet-pnl.scm
index 955b8127f..5c2f7885e 100644
--- a/gnucash/report/standard-reports/balsheet-pnl.scm
+++ b/gnucash/report/standard-reports/balsheet-pnl.scm
@@ -866,7 +866,8 @@ also show overall period profit & loss."))
          (multicol-table-right (if enable-dual-columns?
                                    (gnc:make-html-table)
                                    multicol-table-left))
-         (maxindent (apply max (cons 0 (map gnc-account-get-current-depth accounts)))))
+         (maxindent (1+ (apply max (cons 0 (map gnc-account-get-current-depth
+                                                accounts))))))
 
     (gnc:html-document-set-title!
      doc (with-output-to-string



Summary of changes:
 .../report/report-system/commodity-utilities.scm   | 28 +++++++--------
 gnucash/report/report-system/html-utilities.scm    |  8 +++++
 gnucash/report/standard-reports/balance-sheet.scm  |  6 +---
 gnucash/report/standard-reports/balsheet-pnl.scm   | 40 ++++++++++++++--------
 .../standard-reports/test/test-cash-flow.scm       | 13 +++----
 5 files changed, 54 insertions(+), 41 deletions(-)



More information about the gnucash-changes mailing list