gnucash maint: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Sat Nov 30 03:35:23 EST 2019


Updated	 via  https://github.com/Gnucash/gnucash/commit/0b11a073 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/c21bb66d (commit)
	 via  https://github.com/Gnucash/gnucash/commit/def0caa0 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/e97b78df (commit)
	 via  https://github.com/Gnucash/gnucash/commit/54c4575f (commit)
	 via  https://github.com/Gnucash/gnucash/commit/34c14b44 (commit)
	from  https://github.com/Gnucash/gnucash/commit/7853f5a2 (commit)



commit 0b11a073f0d2f14ea54dbec50ca18ca7d28b4d5f
Merge: c21bb66d6 34c14b44a
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Nov 30 16:34:48 2019 +0800

    Merge branch 'maint' of git://github.com/andrey-legayev/gnucash into maint


commit c21bb66d689972042c95694801f9932e8b982a97
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Thu Nov 28 22:42:31 2019 +0800

    [balsheet-pnl] refactor common account-balance-list adder
    
    * use fold, more efficient, removes the need for intermediate list
    
      (map cdr (filter filter-fn accounts-balances)): filter will create 1
      intermediate list, which is passed as an argument to map which
      creates the final list. using fold will remove the need for
      intermediate list.
    
    * list->vector for O(1) access

diff --git a/gnucash/report/standard-reports/balsheet-pnl.scm b/gnucash/report/standard-reports/balsheet-pnl.scm
index 566c659e4..ac616febc 100644
--- a/gnucash/report/standard-reports/balsheet-pnl.scm
+++ b/gnucash/report/standard-reports/balsheet-pnl.scm
@@ -909,6 +909,15 @@ also show overall period profit & loss."))
          (maxindent (1+ (apply max (cons 0 (map gnc-account-get-current-depth
                                                 accounts))))))
 
+    (define (sum-balances-of-accounts alist accts adder)
+      (let ((balances
+             (fold (lambda (a b) (if (member (car a) accts) (cons (cdr a) b) b))
+                   '() alist)))
+        (list->vector
+         (if (null? balances)
+             (map (const (adder)) report-dates)
+             (apply map adder balances)))))
+
     (gnc:html-document-set-title!
      doc (with-output-to-string
            (lambda ()
@@ -952,33 +961,19 @@ also show overall period profit & loss."))
                            (split (vector-ref date-splits col-idx)))
                   (gnc:split-anchor-text split))))
 
-             ;; a list of collectors whereby collector is the sum of
+             ;; a vector of collectors whereby collector is the sum of
              ;; asset and liabilities at report dates
              (asset-liability-balances
-              (let ((asset-liab-balances
-                     (map cdr (filter
-                               (lambda (acc-balances)
-                                 (member (car acc-balances) asset-liability))
-                               accounts-balances))))
-                (if (null? asset-liab-balances)
-                    (map (const (gnc:make-commodity-collector)) report-dates)
-                    (apply map gnc:monetaries-add asset-liab-balances))))
-
-             ;; a list of collectors whereby collector is the sum of
+              (sum-balances-of-accounts
+               accounts-balances asset-liability gnc:monetaries-add))
+
+             ;; a vector of collectors whereby collector is the sum of
              ;; incomes and expenses at report dates
              (income-expense-balances
-              (let ((inc-exp-balances
-                     (map cdr
-                          (filter
-                           (lambda (acc-balances)
-                             (member (car acc-balances) income-expense))
-                           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)))))
-
-             ;; an (cons account list-of-collectors) whereby each
+              (sum-balances-of-accounts
+               accounts-balances income-expense gnc:monetaries-add))
+
+             ;; an alist of (cons account list-of-collectors) whereby each
              ;; collector is the split-value-balances at report
              ;; dates. split-value-balance determined by transaction currency.
              (accounts-value-balances
@@ -988,18 +983,12 @@ also show overall period profit & loss."))
                              (map col-datum-get-split-value-balance cols-data))))
                accounts))
 
-             ;; a list of collectors whereby each collector is the sum
+             ;; a vector of collectors whereby each collector is the sum
              ;; of asset and liability split-value-balances at report
              ;; dates
              (asset-liability-value-balances
-              (let ((asset-liab-value-balances
-                     (map cdr (filter
-                               (lambda (acc-balances)
-                                 (member (car acc-balances) asset-liability))
-                               accounts-value-balances))))
-                (if (null? asset-liab-value-balances)
-                    (map (const (gnc:make-commodity-collector)) report-dates)
-                    (apply map gnc:collector+ asset-liab-value-balances))))
+              (sum-balances-of-accounts
+               accounts-value-balances asset-liability gnc:collector+))
 
              ;; converts monetaries to common currency
              (monetaries->exchanged
@@ -1024,9 +1013,9 @@ also show overall period profit & loss."))
                                    ((pricedb-latest) (current-time))
                                    (else (list-ref report-dates col-idx))))
                            (asset-liability-balance
-                            (list-ref asset-liability-balances col-idx))
+                            (vector-ref asset-liability-balances col-idx))
                            (asset-liability-basis
-                            (list-ref asset-liability-value-balances col-idx))
+                            (vector-ref asset-liability-value-balances col-idx))
                            (unrealized (gnc:collector- asset-liability-basis
                                                        asset-liability-balance)))
                   (monetaries->exchanged
@@ -1041,7 +1030,7 @@ also show overall period profit & loss."))
                                ((pricedb-latest) (current-time))
                                (else (list-ref report-dates col-idx))))
                        (income-expense-balance
-                        (list-ref income-expense-balances col-idx)))
+                        (vector-ref income-expense-balances col-idx)))
                   (if (and common-currency
                            (every has-price?
                                   (gnc:accounts-get-commodities income-expense #f)))

commit def0caa011c32fcb77d40d28527a4d6d174bc22c
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Thu Nov 28 12:29:47 2019 +0800

    [balsheet-pnl] use and-let*, reindent

diff --git a/gnucash/report/standard-reports/balsheet-pnl.scm b/gnucash/report/standard-reports/balsheet-pnl.scm
index f483120f5..566c659e4 100644
--- a/gnucash/report/standard-reports/balsheet-pnl.scm
+++ b/gnucash/report/standard-reports/balsheet-pnl.scm
@@ -1019,18 +1019,18 @@ also show overall period profit & loss."))
              ;; converted to report currency.
              (unrealized-gain-fn
               (lambda (col-idx)
-                (and common-currency
-                     (let* ((date (case price-source
-                                    ((pricedb-latest) (current-time))
-                                    (else (list-ref report-dates col-idx))))
-                            (asset-liability-balance
-                             (list-ref asset-liability-balances col-idx))
-                            (asset-liability-basis
-                             (list-ref asset-liability-value-balances col-idx))
-                            (unrealized (gnc:collector- asset-liability-basis
-                                                        asset-liability-balance)))
-                       (monetaries->exchanged
-                        unrealized common-currency price-source date)))))
+                (and-let* (common-currency
+                           (date (case price-source
+                                   ((pricedb-latest) (current-time))
+                                   (else (list-ref report-dates col-idx))))
+                           (asset-liability-balance
+                            (list-ref asset-liability-balances col-idx))
+                           (asset-liability-basis
+                            (list-ref asset-liability-value-balances col-idx))
+                           (unrealized (gnc:collector- asset-liability-basis
+                                                       asset-liability-balance)))
+                  (monetaries->exchanged
+                   unrealized common-currency price-source date))))
 
              ;; the retained earnings calculator retrieves the
              ;; income-and-expense report-date balance, and converts
@@ -1052,26 +1052,30 @@ also show overall period profit & loss."))
                        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
-                          (list (list "General" "Start Date" (cons 'absolute startdate))
-                                (list "General" "End Date" (cons 'absolute enddate))
-                                (list "General" "Report's currency"
-                                      (or common-currency book-main-currency))
-                                (list "General" "Step Size" incr)
-                                (list "General" "Price Source"
-                                      (or price-source 'pricedb-nearest))
-                                (list "Accounts" "Accounts" asset-liability)))))
-             (get-col-header-fn (lambda (accounts col-idx)
-                                  (let* ((date (list-ref report-dates col-idx))
-                                         (header (qof-print-date date))
-                                         (cell (gnc:make-html-table-cell/markup
-                                                "total-label-cell" header)))
-                                    (gnc:html-table-cell-set-style!
-                                     cell "total-label-cell"
-                                     'attribute '("style" "text-align:right"))
-                                    cell)))
+             (chart (and-let* (include-chart?
+                               incr
+                               (curr (or common-currency book-main-currency))
+                               (price (or price-source 'pricedb-nearest)))
+                      (gnc:make-report-anchor
+                       networth-barchart-uuid report-obj
+                       (list (list "General" "Start Date" (cons 'absolute startdate))
+                             (list "General" "End Date" (cons 'absolute enddate))
+                             (list "General" "Report's currency" curr)
+                             (list "General" "Step Size" incr)
+                             (list "General" "Price Source" price)
+                             (list "Accounts" "Accounts" asset-liability)))))
+
+             (get-col-header-fn
+              (lambda (accounts col-idx)
+                (let* ((date (list-ref report-dates col-idx))
+                       (header (qof-print-date date))
+                       (cell (gnc:make-html-table-cell/markup
+                              "total-label-cell" header)))
+                  (gnc:html-table-cell-set-style!
+                   cell "total-label-cell"
+                   'attribute '("style" "text-align:right"))
+                  cell)))
+
              (add-to-table (lambda* (table title accounts #:key
                                            (get-col-header-fn #f)
                                            (show-accounts? #t)
@@ -1170,6 +1174,7 @@ also show overall period profit & loss."))
                                           (cons (car balancelist) (last balancelist))
                                           (cons (list-ref balancelist idx)
                                                 (list-ref balancelist (1+ idx))))))
+
              (closing-entries (let ((query (qof-query-create-for-splits)))
                                 (qof-query-set-book query (gnc-get-current-book))
                                 (xaccQueryAddAccountMatch
@@ -1183,6 +1188,7 @@ also show overall period profit & loss."))
                                 (let ((splits (qof-query-run query)))
                                   (qof-query-destroy query)
                                   splits)))
+
              ;; this function will query the above closing-entries for
              ;; splits within the date range, and produce the total
              ;; amount for these closing entries
@@ -1198,52 +1204,49 @@ also show overall period profit & loss."))
                   (gnc:make-gnc-monetary
                    (xaccAccountGetCommodity account)
                    (apply + (map xaccSplitGetAmount account-closing-splits))))))
+
              (get-cell-monetary-fn
               (lambda (account col-idx)
-                (let ((account-balance-list (assoc account accounts-balances)))
-                  (and account-balance-list
-                       (let ((monetarypair (col-idx->monetarypair
-                                            (cdr account-balance-list)
-                                            col-idx)))
-                         (monetary-less
-                          (cdr monetarypair)
-                          (car monetarypair)
-                          (closing-adjustment account col-idx)))))))
-
-             (get-cell-anchor-fn (lambda (account col-idx)
-                                   (define datepair (col-idx->datepair col-idx))
-                                   (gnc:make-report-anchor
-                                    trep-uuid report-obj
-                                    (list
-                                     (list "General" "Start Date"
-                                           (cons 'absolute (car datepair)))
-                                     (list "General" "End Date"
-                                           (cons 'absolute (cdr datepair)))
-                                     (list "General" "Show original currency amount"
-                                           (and common-currency #t))
-                                     (list "General" "Common Currency"
-                                           common-currency)
-                                     (list "General" "Report's currency"
-                                           (or common-currency book-main-currency))
-                                     (list "Display" "Amount" 'double)
-                                     (list "Accounts" "Accounts"
-                                           (if (pair? account)
-                                               account
-                                               (list account)))))))
-
-             (chart (and include-chart?
-                         (gnc:make-report-anchor
-                          pnl-barchart-uuid report-obj
-                          (list (list "General" "Start Date"
-                                      (cons 'absolute startdate))
-                                (list "General" "End Date"
-                                      (cons 'absolute enddate))
-                                (list "General" "Report's currency"
-                                      (or common-currency book-main-currency))
-                                (list "General" "Step Size" (or incr 'MonthDelta))
-                                (list "General" "Price Source"
-                                      (or price-source 'pricedb-nearest))
-                                (list "Accounts" "Accounts" income-expense)))))
+                (let* ((balances (assoc-ref accounts-balances account))
+                       (monetarypair (col-idx->monetarypair balances col-idx)))
+                  (monetary-less
+                   (cdr monetarypair)
+                   (car monetarypair)
+                   (closing-adjustment account col-idx)))))
+
+             (get-cell-anchor-fn
+              (lambda (account col-idx)
+                (let ((datepair (col-idx->datepair col-idx))
+                      (show-orig? (and common-currency #t))
+                      (curr (or common-currency book-main-currency))
+                      (delta (or incr 'MonthDelta))
+                      (price (or price-source 'pricedb-nearest))
+                      (accts (if (pair? account) account (list account))))
+                  (gnc:make-report-anchor
+                   trep-uuid report-obj
+                   (list
+                    (list "General" "Start Date" (cons 'absolute (car datepair)))
+                    (list "General" "End Date" (cons 'absolute (cdr datepair)))
+                    (list "General" "Show original currency amount" show-orig?)
+                    (list "General" "Common Currency" common-currency)
+                    (list "General" "Report's currency" curr)
+                    (list "Display" "Amount" 'double)
+                    (list "Accounts" "Accounts" accts))))))
+
+             (chart
+              (and-let* (include-chart?
+                         (curr (or common-currency book-main-currency))
+                         (delta (or incr 'MonthDelta))
+                         (price (or price-source 'pricedb-nearest)))
+                (gnc:make-report-anchor
+                 pnl-barchart-uuid report-obj
+                 (list (list "General" "Start Date" (cons 'absolute startdate))
+                       (list "General" "End Date" (cons 'absolute enddate))
+                       (list "General" "Report's currency" curr)
+                       (list "General" "Step Size" delta)
+                       (list "General" "Price Source" price)
+                       (list "Accounts" "Accounts" income-expense)))))
+
              (get-col-header-fn
               (lambda (accounts col-idx)
                 (let* ((datepair (col-idx->datepair col-idx))
@@ -1258,6 +1261,7 @@ also show overall period profit & loss."))
                    cell "total-label-cell"
                    'attribute '("style" "text-align:right"))
                   cell)))
+
              (add-to-table (lambda* (table title accounts #:key
                                            (get-col-header-fn #f)
                                            (show-accounts? #t)

commit e97b78df80251ef21eb268575ae80e08a0fd151e
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Thu Nov 28 22:41:47 2019 +0800

    [balsheet-pnl] fix: single-date balsheet missed printing date

diff --git a/gnucash/report/standard-reports/balsheet-pnl.scm b/gnucash/report/standard-reports/balsheet-pnl.scm
index 36804aabb..f483120f5 100644
--- a/gnucash/report/standard-reports/balsheet-pnl.scm
+++ b/gnucash/report/standard-reports/balsheet-pnl.scm
@@ -917,7 +917,7 @@ also show overall period profit & loss."))
              (if (or incr (eq? report-type 'pnl))
                  (format #t (_ "~a to ~a")
                          (qof-print-date startdate) (qof-print-date enddate))
-                 (qof-print-date enddate)))))
+                 (display (qof-print-date enddate))))))
 
     (if (eq? (get-option gnc:pagename-general optname-options-summary) 'always)
         (gnc:html-document-add-object!

commit 54c4575f27a6b6033aac147ee542b2fc6943cc3a
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Thu Nov 28 12:17:34 2019 +0800

    [balsheet-pnl] fix: hide Equity sections when not needed
    
    * If currencies are not converted, Unrealized Gains are
    meaningless. Hide them.
    
    * If there are no income/expense accounts, retained earnings will be
    nil. Remove row.

diff --git a/gnucash/report/standard-reports/balsheet-pnl.scm b/gnucash/report/standard-reports/balsheet-pnl.scm
index d8a48d471..36804aabb 100644
--- a/gnucash/report/standard-reports/balsheet-pnl.scm
+++ b/gnucash/report/standard-reports/balsheet-pnl.scm
@@ -1125,11 +1125,14 @@ also show overall period profit & loss."))
         (add-to-table
          multicol-table-right (_ "Equity")
          (append equity-accounts
-                 (list
-                  (vector (_ "Unrealized Gains")
-                          unrealized-gain-fn)
-                  (vector (_ "Retained Earnings")
-                          retained-earnings-fn)))
+                 (if common-currency
+                     (list (vector (_ "Unrealized Gains")
+                                   unrealized-gain-fn))
+                     '())
+                 (if (null? income-expense)
+                     '()
+                     (list (vector (_ "Retained Earnings")
+                                   retained-earnings-fn))))
          #:negate-amounts? #t)
 
         (if (and common-currency show-rates?)
diff --git a/gnucash/report/standard-reports/test/test-balsheet-pnl.scm b/gnucash/report/standard-reports/test/test-balsheet-pnl.scm
index 9fa490a88..98e272c35 100644
--- a/gnucash/report/standard-reports/test/test-balsheet-pnl.scm
+++ b/gnucash/report/standard-reports/test/test-balsheet-pnl.scm
@@ -497,7 +497,7 @@
         "Root.Asset.House" "Total For Asset" "Liability" "Root.Liability"
         "Root.Liability.Bank2" "Root.Liability.Bank2.CreditCard"
         "Root.Liability.Bank2.Loan" "Total For Liability" "Equity" "Root.Equity"
-        "Unrealized Gains" "Retained Earnings" "Total For Equity")
+        "Retained Earnings" "Total For Equity")
       (sxml->table-row-col sxml 1 #f 1))
     (test-equal "default balances"
       '("#200.00" "$106,709.00" "30 FUNDS" "#200.00" "$106,709.00" "30 FUNDS"

commit 34c14b44a9f98035206465ab3543d43bc06ddd3d
Author: Andrey Legayev <andrey at ven.com>
Date:   Fri Nov 29 18:32:50 2019 +0200

    Remove not needed semicolons in Python bindings

diff --git a/bindings/python/example_scripts/rest-api/gnucash_simple.py b/bindings/python/example_scripts/rest-api/gnucash_simple.py
index 1bc56de02..2aa234f95 100644
--- a/bindings/python/example_scripts/rest-api/gnucash_simple.py
+++ b/bindings/python/example_scripts/rest-api/gnucash_simple.py
@@ -34,14 +34,14 @@ def addressToDict(address):
         return None
     else:
         simple_address = {}
-        simple_address['name'] = address.GetName();
-        simple_address['line_1'] = address.GetAddr1();
-        simple_address['line_2'] = address.GetAddr2();
-        simple_address['line_3'] = address.GetAddr3();
-        simple_address['line_4'] = address.GetAddr4();
-        simple_address['phone'] = address.GetPhone();
-        simple_address['fax'] = address.GetFax();
-        simple_address['email'] = address.GetEmail();
+        simple_address['name'] = address.GetName()
+        simple_address['line_1'] = address.GetAddr1()
+        simple_address['line_2'] = address.GetAddr2()
+        simple_address['line_3'] = address.GetAddr3()
+        simple_address['line_4'] = address.GetAddr4()
+        simple_address['phone'] = address.GetPhone()
+        simple_address['fax'] = address.GetFax()
+        simple_address['email'] = address.GetEmail()
 
         return simple_address
 
diff --git a/bindings/python/gnucash_core.py b/bindings/python/gnucash_core.py
index 9b1416f9d..c7a7901e4 100644
--- a/bindings/python/gnucash_core.py
+++ b/bindings/python/gnucash_core.py
@@ -619,7 +619,7 @@ methods_return_instance(GncLot, gnclot_dict)
 
 # Transaction
 Transaction.add_methods_with_prefix('xaccTrans')
-Transaction.add_method('gncTransGetGUID', 'GetGUID');
+Transaction.add_method('gncTransGetGUID', 'GetGUID')
 
 Transaction.add_method('xaccTransGetDescription', 'GetDescription')
 Transaction.add_method('xaccTransDestroy', 'Destroy')
@@ -648,7 +648,7 @@ Transaction.decorate_functions(
 
 # Split
 Split.add_methods_with_prefix('xaccSplit')
-Split.add_method('gncSplitGetGUID', 'GetGUID');
+Split.add_method('gncSplitGetGUID', 'GetGUID')
 Split.add_method('xaccSplitDestroy', 'Destroy')
 
 split_dict =    {
@@ -677,7 +677,7 @@ Split.parent = property( Split.GetParent, Split.SetParent )
 # Account
 Account.add_methods_with_prefix('xaccAccount')
 Account.add_methods_with_prefix('gnc_account_')
-Account.add_method('gncAccountGetGUID', 'GetGUID');
+Account.add_method('gncAccountGetGUID', 'GetGUID')
 Account.add_method('xaccAccountGetPlaceholder', 'GetPlaceholder')
 
 account_dict =  {



Summary of changes:
 .../example_scripts/rest-api/gnucash_simple.py     |  16 +-
 bindings/python/gnucash_core.py                    |   6 +-
 gnucash/report/standard-reports/balsheet-pnl.scm   | 226 ++++++++++-----------
 .../standard-reports/test/test-balsheet-pnl.scm    |   2 +-
 4 files changed, 123 insertions(+), 127 deletions(-)



More information about the gnucash-changes mailing list