gnucash maint: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Thu Dec 5 04:28:47 EST 2019


Updated	 via  https://github.com/Gnucash/gnucash/commit/b5f9cd0b (commit)
	 via  https://github.com/Gnucash/gnucash/commit/775200ef (commit)
	 via  https://github.com/Gnucash/gnucash/commit/2cd69e8d (commit)
	 via  https://github.com/Gnucash/gnucash/commit/ded336f9 (commit)
	from  https://github.com/Gnucash/gnucash/commit/c06191a6 (commit)



commit b5f9cd0b32398fe5668e4f140cc91a7324436e01
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Oct 19 16:21:43 2019 +0800

    [budgets.scm] budget reports handle both natural & reversed budgets

diff --git a/gnucash/report/standard-reports/budget-balance-sheet.scm b/gnucash/report/standard-reports/budget-balance-sheet.scm
index 0b24b26e1..38c89ee9d 100644
--- a/gnucash/report/standard-reports/budget-balance-sheet.scm
+++ b/gnucash/report/standard-reports/budget-balance-sheet.scm
@@ -256,7 +256,8 @@
       (gnc:report-options report-obj) pagename optname)))
 
   (define (get-budget-account-budget-balance budget account)
-    (gnc:budget-account-get-net budget account #f #f))
+    (let ((bal (gnc:budget-account-get-net budget account #f #f)))
+      (if (gnc-reverse-budget-balance account #t) (gnc:collector- bal) bal)))
 
   (define (get-budget-account-initial-balance budget account)
     (gnc:budget-account-get-initial-balance budget account))
diff --git a/gnucash/report/standard-reports/budget-income-statement.scm b/gnucash/report/standard-reports/budget-income-statement.scm
index a2393037c..07618edfc 100644
--- a/gnucash/report/standard-reports/budget-income-statement.scm
+++ b/gnucash/report/standard-reports/budget-income-statement.scm
@@ -308,7 +308,8 @@
                    (get-balance-fn budget account period-start period-end))))
 
   (define (get-budget-account-budget-balance budget account period-start period-end)
-    (gnc:budget-account-get-net budget account period-start period-end))
+    (let ((bal (gnc:budget-account-get-net budget account period-start period-end)))
+      (if (gnc-reverse-budget-balance account #t) (gnc:collector- bal) bal)))
 
   (gnc:report-starting reportname)
   
diff --git a/gnucash/report/standard-reports/budget.scm b/gnucash/report/standard-reports/budget.scm
index 80b98dd6a..8af29a078 100644
--- a/gnucash/report/standard-reports/budget.scm
+++ b/gnucash/report/standard-reports/budget.scm
@@ -331,6 +331,9 @@
              column-list exchange-fn)
       (let* ((comm (xaccAccountGetCommodity acct))
              (reverse-balance? (gnc-reverse-balance acct))
+             (maybe-negate (lambda (amt) (if reverse-balance? (- amt) amt)))
+             (unreversed? (gnc-using-unreversed-budgets
+                           (gnc-get-current-book))) ;fwd-compatibility
              (allperiods (filter number? (gnc:list-flatten column-list)))
              (total-periods (if (and accumulate? (not (null? allperiods)))
                                 (iota (1+ (apply max allperiods)))
@@ -379,6 +382,19 @@
            ((null? column-list)
             #f)
 
+           ;; fwd-compatibility: the next cond may be removed in master
+           ((and (eq? (car column-list) 'total) unreversed?)
+            (let* ((bgt-total (maybe-negate
+                               (gnc:get-account-periodlist-budget-value
+                                budget acct total-periods)))
+                   (act-total (maybe-negate
+                               (gnc:get-account-periodlist-actual-value
+                                budget acct total-periods)))
+                   (dif-total (- bgt-total act-total)))
+              (loop (cdr column-list)
+                    (disp-cols "total-number-cell" current-col
+                               bgt-total act-total dif-total))))
+
            ((eq? (car column-list) 'total)
             (let* ((bgt-total (gnc:get-account-periodlist-budget-value
                                budget acct total-periods))
@@ -392,6 +408,23 @@
                     (disp-cols "total-number-cell" current-col
                                bgt-total act-total dif-total))))
 
+           ;; fwd-compatibility: the next cond may be removed in master
+           (unreversed?
+            (let* ((period-list (cond
+                                 ((list? (car column-list)) (car column-list))
+                                 (accumulate? (iota (1+ (car column-list))))
+                                 (else (list (car column-list)))))
+                   (bgt-val (maybe-negate
+                             (gnc:get-account-periodlist-budget-value
+                              budget acct period-list)))
+                   (act-val (maybe-negate
+                             (gnc:get-account-periodlist-actual-value
+                              budget acct period-list)))
+                   (dif-val (- bgt-val act-val)))
+              (loop (cdr column-list)
+                    (disp-cols "number-cell" current-col
+                               bgt-val act-val dif-val))))
+
            (else
             (let* ((period-list (cond
                                  ((list? (car column-list)) (car column-list))

commit 775200ef348f8579a3e0258988ae25a8026dbd6d
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Tue Oct 22 23:19:28 2019 +0800

    [gnc-budget-view.c] totals - 5 fundamental types
    
    previous showed income/expense/transfers/totals budget totals, of
    uncertain meaning. now shows income/expense/asset/liability/equity
    budget totals.
    
    the 5 lines also become sensitive to global sign-reverses property

diff --git a/gnucash/gnome/gnc-budget-view.c b/gnucash/gnome/gnc-budget-view.c
index f8972910a..02ace74b9 100644
--- a/gnucash/gnome/gnc-budget-view.c
+++ b/gnucash/gnome/gnc-budget-view.c
@@ -94,8 +94,9 @@ enum
 {
     TOTALS_TYPE_INCOME, /**< This total is Income type*/
     TOTALS_TYPE_EXPENSES, /**< This total is Expenses type*/
-    TOTALS_TYPE_TRANSFERS, /**< This total is Transfers type*/
-    TOTALS_TYPE_TOTAL /**< This total is for Totals*/
+    TOTALS_TYPE_ASSET, /**< This total is Assets type*/
+    TOTALS_TYPE_LIABILITY, /**< This total is Liabilities type*/
+    TOTALS_TYPE_EQUITY /**< This total is for Equity type*/
 };
 /**< \brief ENUM for different budget totals types.
 
@@ -420,9 +421,11 @@ gbv_create_widget(GncBudgetView *view)
     gtk_list_store_append(totals_tree_model, &iter);
     gtk_list_store_set(totals_tree_model, &iter, 0, _("Expenses"), 1, TOTALS_TYPE_EXPENSES, -1);
     gtk_list_store_append(totals_tree_model, &iter);
-    gtk_list_store_set(totals_tree_model, &iter, 0, _("Transfers"), 1, TOTALS_TYPE_TRANSFERS, -1);
+    gtk_list_store_set(totals_tree_model, &iter, 0, _("Assets"), 1, TOTALS_TYPE_ASSET, -1);
     gtk_list_store_append(totals_tree_model, &iter);
-    gtk_list_store_set(totals_tree_model, &iter, 0, _("Total"), 1, TOTALS_TYPE_TOTAL, -1);
+    gtk_list_store_set(totals_tree_model, &iter, 0, _("Liabilities"), 1, TOTALS_TYPE_LIABILITY, -1);
+    gtk_list_store_append(totals_tree_model, &iter);
+    gtk_list_store_set(totals_tree_model, &iter, 0, _("Equity"), 1, TOTALS_TYPE_EQUITY, -1);
 
     totals_tree_view = GTK_TREE_VIEW(gtk_tree_view_new());
     priv->totals_tree_view = totals_tree_view;
@@ -1172,24 +1175,23 @@ totals_col_source(GtkTreeViewColumn *col, GtkCellRenderer *cell,
         switch (xaccAccountGetType(account))
         {
         case ACCT_TYPE_INCOME:
-            if (row_type != TOTALS_TYPE_INCOME &&
-                row_type != TOTALS_TYPE_TOTAL)
-                continue;
-            break;
-        case ACCT_TYPE_LIABILITY:
-        case ACCT_TYPE_EQUITY:
-            if (row_type != TOTALS_TYPE_TRANSFERS &&
-                row_type != TOTALS_TYPE_TOTAL)
+            if (row_type != TOTALS_TYPE_INCOME)
                 continue;
             break;
         case ACCT_TYPE_EXPENSE:
-            if ((row_type != TOTALS_TYPE_EXPENSES) &&
-                (row_type != TOTALS_TYPE_TOTAL))
+            if (row_type != TOTALS_TYPE_EXPENSES)
                 continue;
             break;
         case ACCT_TYPE_ASSET:
-            if (row_type != TOTALS_TYPE_TRANSFERS &&
-                row_type != TOTALS_TYPE_TOTAL)
+            if (row_type != TOTALS_TYPE_ASSET)
+                continue;
+            break;
+        case ACCT_TYPE_LIABILITY:
+            if (row_type != TOTALS_TYPE_LIABILITY)
+                continue;
+            break;
+        case ACCT_TYPE_EQUITY:
+            if (row_type != TOTALS_TYPE_EQUITY)
                 continue;
             break;
         default:
@@ -1203,20 +1205,14 @@ totals_col_source(GtkTreeViewColumn *col, GtkCellRenderer *cell,
         }
         else
         {
-            value =
-                gbv_get_accumulated_budget_amount(budget, account, period_num);
+            value = gbv_get_accumulated_budget_amount(budget, account, period_num);
 
             value = gnc_pricedb_convert_balance_nearest_price_t64(
                         pdb, value, currency, total_currency,
                         gnc_budget_get_period_start_date(budget, period_num));
         }
 
-        if (gnc_reverse_budget_balance (account, TRUE))
-            total = gnc_numeric_sub(total, value, GNC_DENOM_AUTO,
-                                    GNC_HOW_DENOM_LCD);
-        else
-            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);
     }
 
     xaccSPrintAmount(amtbuff, total,

commit 2cd69e8d85f8f1538409deeb657a379a0bc36c92
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Oct 19 16:19:11 2019 +0800

    [budgets.c] handle both natural & reversed signs budgets
    
    introduce new API
    * gnc_using_unreversed_budgets - queries book's unreversed feature
    * gnc_reverse_budget_balance - check if book unreversal status matches
      2nd argument. if so, return account's reversal status. else, return
      FALSE.
    
    * gnome-budget-view can now show both natural and reversed budgets
    * gnome-plugin-page-budget will now read&write both natural and
      reversed budgets.

diff --git a/gnucash/gnome/gnc-budget-view.c b/gnucash/gnome/gnc-budget-view.c
index 9846e5e3f..f8972910a 100644
--- a/gnucash/gnome/gnc-budget-view.c
+++ b/gnucash/gnome/gnc-budget-view.c
@@ -901,6 +901,10 @@ gbv_get_accumulated_budget_amount(GncBudget* budget, Account* account, guint per
     {
         info.total = gnc_budget_get_account_period_value(budget, account, period_num);
     }
+
+    if (gnc_reverse_budget_balance (account, TRUE))
+        info.total = gnc_numeric_neg (info.total);
+
     return info.total;
 }
 
@@ -979,6 +983,9 @@ budget_col_source(Account *account, GtkTreeViewColumn *col,
         }
         else
         {
+            if (gnc_reverse_budget_balance (account, TRUE))
+                numeric = gnc_numeric_neg (numeric);
+
             xaccSPrintAmount(amtbuff, numeric,
                              gnc_account_print_info(account, FALSE));
             g_object_set(cell, "foreground",
@@ -1019,6 +1026,9 @@ bgv_get_total_for_account(Account* account, GncBudget* budget, gnc_commodity *ne
             {
                 numeric = gbv_get_accumulated_budget_amount(budget, account, period_num);
 
+                if (gnc_reverse_budget_balance (account, TRUE))
+                    numeric = gnc_numeric_neg (numeric);
+
                 if (new_currency)
                 {
                     numeric = gnc_pricedb_convert_balance_nearest_price_t64(
@@ -1043,6 +1053,10 @@ bgv_get_total_for_account(Account* account, GncBudget* budget, gnc_commodity *ne
             }
         }
     }
+
+    if (gnc_reverse_budget_balance (account, TRUE))
+        total = gnc_numeric_neg(total);
+
     return total;
 }
 
@@ -1093,8 +1107,12 @@ budget_col_edited(Account *account, GtkTreeViewColumn *col,
     if (new_text && *new_text == '\0')
         gnc_budget_unset_account_period_value(budget, account, period_num);
     else
+    {
+        if (gnc_reverse_budget_balance (account, TRUE))
+            numeric = gnc_numeric_neg(numeric);
         gnc_budget_set_account_period_value(budget, account, period_num,
                                             numeric);
+    }
 }
 
 /** \brief Function to find the total in a column of budget provided and
@@ -1124,7 +1142,7 @@ totals_col_source(GtkTreeViewColumn *col, GtkCellRenderer *cell,
     gchar amtbuff[100]; //FIXME: overkill, where's the #define?
     gint i;
     gint num_top_accounts;
-    gboolean neg, red;
+    gboolean red;
     GNCPriceDB *pdb;
     gnc_commodity *total_currency, *currency;
 
@@ -1150,7 +1168,6 @@ totals_col_source(GtkTreeViewColumn *col, GtkCellRenderer *cell,
     {
         account  = gnc_account_nth_child(priv->rootAcct, i);
         currency = gnc_account_get_currency_or_parent(account);
-        neg      = FALSE;
 
         switch (xaccAccountGetType(account))
         {
@@ -1166,16 +1183,14 @@ totals_col_source(GtkTreeViewColumn *col, GtkCellRenderer *cell,
                 continue;
             break;
         case ACCT_TYPE_EXPENSE:
-            if (row_type == TOTALS_TYPE_TOTAL)
-                neg = TRUE;
-            else if (row_type != TOTALS_TYPE_EXPENSES)
+            if ((row_type != TOTALS_TYPE_EXPENSES) &&
+                (row_type != TOTALS_TYPE_TOTAL))
                 continue;
             break;
         case ACCT_TYPE_ASSET:
             if (row_type != TOTALS_TYPE_TRANSFERS &&
                 row_type != TOTALS_TYPE_TOTAL)
                 continue;
-            neg = TRUE;
             break;
         default:
             continue;
@@ -1196,7 +1211,7 @@ totals_col_source(GtkTreeViewColumn *col, GtkCellRenderer *cell,
                         gnc_budget_get_period_start_date(budget, period_num));
         }
 
-        if (neg)
+        if (gnc_reverse_budget_balance (account, TRUE))
             total = gnc_numeric_sub(total, value, GNC_DENOM_AUTO,
                                     GNC_HOW_DENOM_LCD);
         else
diff --git a/gnucash/gnome/gnc-plugin-page-budget.c b/gnucash/gnome/gnc-plugin-page-budget.c
index ca77b4893..d7ae5352d 100644
--- a/gnucash/gnome/gnc-plugin-page-budget.c
+++ b/gnucash/gnome/gnc-plugin-page-budget.c
@@ -902,7 +902,7 @@ estimate_budget_helper(GtkTreeModel *model, GtkTreePath *path,
                               GNC_HOW_DENOM_SIGFIGS(priv->sigFigs) | 
                               GNC_HOW_RND_ROUND_HALF_UP);
 
-        if (gnc_reverse_balance(acct))
+        if (gnc_reverse_budget_balance(acct, FALSE))
             num = gnc_numeric_neg(num);
 
         for (i = 0; i < num_periods; i++)
@@ -920,7 +920,7 @@ estimate_budget_helper(GtkTreeModel *model, GtkTreePath *path,
 
             if (!gnc_numeric_check(num))
             {
-                if (gnc_reverse_balance(acct))
+                if (gnc_reverse_budget_balance(acct, FALSE))
                     num = gnc_numeric_neg(num);
 
                 num = gnc_numeric_convert(num, GNC_DENOM_AUTO,
@@ -1020,7 +1020,7 @@ allperiods_budget_helper(GtkTreeModel *model, GtkTreePath *path,
 {
     Account *acct;
     guint num_periods, i;
-    gnc_numeric num;
+    gnc_numeric num, allvalue;
     GncPluginPageBudgetPrivate *priv;
     GncPluginPageBudget *page = data;
 
@@ -1028,7 +1028,9 @@ allperiods_budget_helper(GtkTreeModel *model, GtkTreePath *path,
     priv = GNC_PLUGIN_PAGE_BUDGET_GET_PRIVATE(page);
     acct = gnc_budget_view_get_account_from_path(priv->budget_view, path);
     num_periods = gnc_budget_get_num_periods(priv->budget);
-    num = priv->allValue;
+    allvalue = priv->allValue;
+    if (gnc_reverse_budget_balance(acct, TRUE))
+        allvalue = gnc_numeric_neg(allvalue);
 
     for (i = 0; i < num_periods; i++)
     {
@@ -1036,7 +1038,7 @@ allperiods_budget_helper(GtkTreeModel *model, GtkTreePath *path,
         {
         case ADD:
             num = gnc_budget_get_account_period_value(priv->budget, acct, i);
-            num = gnc_numeric_add(num, priv->allValue, GNC_DENOM_AUTO,
+            num = gnc_numeric_add(num, allvalue, GNC_DENOM_AUTO,
                                   GNC_HOW_DENOM_SIGFIGS(priv->sigFigs) |
                                   GNC_HOW_RND_ROUND_HALF_UP);
             gnc_budget_set_account_period_value(priv->budget, acct, i, num);
@@ -1053,7 +1055,7 @@ allperiods_budget_helper(GtkTreeModel *model, GtkTreePath *path,
             break;
         default:
             gnc_budget_set_account_period_value(priv->budget, acct, i,
-                                                priv->allValue);
+                                                allvalue);
             break;
         }
     }
diff --git a/libgnucash/app-utils/app-utils.i b/libgnucash/app-utils/app-utils.i
index 7ded4efa8..2da48b375 100644
--- a/libgnucash/app-utils/app-utils.i
+++ b/libgnucash/app-utils/app-utils.i
@@ -116,6 +116,8 @@ const char * xaccPrintAmount (gnc_numeric val, GNCPrintAmountInfo info);
 gchar *number_to_words(gdouble val, gint64 denom);
 const gchar *printable_value (gdouble val, gint denom);
 
+gboolean gnc_using_unreversed_budgets (QofBook* book);
+gboolean gnc_reverse_budget_balance (const Account *account, gboolean unreversed);
 gboolean gnc_reverse_balance (const Account *account);
 
 gboolean gnc_is_euro_currency(const gnc_commodity * currency);
diff --git a/libgnucash/app-utils/gnc-ui-util.c b/libgnucash/app-utils/gnc-ui-util.c
index bae5f388b..3ff97e105 100644
--- a/libgnucash/app-utils/gnc-ui-util.c
+++ b/libgnucash/app-utils/gnc-ui-util.c
@@ -179,6 +179,23 @@ gnc_reverse_balance (const Account *account)
     return reverse_type[type];
 }
 
+gboolean gnc_using_unreversed_budgets (QofBook* book)
+{
+    return gnc_features_check_used (book, GNC_FEATURE_BUDGET_UNREVERSED);
+}
+
+/* similar to gnc_reverse_balance but also accepts a gboolean
+   unreversed which specifies the reversal strategy - FALSE = pre-4.x
+   always-assume-credit-accounts, TRUE = all amounts unreversed */
+gboolean
+gnc_reverse_budget_balance (const Account *account, gboolean unreversed)
+{
+    if (unreversed == gnc_using_unreversed_budgets(gnc_account_get_book(account)))
+        return gnc_reverse_balance (account);
+
+    return FALSE;
+}
+
 
 gchar *
 gnc_get_default_directory (const gchar *section)
diff --git a/libgnucash/app-utils/gnc-ui-util.h b/libgnucash/app-utils/gnc-ui-util.h
index 4601f3b8b..472ee4dbc 100644
--- a/libgnucash/app-utils/gnc-ui-util.h
+++ b/libgnucash/app-utils/gnc-ui-util.h
@@ -46,6 +46,16 @@ typedef QofSession * (*QofSessionCB) (void);
 gchar *gnc_normalize_account_separator (const gchar* separator);
 gboolean gnc_reverse_balance(const Account *account);
 
+/* Backward compatibility *******************************************
+ * Return book's UNREVERSED_BUDGET feature check. */
+gboolean gnc_using_unreversed_budgets (QofBook* book);
+
+/* Backward compatibility *******************************************
+ * Compare book's UNREVERSED_BUDGET with unreverse_check. If they
+ * match, return account reversal according to global pref. If they
+ * don't match, return FALSE. */
+gboolean gnc_reverse_budget_balance (const Account *account, gboolean unreversed);
+
 /* Default directory sections ***************************************/
 #define GNC_PREFS_GROUP_OPEN_SAVE    "dialogs.open-save"
 #define GNC_PREFS_GROUP_EXPORT       "dialogs.export-accounts"

commit ded336f987ccd6b23c14d79a721ca115a4bb95dc
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Oct 19 16:06:20 2019 +0800

    [gnc-features] enable reading of unreversed budgets

diff --git a/libgnucash/engine/gnc-features.c b/libgnucash/engine/gnc-features.c
index 453ecfc6e..98e8d50b2 100644
--- a/libgnucash/engine/gnc-features.c
+++ b/libgnucash/engine/gnc-features.c
@@ -49,6 +49,7 @@ static gncFeature known_features[] =
     { GNC_FEATURE_GUID_FLAT_BAYESIAN, "Use account GUID as key for bayesian data and store KVP flat (requires at least Gnucash 2.6.19)" },
     { GNC_FEATURE_SQLITE3_ISO_DATES, "Use ISO formatted date-time strings in SQLite3 databases (requires at least GnuCash 2.6.20)"},
     { GNC_FEATURE_REG_SORT_FILTER, "Store the register sort and filter settings in .gcm metadata file (requires at least GnuCash 3.3)"},
+    { GNC_FEATURE_BUDGET_UNREVERSED, "Store budget amounts unreversed (i.e. natural) signs (requires at least Gnucash 3.8)"},
     { NULL },
 };
 
diff --git a/libgnucash/engine/gnc-features.h b/libgnucash/engine/gnc-features.h
index a53be433f..bb2efe10b 100644
--- a/libgnucash/engine/gnc-features.h
+++ b/libgnucash/engine/gnc-features.h
@@ -53,6 +53,7 @@ extern "C" {
 #define GNC_FEATURE_GUID_FLAT_BAYESIAN "Account GUID based bayesian with flat KVP"
 #define GNC_FEATURE_SQLITE3_ISO_DATES "ISO-8601 formatted date strings in SQLite3 databases."
 #define GNC_FEATURE_REG_SORT_FILTER "Register sort and filter settings stored in .gcm file"
+#define GNC_FEATURE_BUDGET_UNREVERSED "Use natural signs in budget amounts"
 
 /** @} */
 



Summary of changes:
 gnucash/gnome/gnc-budget-view.c                    | 67 +++++++++++++---------
 gnucash/gnome/gnc-plugin-page-budget.c             | 14 +++--
 .../standard-reports/budget-balance-sheet.scm      |  3 +-
 .../standard-reports/budget-income-statement.scm   |  3 +-
 gnucash/report/standard-reports/budget.scm         | 33 +++++++++++
 libgnucash/app-utils/app-utils.i                   |  2 +
 libgnucash/app-utils/gnc-ui-util.c                 | 17 ++++++
 libgnucash/app-utils/gnc-ui-util.h                 | 10 ++++
 libgnucash/engine/gnc-features.c                   |  1 +
 libgnucash/engine/gnc-features.h                   |  1 +
 10 files changed, 115 insertions(+), 36 deletions(-)



More information about the gnucash-changes mailing list