gnucash stable: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Wed May 24 12:46:59 EDT 2023


Updated	 via  https://github.com/Gnucash/gnucash/commit/0da40819 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/66f4b4c2 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/b0292d78 (commit)
	from  https://github.com/Gnucash/gnucash/commit/8a5b3721 (commit)



commit 0da408191b9af976993cc8507224807e28f8ee1f
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Mon May 22 16:13:39 2023 +0800

    [gnc-budget-view.c] simplify totals_col_source, decl before use

diff --git a/gnucash/gnome/gnc-budget-view.c b/gnucash/gnome/gnc-budget-view.c
index 98a833554c..ebfadd2818 100644
--- a/gnucash/gnome/gnc-budget-view.c
+++ b/gnucash/gnome/gnc-budget-view.c
@@ -1307,95 +1307,63 @@ totals_col_source (GtkTreeViewColumn *col, GtkCellRenderer *cell,
                    GtkTreeModel *s_model, GtkTreeIter *s_iter,
                    gpointer user_data)
 {
-    GncBudgetView *budget_view;
-    GncBudgetViewPrivate *priv;
-    gint row_type;
-    GList *top_level_accounts;
-    gint period_num;
-    gnc_numeric value; // used to assist in adding and subtracting
-    gchar amtbuff[100]; //FIXME: overkill, where's the #define?
-    GNCPriceDB *pdb;
-    gnc_commodity *total_currency, *currency;
     gnc_numeric total = gnc_numeric_zero ();
-
-    budget_view = GNC_BUDGET_VIEW(user_data);
-    priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
+    GncBudgetView *budget_view = GNC_BUDGET_VIEW(user_data);
+    GncBudgetViewPrivate *priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
+    gint period_num = GPOINTER_TO_INT(g_object_get_data (G_OBJECT(col), "period_num"));
+    GNCPriceDB *pdb = gnc_pricedb_get_db (gnc_get_current_book ());
+    gnc_commodity *total_currency = gnc_default_currency ();
+    GList *top_level_accounts = gnc_account_get_children (priv->rootAcct);
+    gint row_type;
 
     gtk_tree_model_get (s_model, s_iter, 1, &row_type, -1);
-    period_num = GPOINTER_TO_INT(g_object_get_data (G_OBJECT(col), "period_num"));
-
-    pdb = gnc_pricedb_get_db (gnc_get_current_book ());
-    total_currency = gnc_default_currency ();
-    top_level_accounts = gnc_account_get_children (priv->rootAcct);
-
-    // step through each child account of the root, find the total income, expenses, liabilities, and assets.
 
+    // step through each child account of the root, find the total
+    // income, expenses, liabilities, and assets.
     for (GList *node = top_level_accounts; node; node = g_list_next (node))
     {
         Account *account = node->data;
-        GNCAccountType acctype;
-
-        currency = gnc_account_get_currency_or_parent (account);
-        acctype = xaccAccountTypeGetFundamental (xaccAccountGetType (account));
-
-        switch (row_type)
+        GNCAccountType acctype = xaccAccountTypeGetFundamental (xaccAccountGetType (account));
+
+        if ((row_type == TOTALS_TYPE_INCOME && acctype == ACCT_TYPE_INCOME) ||
+            (row_type == TOTALS_TYPE_EXPENSES && acctype == ACCT_TYPE_EXPENSE) ||
+            (row_type == TOTALS_TYPE_REMAINDER) ||
+            (row_type == TOTALS_TYPE_ASSET_LIAB_EQ &&
+             (acctype == ACCT_TYPE_ASSET || acctype == ACCT_TYPE_LIABILITY ||
+              acctype == ACCT_TYPE_EQUITY)))
         {
-            case TOTALS_TYPE_ASSET_LIAB_EQ:
-                if ((acctype != ACCT_TYPE_ASSET) &&
-                    (acctype != ACCT_TYPE_LIABILITY) &&
-                    (acctype != ACCT_TYPE_EQUITY))
-                    continue;
-                break;
-            case TOTALS_TYPE_EXPENSES:
-                if (acctype != ACCT_TYPE_EXPENSE)
-                    continue;
-                break;
-            case TOTALS_TYPE_INCOME:
-                if (acctype != ACCT_TYPE_INCOME)
-                    continue;
-                break;
-            case TOTALS_TYPE_REMAINDER:
-                break;
-            default:
-                continue;       /* don't count if unexpected total row type is passed in... */
-        }
-        // find the total for this account
+            gnc_numeric value; // used to assist in adding and subtracting
+            // find the total for this account
+            if (period_num < 0)
+                value = bgv_get_total_for_account (account, priv->budget, total_currency);
+            else
+            {
+                gnc_commodity *currency = gnc_account_get_currency_or_parent (account);
+                value = gbv_get_accumulated_budget_amount
+                    (priv->budget, account, period_num);
 
-        if (period_num < 0)
-        {
-            value = bgv_get_total_for_account (account, priv->budget, total_currency);
-        }
-        else
-        {
-            value = gbv_get_accumulated_budget_amount (priv->budget, account, period_num);
+                value = gnc_pricedb_convert_balance_nearest_price_t64
+                    (pdb, value, currency, total_currency,
+                     gnc_budget_get_period_start_date (priv->budget, period_num));
+            }
 
-            value = gnc_pricedb_convert_balance_nearest_price_t64 (
-                        pdb, value, currency, total_currency,
-                        gnc_budget_get_period_start_date (priv->budget, period_num));
+            total = gnc_numeric_add (total, value, GNC_DENOM_AUTO, GNC_HOW_DENOM_LCD);
         }
-
-        total = gnc_numeric_add (total, value, GNC_DENOM_AUTO, GNC_HOW_DENOM_LCD);
     }
 
-    /* because we want income to be positive, expense and transfer to
-       be negative. i.e. income adds to the budget, expense and
-       transfer deducts from budget */
     total = gnc_numeric_neg (total);
 
-    xaccSPrintAmount (amtbuff, total,
-                      gnc_commodity_print_info (total_currency,
-                                                period_num < 0 ? TRUE : FALSE));
-    if (priv->use_red_color && gnc_numeric_negative_p (total))
-    {
-        gchar *color = gnc_get_negative_color ();
-        g_object_set (cell, "foreground", color, NULL);
-        g_free (color);
-    }
-    else
-        g_object_set (cell, "foreground", NULL, NULL);
+    GNCPrintAmountInfo pinfo = gnc_commodity_print_info (total_currency, period_num < 0);
+    gchar *color = (priv->use_red_color && gnc_numeric_negative_p (total)) ?
+        gnc_get_negative_color () : NULL;
 
-    g_object_set (G_OBJECT(cell), "text", amtbuff, "xalign", 1.0, NULL);
+    g_object_set (G_OBJECT(cell),
+                  "text", xaccPrintAmount (total, pinfo),
+                  "xalign", 1.0,
+                  "foreground", color,
+                  NULL);
 
+    g_free (color);
     g_list_free (top_level_accounts);
 }
 

commit 66f4b4c2ae9a3f3f8ac07d0c153eae3fcd606534
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun May 21 23:48:54 2023 +0800

    [gnc-budget-view.c] much simpler negation rule: always negate.
    
    previously negation was dependent on the row type and account
    type. this change will modify the rule to *always* negate the total
    amount prior to rendering.
    
    this is because budget amounts are now natural numbers, i.e. budget
    income usually negative, budget expense usually positive. the total of
    budget amounts in a period (asset+liability+income+expense+equity)
    should be zero.
    
    the compulsory negation will ensure the budget equation is now much
    more intuitive, i.e. an income *adds* to the budget, and an
    expense *deducts* from budget; the "remaining to budget" is thus
    positive if there is unallocated budget.

diff --git a/gnucash/gnome/gnc-budget-view.c b/gnucash/gnome/gnc-budget-view.c
index 7d01ad58d7..98a833554c 100644
--- a/gnucash/gnome/gnc-budget-view.c
+++ b/gnucash/gnome/gnc-budget-view.c
@@ -1219,9 +1219,6 @@ bgv_get_total_for_account (Account *account, GncBudget *budget, gnc_commodity *n
         }
     }
 
-    if (gnc_reverse_balance (account))
-        total = gnc_numeric_neg (total);
-
     return total;
 }
 
@@ -1317,7 +1314,6 @@ totals_col_source (GtkTreeViewColumn *col, GtkCellRenderer *cell,
     gint period_num;
     gnc_numeric value; // used to assist in adding and subtracting
     gchar amtbuff[100]; //FIXME: overkill, where's the #define?
-    gboolean neg;
     GNCPriceDB *pdb;
     gnc_commodity *total_currency, *currency;
     gnc_numeric total = gnc_numeric_zero ();
@@ -1342,8 +1338,6 @@ totals_col_source (GtkTreeViewColumn *col, GtkCellRenderer *cell,
         currency = gnc_account_get_currency_or_parent (account);
         acctype = xaccAccountTypeGetFundamental (xaccAccountGetType (account));
 
-        neg = gnc_reverse_balance (account);
-
         switch (row_type)
         {
             case TOTALS_TYPE_ASSET_LIAB_EQ:
@@ -1351,7 +1345,6 @@ totals_col_source (GtkTreeViewColumn *col, GtkCellRenderer *cell,
                     (acctype != ACCT_TYPE_LIABILITY) &&
                     (acctype != ACCT_TYPE_EQUITY))
                     continue;
-                neg = !neg;
                 break;
             case TOTALS_TYPE_EXPENSES:
                 if (acctype != ACCT_TYPE_EXPENSE)
@@ -1360,10 +1353,8 @@ totals_col_source (GtkTreeViewColumn *col, GtkCellRenderer *cell,
             case TOTALS_TYPE_INCOME:
                 if (acctype != ACCT_TYPE_INCOME)
                     continue;
-                neg = !neg;
                 break;
             case TOTALS_TYPE_REMAINDER:
-                neg = !neg;
                 break;
             default:
                 continue;       /* don't count if unexpected total row type is passed in... */
@@ -1383,12 +1374,14 @@ totals_col_source (GtkTreeViewColumn *col, GtkCellRenderer *cell,
                         gnc_budget_get_period_start_date (priv->budget, period_num));
         }
 
-        if (neg)
-            value = gnc_numeric_neg (value);
-
         total = gnc_numeric_add (total, value, GNC_DENOM_AUTO, GNC_HOW_DENOM_LCD);
     }
 
+    /* because we want income to be positive, expense and transfer to
+       be negative. i.e. income adds to the budget, expense and
+       transfer deducts from budget */
+    total = gnc_numeric_neg (total);
+
     xaccSPrintAmount (amtbuff, total,
                       gnc_commodity_print_info (total_currency,
                                                 period_num < 0 ? TRUE : FALSE));

commit b0292d789321f53bc79cf835ea80bd5c015e8fb4
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun May 21 15:21:05 2023 +0800

    [budget.scm] budget report's *actual* amounts link to a trep
    
    showing the exact transactions comprising the *actual* period total.

diff --git a/gnucash/report/reports/standard/budget.scm b/gnucash/report/reports/standard/budget.scm
index 0bc0e2afca..ff03c435e9 100644
--- a/gnucash/report/reports/standard/budget.scm
+++ b/gnucash/report/reports/standard/budget.scm
@@ -36,6 +36,8 @@
 (use-modules (srfi srfi-1))
 (use-modules (ice-9 match))
 
+(define trep-uuid "2fe3b9833af044abb929a88d5a59620f")
+
 (define reportname (N_ "Budget Report"))
 
 ;; define all option's names so that they are properly defined
@@ -52,6 +54,8 @@
 (define opthelp-show-notes (N_ "Display a column for the budget notes."))
 (define optname-show-actual (N_ "Show Actual"))
 (define opthelp-show-actual (N_ "Display a column for the actual values."))
+(define optname-show-trep (N_ "Link to actual transactions"))
+(define opthelp-show-trep (N_ "Show the actual transactions for the budget period"))
 (define optname-show-difference (N_ "Show Difference"))
 (define opthelp-show-difference (N_ "Display the difference as budget - actual."))
 (define optname-accumulate (N_ "Use accumulated amounts"))
@@ -209,9 +213,15 @@
     (gnc-register-simple-boolean-option options
       gnc:pagename-display optname-show-notes
       "s15" opthelp-show-notes #t)
-    (gnc-register-simple-boolean-option options
+    (gnc-register-complex-boolean-option options
       gnc:pagename-display optname-show-actual
-      "s2" opthelp-show-actual #t)
+      "s2" opthelp-show-actual #t
+      (lambda (x)
+        (gnc-optiondb-set-option-selectable-by-name
+         options gnc:pagename-display optname-show-trep x)))
+    (gnc-register-simple-boolean-option options
+      gnc:pagename-display optname-show-trep
+      "s25" opthelp-show-trep #f)
     (gnc-register-simple-boolean-option options
       gnc:pagename-display optname-show-difference
       "s3" opthelp-show-difference #f)
@@ -256,11 +266,12 @@
 ;;   budget - budget to use
 ;;   params - report parameters
 (define (gnc:html-table-add-budget-values!
-         html-table acct-table budget params)
+         html-table acct-table budget params report-obj)
   (let* ((get-val (lambda (alist key)
                     (let ((lst (assoc-ref alist key)))
                       (and lst (car lst)))))
          (show-actual? (get-val params 'show-actual))
+         (show-trep? (get-val params 'show-trep))
          (show-budget? (get-val params 'show-budget))
          (show-diff? (get-val params 'show-difference))
          (show-note? (get-val params 'show-note))
@@ -346,7 +357,7 @@
         ;;
         ;; Returns
         ;;   col - next column
-        (define (disp-cols style-tag col0
+        (define (disp-cols style-tag col0 acct start-date end-date
                            bgt-val act-val dif-val note)
           (let* ((col1 (+ col0 (if show-budget? 1 0)))
                  (col2 (+ col1 (if show-actual? 1 0)))
@@ -361,7 +372,19 @@
                 (gnc:html-table-set-cell/tag!
                  html-table rownum col1
                  style-tag
-                 (gnc:make-gnc-monetary comm act-val)))
+                 (if show-trep?
+                     (gnc:make-html-text
+                      (gnc:html-markup-anchor
+                       (gnc:make-report-anchor
+                        trep-uuid report-obj
+                        (list
+                         (list "General" "Start Date" (cons 'absolute start-date))
+                         (list "General" "End Date" (cons 'absolute end-date))
+                         (list "Accounts" "Accounts" (gnc-accounts-and-all-descendants (list acct)))
+                         (list "Currency" "Common Currency" #t)
+                         (list "Currency" "Report's currency" (gnc-account-get-currency-or-parent acct))))
+                       (gnc:make-gnc-monetary comm act-val)))
+                     (gnc:make-gnc-monetary comm act-val))))
             (if show-diff?
                 (gnc:html-table-set-cell/tag!
                  html-table rownum col2
@@ -386,7 +409,9 @@
                                 budget acct total-periods)))
                    (dif-total (- bgt-total act-total)))
               (loop (cdr column-list)
-                    (disp-cols "total-number-cell" current-col
+                    (disp-cols "total-number-cell" current-col acct
+                               (gnc-budget-get-period-start-date budget (car total-periods))
+                               (gnc-budget-get-period-end-date budget (last total-periods))
                                bgt-total act-total dif-total #f))))
 
            (else
@@ -405,7 +430,9 @@
                               budget acct period-list)))
                    (dif-val (- bgt-val act-val)))
               (loop (cdr column-list)
-                    (disp-cols "number-cell" current-col
+                    (disp-cols "number-cell" current-col acct
+                               (gnc-budget-get-period-start-date budget (car period-list))
+                               (gnc-budget-get-period-end-date budget (car period-list))
                                bgt-val act-val dif-val note))))))))
 
     ;; Adds header rows to the budget report.  The columns are
@@ -668,6 +695,8 @@
               (list
                (list 'show-actual
                      (get-option gnc:pagename-display optname-show-actual))
+               (list 'show-trep
+                     (get-option gnc:pagename-display optname-show-trep))
                (list 'show-budget
                      (get-option gnc:pagename-display optname-show-budget))
                (list 'show-difference
@@ -712,7 +741,8 @@
         (let ((html-table (gnc:html-table-add-account-balances #f acct-table '())))
 
           ;; ... then the budget values
-          (gnc:html-table-add-budget-values! html-table acct-table budget paramsBudget)
+          (gnc:html-table-add-budget-values! html-table acct-table budget
+                                             paramsBudget report-obj)
 
           ;; hmmm... I expected that add-budget-values would have to
           ;; clear out any unused columns to the right, out to the



Summary of changes:
 gnucash/gnome/gnc-budget-view.c            | 123 ++++++++++-------------------
 gnucash/report/reports/standard/budget.scm |  46 +++++++++--
 2 files changed, 80 insertions(+), 89 deletions(-)



More information about the gnucash-changes mailing list