gnucash stable: Multiple changes pushed

John Ralls jralls at code.gnucash.org
Thu Nov 9 17:03:41 EST 2023


Updated	 via  https://github.com/Gnucash/gnucash/commit/e6a30f77 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/c2ef684b (commit)
	from  https://github.com/Gnucash/gnucash/commit/0650f56e (commit)



commit e6a30f77087c2155acc1f2268d16f8e2cf0c6845
Merge: 0650f56e96 c2ef684b59
Author: John Ralls <jralls at ceridwen.us>
Date:   Thu Nov 9 13:57:06 2023 -0800

    Merge Mark Browning's 'check-print-subacct' into stable.


commit c2ef684b59cf7bd3a28d0a8a4c1a7dd9bfd0b76a
Author: Mark Browning <mabrowningrr at gmail.com>
Date:   Fri Feb 28 01:59:36 2020 -0600

    Correct check amount when printed from subaccount
    
    Previously, GnuCash would include only a single split's amount as the check
    amount. If a "bank" account has multiple subaccounts for budgeting reasons, and
    a transaction involves both "internal" (e.g. from one bank subaccount to
    another bank subaccount) and external transfers, then even when a "subaccount"
    register showing the top-level bank account is printed from, the check will
    have the amount of the first split rather than the total of all splits which
    are from subaccounts.
    
    This change communicates the parent account (when viewed from a "subccount"
    register) to the check printing dialog so that the check amount matches the
    amount displayed in the register.

diff --git a/gnucash/gnome/dialog-payment.c b/gnucash/gnome/dialog-payment.c
index b1d048ff51..d73d093361 100644
--- a/gnucash/gnome/dialog-payment.c
+++ b/gnucash/gnome/dialog-payment.c
@@ -1041,7 +1041,7 @@ gnc_payment_ok_cb (G_GNUC_UNUSED GtkWidget *widget, gpointer data)
         Split *split = xaccTransFindSplitByAccount (pw->tx_info->txn, pw->xfer_acct);
         GList *splits = NULL;
         splits = g_list_append(splits, split);
-        gnc_ui_print_check_dialog_create(NULL, splits);
+        gnc_ui_print_check_dialog_create(NULL, splits, NULL);
         g_list_free (splits);
     }
 
diff --git a/gnucash/gnome/dialog-print-check.c b/gnucash/gnome/dialog-print-check.c
index 684030baba..c351cfbf87 100644
--- a/gnucash/gnome/dialog-print-check.c
+++ b/gnucash/gnome/dialog-print-check.c
@@ -278,6 +278,7 @@ struct _print_check_dialog
 
     Split *split;
     GList *splits;
+    Account* account;
 
     GtkWidget *format_combobox;
     gint format_max;
@@ -369,6 +370,44 @@ get_check_address( PrintCheckDialog *pcd)
     return address;
 }
 
+struct _trans_amount
+{
+    const Transaction* trans;
+    gnc_numeric amount;
+};
+
+static void
+subtotal_subaccount(const Account *account, struct _trans_amount* trans_amount)
+{
+    /* Get the amount of this account in the transaction.*/
+    gnc_numeric amount = xaccTransGetAccountAmount(trans_amount->trans, account);
+    /* Accumulate. */
+    trans_amount->amount = gnc_numeric_add_fixed(trans_amount->amount, amount);
+}
+
+/* This function returns the amount of the check.
+ */
+static gnc_numeric
+get_check_amount(PrintCheckDialog *pcd)
+{
+    gnc_numeric amount;
+    if (pcd->account)
+    {
+        /* A parent account, e.g. from a subaccount register plugin page.
+         * Subtotal the amount of all splits from descendant accounts. */
+        struct _trans_amount trans_amount;
+        trans_amount.trans = xaccSplitGetParent(pcd->split);
+        trans_amount.amount = gnc_numeric_zero();
+        gnc_account_foreach_descendant(pcd->account, (AccountCb)subtotal_subaccount, &trans_amount);
+        amount = trans_amount.amount;
+    }
+    else
+    {
+        /* Print just the amount of the split. */
+        amount = xaccSplitGetAmount(pcd->split);
+    }
+    return gnc_numeric_abs(amount);
+}
 
 //@{
 /** @name Split printing functions */
@@ -1606,10 +1645,13 @@ initialize_format_combobox (PrintCheckDialog *pcd)
 /*****************************************************
  * gnc_ui_print_check_dialog_create                  *
  * make a new print check dialog and wait for it.    *
+ * If account is given, this is a parent account to  *
+ * subtotal the amount of all splits under it.       *
  *****************************************************/
 void
 gnc_ui_print_check_dialog_create(GtkWidget *parent,
-                                 GList *splits)
+                                 GList *splits,
+                                 Account* account)
 {
     PrintCheckDialog *pcd;
     GtkBuilder *builder;
@@ -1620,6 +1662,7 @@ gnc_ui_print_check_dialog_create(GtkWidget *parent,
     pcd = g_new0(PrintCheckDialog, 1);
     pcd->caller_window = GTK_WINDOW(parent);
     pcd->splits = g_list_copy(splits);
+    pcd->account = account;
 
     builder = gtk_builder_new();
     gnc_builder_add_from_file (builder, "dialog-print-check.glade", "adjustment1");
@@ -2112,7 +2155,7 @@ draw_page_items(GtkPrintContext *context,
     trans = xaccSplitGetParent(pcd->split);
     /* This was valid when the check printing dialog was instantiated. */
     g_return_if_fail(trans);
-    amount = gnc_numeric_abs(xaccSplitGetAmount(pcd->split));
+    amount = get_check_amount(pcd);
 
     if (format->font)
         default_desc = pango_font_description_from_string(format->font);
diff --git a/gnucash/gnome/dialog-print-check.h b/gnucash/gnome/dialog-print-check.h
index e36a78e940..818b7df9e5 100644
--- a/gnucash/gnome/dialog-print-check.h
+++ b/gnucash/gnome/dialog-print-check.h
@@ -29,6 +29,7 @@
 typedef struct _print_check_dialog PrintCheckDialog;
 
 void gnc_ui_print_check_dialog_create(GtkWidget *parent,
-                                      GList *splits);
+                                      GList *splits,
+                                      Account* account);
 
 #endif
diff --git a/gnucash/gnome/gnc-plugin-page-register.c b/gnucash/gnome/gnc-plugin-page-register.c
index c9bee2493e..58135d1455 100644
--- a/gnucash/gnome/gnc-plugin-page-register.c
+++ b/gnucash/gnome/gnc-plugin-page-register.c
@@ -3458,7 +3458,7 @@ gnc_plugin_page_register_cmd_print_check (GSimpleAction *simple,
     Transaction*    trans;
     GList*          splits = NULL, *item;
     GNCLedgerDisplayType ledger_type;
-    Account*        account;
+    Account*        account, *subaccount = NULL;
     GtkWidget*      window;
 
     ENTER ("(action %p, page %p)", simple, page);
@@ -3474,13 +3474,19 @@ gnc_plugin_page_register_cmd_print_check (GSimpleAction *simple,
         account  = gnc_plugin_page_register_get_account (page);
         split    = gnc_split_register_get_current_split (reg);
         trans    = xaccSplitGetParent (split);
+        if (ledger_type == LD_SUBACCOUNT)
+        {
+            /* Set up subaccount printing, where the check amount matches the
+             * value displayed in the register. */
+            subaccount = account;
+        }
 
         if (split && trans)
         {
             if (xaccSplitGetAccount (split) == account)
             {
                 splits = g_list_prepend (splits, split);
-                gnc_ui_print_check_dialog_create (window, splits);
+                gnc_ui_print_check_dialog_create (window, splits, subaccount);
                 g_list_free (splits);
             }
             else
@@ -3491,7 +3497,7 @@ gnc_plugin_page_register_cmd_print_check (GSimpleAction *simple,
                 if (split)
                 {
                     splits = g_list_prepend (splits, split);
-                    gnc_ui_print_check_dialog_create (window, splits);
+                    gnc_ui_print_check_dialog_create (window, splits, subaccount);
                     g_list_free (splits);
                 }
             }
@@ -3544,7 +3550,7 @@ gnc_plugin_page_register_cmd_print_check (GSimpleAction *simple,
                 }
             }
         }
-        gnc_ui_print_check_dialog_create (window, splits);
+        gnc_ui_print_check_dialog_create (window, splits, NULL);
     }
     else
     {



Summary of changes:
 gnucash/gnome/dialog-payment.c           |  2 +-
 gnucash/gnome/dialog-print-check.c       | 47 ++++++++++++++++++++++++++++++--
 gnucash/gnome/dialog-print-check.h       |  3 +-
 gnucash/gnome/gnc-plugin-page-register.c | 14 +++++++---
 4 files changed, 58 insertions(+), 8 deletions(-)



More information about the gnucash-changes mailing list