gnucash maint: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Fri Jul 12 23:08:13 EDT 2019


Updated	 via  https://github.com/Gnucash/gnucash/commit/105f5396 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/89749a1b (commit)
	 via  https://github.com/Gnucash/gnucash/commit/ec28835d (commit)
	 via  https://github.com/Gnucash/gnucash/commit/c05ba641 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/43c8b16b (commit)
	 via  https://github.com/Gnucash/gnucash/commit/1ad4ae30 (commit)
	from  https://github.com/Gnucash/gnucash/commit/6c4ae890 (commit)



commit 105f5396fc27cc0cd6f69511523bf03cda2cf935
Merge: 1ad4ae30b 89749a1b6
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Jul 13 10:50:16 2019 +0800

    Merge branch 'maint-budget-ytd-upgrade' into maint


commit 89749a1b63dfe5987e88871fd5e7c62c9c953977
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Jul 13 10:11:42 2019 +0800

    [test-budget] add tests for envelope budgeting

diff --git a/gnucash/report/standard-reports/test/test-budget.scm b/gnucash/report/standard-reports/test/test-budget.scm
index f1fb8ce23..6a6870af3 100644
--- a/gnucash/report/standard-reports/test/test-budget.scm
+++ b/gnucash/report/standard-reports/test/test-budget.scm
@@ -165,4 +165,11 @@
         '("Bank" "$40.00" "-$20.00" "$60.00" "." "$67.00" "-$67.00"
           "$60.00" "$77.00" "-$17.00" "$100.00" "$124.00" "-$24.00")
         (sxml->table-row-col sxml 1 5 #f)))
+
+    (set-option options "General" "Use envelope budgeting" #t)
+    (let ((sxml (options->sxml options "envelope budgeting")))
+      (test-equal "envelope budgeting"
+        '("Bank" "$60.00" "$15.00" "$45.00" "$60.00" "$82.00" "-$22.00"
+          "$120.00" "$159.00" "-$39.00" "$120.00" "$159.00" "-$39.00")
+        (sxml->table-row-col sxml 1 5 #f)))
     ))

commit ec28835d78d7f8915aea830d5f299c0101cea04a
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Wed Jul 3 21:51:25 2019 +0800

    [budget] upgrade to support envelope budgeting
    
    merges ideas from Phil Longstaff's ytd-budget.scm report. differences
    from non-envelope budget:
    
    * envelope budgeting accumulates bgt/act/diff amounts from period=0
      e.g. selecting periods 2 to 4 means amounts must accumulate from
      period 0 to 1 (not shown) and accumulated amounts 2 to 4 (shown).
    * total column must encompass all periods from 0 to maxperiod

diff --git a/gnucash/report/standard-reports/budget.scm b/gnucash/report/standard-reports/budget.scm
index 3d30603fd..0c74ec7dc 100644
--- a/gnucash/report/standard-reports/budget.scm
+++ b/gnucash/report/standard-reports/budget.scm
@@ -55,6 +55,8 @@
 (define opthelp-show-actual (N_ "Display a column for the actual values."))
 (define optname-show-difference (N_ "Show Difference"))
 (define opthelp-show-difference (N_ "Display the difference as budget - actual."))
+(define optname-use-envelope (N_ "Use envelope budgeting"))
+(define opthelp-use-envelope (N_ "Values are accumulated across periods."))
 (define optname-show-totalcol (N_ "Show Column with Totals"))
 (define opthelp-show-totalcol (N_ "Display a column with the row totals."))
 (define optname-show-zb-accounts (N_ "Include accounts with zero total balances and budget values"))
@@ -135,6 +137,11 @@
       gnc:pagename-general optname-budget
       "a" (N_ "Budget to use.")))
 
+    (add-option
+     (gnc:make-simple-boolean-option
+      gnc:pagename-general optname-use-envelope
+      "b" opthelp-use-envelope #f))
+
     (add-option
      (gnc:make-complex-boolean-option
       gnc:pagename-general optname-use-budget-period-range
@@ -262,6 +269,7 @@
          (show-actual? (get-val params 'show-actual))
          (show-budget? (get-val params 'show-budget))
          (show-diff? (get-val params 'show-difference))
+         (use-envelope? (get-val params 'use-envelope))
          (show-totalcol? (get-val params 'show-totalcol))
          (use-ranges? (get-val params 'use-ranges))
          (num-rows (gnc:html-acct-table-num-rows acct-table))
@@ -309,6 +317,17 @@
                   (gnc-budget-get-account-period-actual-value budget acct period))
                 periodlist)))
 
+    (define (flatten lst)
+      (reverse!
+       (let loop ((lst lst) (result '()))
+         (if (null? lst)
+             result
+             (let ((elt (car lst))
+                   (rest (cdr lst)))
+               (if (pair? elt)
+                   (loop rest (append (loop elt '()) result))
+                   (loop rest (cons elt result))))))))
+
     ;; Adds a line to tbe budget report.
     ;;
     ;; Parameters:
@@ -323,6 +342,10 @@
              column-list exchange-fn)
       (let* ((comm (xaccAccountGetCommodity acct))
              (reverse-balance? (gnc-reverse-balance acct))
+             (allperiods (filter number? (flatten column-list)))
+             (total-periods (if use-envelope?
+                                (iota (1+ (apply max allperiods)))
+                                allperiods))
              (income-acct? (eqv? (xaccAccountGetType acct) ACCT-TYPE-INCOME)))
 
         ;; Displays a set of budget column values
@@ -362,8 +385,6 @@
             col3))
 
         (let loop ((column-list column-list)
-                   (bgt-total 0)
-                   (act-total 0)
                    (current-col (1+ colnum)))
           (cond
 
@@ -371,19 +392,22 @@
             #f)
 
            ((eq? (car column-list) 'total)
-            (loop (cdr column-list)
-                  bgt-total
-                  act-total
-                  (disp-cols "total-number-cell" current-col
-                             bgt-total act-total
-                             (if income-acct?
-                                 (- act-total bgt-total)
-                                 (- bgt-total act-total)))))
+            (let* ((bgt-total (gnc:get-account-periodlist-budget-value
+                               budget acct total-periods))
+                   (act-total (gnc:get-account-periodlist-actual-value
+                               budget acct total-periods))
+                   (dif-total (if income-acct?
+                                  (- act-total bgt-total)
+                                  (- bgt-total act-total))))
+              (loop (cdr column-list)
+                    (disp-cols "total-number-cell" current-col
+                               bgt-total act-total dif-total))))
 
            (else
-            (let* ((period-list (if (list? (car column-list))
-                                    (car column-list)
-                                    (list (car column-list))))
+            (let* ((period-list (cond
+                                 ((list? (car column-list)) (car column-list))
+                                 (use-envelope? (iota (1+ (car column-list))))
+                                 (else (list (car column-list)))))
                    (bgt-val (gnc:get-account-periodlist-budget-value
                              budget acct period-list))
                    (act-abs (gnc:get-account-periodlist-actual-value
@@ -395,8 +419,6 @@
                                 (- act-val bgt-val)
                                 (- bgt-val act-val))))
               (loop (cdr column-list)
-                    (+ bgt-total bgt-val)
-                    (+ act-total act-val)
                     (disp-cols "number-cell" current-col
                                bgt-val act-val dif-val))))))))
 
@@ -653,6 +675,7 @@
                          (if show-zb-accts? 'show-leaf-acct 'omit-leaf-acct))
                    (list 'report-budget budget)))
              (accounts (sort accounts account-full-name<?))
+             (use-envelope? (get-option gnc:pagename-general optname-use-envelope))
              (acct-table (gnc:make-html-acct-table/env/accts env accounts))
              (paramsBudget
               (list
@@ -662,6 +685,7 @@
                      (get-option gnc:pagename-display optname-show-budget))
                (list 'show-difference
                      (get-option gnc:pagename-display optname-show-difference))
+               (list 'use-envelope use-envelope?)
                (list 'show-totalcol
                      (get-option gnc:pagename-display optname-show-totalcol))
                (list 'use-ranges use-ranges?)
@@ -681,8 +705,10 @@
                                       gnc:optname-reportname)))
 
         (gnc:html-document-set-title!
-         doc (format #f (_ "~a: ~a")
-                     report-name (gnc-budget-get-name budget)))
+         doc (format #f "~a: ~a ~a"
+                     report-name (gnc-budget-get-name budget)
+                     (if use-envelope? (_ "using envelope budgeting")
+                         "")))
 
         ;; We do this in two steps: First the account names...  the
         ;; add-account-balances will actually compute and add a

commit c05ba6415f55cb7114ed523e55494aa4c212a4da
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Jul 13 10:27:05 2019 +0800

    [budget] compact functions in options-generator

diff --git a/gnucash/report/standard-reports/budget.scm b/gnucash/report/standard-reports/budget.scm
index 3f3cd12e8..3d30603fd 100644
--- a/gnucash/report/standard-reports/budget.scm
+++ b/gnucash/report/standard-reports/budget.scm
@@ -137,38 +137,29 @@
 
     (add-option
      (gnc:make-complex-boolean-option
-      gnc:pagename-general
-      optname-use-budget-period-range
-      "f"
-      opthelp-use-budget-period-range
-      #f
-      #f
-      ;; Make period only option widgets
-      ;; selectable only when we are running the report for a budget period
-      ;; range.
+      gnc:pagename-general optname-use-budget-period-range
+      "f" opthelp-use-budget-period-range #f #f
       (lambda (value)
-        (let ((enabler (lambda (target-opt enabled)
-                         (set-option-enabled
-                          options gnc:pagename-general target-opt enabled))))
-          (for-each
-           (lambda (target-opt)
-             (enabler target-opt value))
-           (list optname-budget-period-start optname-budget-period-end
-                 optname-period-collapse-before optname-period-collapse-after))
-          (enabler optname-budget-period-start-exact
-                   (and value
-                        (eq? 'manual ui-start-period-type)))
-          (enabler optname-budget-period-end-exact
-                   (and value
-                        (eq? 'manual ui-end-period-type)))
-          (set! ui-use-periods value)))))
+        (for-each
+         (lambda (opt)
+           (set-option-enabled options gnc:pagename-general opt value))
+         (list optname-budget-period-start optname-budget-period-end
+               optname-period-collapse-before optname-period-collapse-after))
+
+        (set-option-enabled options gnc:pagename-general
+                            optname-budget-period-start-exact
+                            (and value (eq? 'manual ui-start-period-type)))
+
+        (set-option-enabled options gnc:pagename-general
+                            optname-budget-period-end-exact
+                            (and value (eq? 'manual ui-end-period-type)))
+
+        (set! ui-use-periods value))))
 
     (add-option
      (gnc:make-multichoice-callback-option
       gnc:pagename-general optname-budget-period-start
-      "g1.1" opthelp-budget-period-start 'current
-      period-options
-      #f
+      "g1.1" opthelp-budget-period-start 'current period-options #f
       (lambda (new-val)
         (set-option-enabled options gnc:pagename-general
                             optname-budget-period-start-exact
@@ -187,9 +178,7 @@
     (add-option
      (gnc:make-multichoice-callback-option
       gnc:pagename-general optname-budget-period-end
-      "g2.1" opthelp-budget-period-end 'next
-      period-options
-      #f
+      "g2.1" opthelp-budget-period-end 'next period-options #f
       (lambda (new-val)
         (set-option-enabled options gnc:pagename-general
                             optname-budget-period-end-exact
@@ -217,15 +206,15 @@
       "g4" opthelp-period-collapse-after #t))
 
     (gnc:options-add-account-selection!
-     options gnc:pagename-accounts
-     optname-display-depth optname-show-subaccounts
-     optname-accounts "a" 2
+     options gnc:pagename-accounts optname-display-depth
+     optname-show-subaccounts optname-accounts "a" 2
      (lambda ()
        (gnc:filter-accountlist-type
         (list ACCT-TYPE-ASSET ACCT-TYPE-LIABILITY ACCT-TYPE-INCOME
               ACCT-TYPE-EXPENSE)
         (gnc-account-get-descendants-sorted (gnc-get-current-root-account))))
      #f)
+
     (add-option
      (gnc:make-simple-boolean-option
       gnc:pagename-accounts optname-bottom-behavior

commit 43c8b16ba53d24dc24bf76b1726f0a3daba0c747
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Jul 13 10:18:44 2019 +0800

    [budget] remove unused options
    
    these options are unused
    
    * general/price-source
    * general/show-full-names?

diff --git a/gnucash/report/standard-reports/budget.scm b/gnucash/report/standard-reports/budget.scm
index bcbaa9979..3f3cd12e8 100644
--- a/gnucash/report/standard-reports/budget.scm
+++ b/gnucash/report/standard-reports/budget.scm
@@ -48,9 +48,6 @@
 (define optname-show-subaccounts (N_ "Always show sub-accounts"))
 (define optname-accounts (N_ "Account"))
 
-(define optname-price-source (N_ "Price Source"))
-(define optname-show-rates (N_ "Show Exchange Rates"))
-(define optname-show-full-names (N_ "Show Full Account Names"))
 (define optname-select-columns (N_ "Select Columns"))
 (define optname-show-budget (N_ "Show Budget"))
 (define opthelp-show-budget (N_ "Display a column for the budget values."))
@@ -138,15 +135,6 @@
       gnc:pagename-general optname-budget
       "a" (N_ "Budget to use.")))
 
-    (gnc:options-add-price-source!
-     options gnc:pagename-general optname-price-source "c" 'pricedb-nearest)
-
-    (gnc:register-option
-     options
-     (gnc:make-simple-boolean-option
-      gnc:pagename-general optname-show-full-names
-      "e" (N_ "Show full account names (including parent accounts).") #t))
-
     (add-option
      (gnc:make-complex-boolean-option
       gnc:pagename-general
@@ -638,8 +626,6 @@
          (include-collapse-after? (and use-ranges?
                                        (get-option gnc:pagename-general
                                                    optname-period-collapse-after)))
-         (show-full-names? (get-option gnc:pagename-general
-                                       optname-show-full-names))
          (doc (gnc:make-html-document))
          (accounts (append accounts
                            (filter (lambda (acc) (not (member acc accounts)))

commit 1ad4ae30be3aea7122a410a3d8371695cfb3b85a
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Fri Jul 12 21:54:24 2019 +0800

    [owner-report] fix html to be parsable by sxml
    
    in preparation for tests

diff --git a/gnucash/report/business-reports/owner-report.scm b/gnucash/report/business-reports/owner-report.scm
index b6a0a48ce..47dd06985 100644
--- a/gnucash/report/business-reports/owner-report.scm
+++ b/gnucash/report/business-reports/owner-report.scm
@@ -691,8 +691,8 @@
   (gnc:html-table-append-row!
    table
    (list
-    (string-append label ": ")
-    (string-expand (qof-print-date date) #\space " "))))
+    (string-append label ": ")
+    (qof-print-date date))))
 
 (define (make-date-table)
   (let ((table (gnc:make-html-table)))
@@ -777,7 +777,7 @@
 
         (gnc:html-document-set-headline!
          document (gnc:html-markup
-                   "!" 
+                   "span"
                    (doctype-str type)
                    " " (_ "Report:") " "
                    (gnc:html-markup-anchor



Summary of changes:
 gnucash/report/business-reports/owner-report.scm   |   6 +-
 gnucash/report/standard-reports/budget.scm         | 125 +++++++++++----------
 .../report/standard-reports/test/test-budget.scm   |   7 ++
 3 files changed, 73 insertions(+), 65 deletions(-)



More information about the gnucash-changes mailing list