r23497 - gnucash/trunk/src/gnome - Fix bug 653594 related to check printing.

Mike Alexander mta at code.gnucash.org
Sat Dec 7 02:33:33 EST 2013


Author: mta
Date: 2013-12-07 02:33:33 -0500 (Sat, 07 Dec 2013)
New Revision: 23497
Trac: http://svn.gnucash.org/trac/changeset/23497

Modified:
   gnucash/trunk/src/gnome/dialog-print-check.c
   gnucash/trunk/src/gnome/dialog-print-check2.c
   gnucash/trunk/src/gnome/gnc-plugin-page-register.c
   gnucash/trunk/src/gnome/gnc-plugin-page-register2.c
Log:
Fix bug 653594 related to check printing.
This bug has two parts.  The original bug was that the wrong split is sometimes
used to print the check.  In the comments a second problem was mentioned:
sometimes the wrong split is omitted from the split list in formats that print
all the splits.

Modified: gnucash/trunk/src/gnome/dialog-print-check.c
===================================================================
--- gnucash/trunk/src/gnome/dialog-print-check.c	2013-12-07 07:33:24 UTC (rev 23496)
+++ gnucash/trunk/src/gnome/dialog-print-check.c	2013-12-07 07:33:33 UTC (rev 23497)
@@ -381,31 +381,29 @@
 get_check_splits_amount(PrintCheckDialog *pcd)
 {
     gchar* amount = NULL;
-    gchar* amt_temp;
-    int cnt;
-    const gchar* split_amount;
-    int nSplits;
     Transaction *trans;
-    Split *split;
     GList *node;
     SplitList* s_list;
 
     trans = xaccSplitGetParent(pcd->split);
-    nSplits = xaccTransCountSplits(trans);
     s_list = xaccTransGetSplitList(trans);
     if ( !s_list ) return NULL;
 
     amount = g_strconcat("", NULL);
     node = s_list;
-    cnt = 1;
-    while ( cnt < nSplits )
+    while ( node )
     {
-        cnt++;
-        split = node->data;
-        split_amount = xaccPrintAmount(xaccSplitGetAmount(split), gnc_split_amount_print_info(split, TRUE));
-        amt_temp = amount;
-        amount = g_strconcat(amt_temp, "\n", split_amount, NULL);
-        g_free(amt_temp);
+        Split *split = node->data;
+        /* Include all splits except the main split for the check */
+        if (split != pcd->split)
+        {
+            const gchar* split_amount;
+            gchar* amt_temp;
+            split_amount = xaccPrintAmount(xaccSplitGetAmount(split), gnc_split_amount_print_info(split, TRUE));
+            amt_temp = amount;
+            amount = g_strconcat(amt_temp, "\n", split_amount, NULL);
+            g_free(amt_temp);
+        }
         node = node->next;
     }
     return amount;
@@ -418,31 +416,29 @@
 get_check_splits_memo(PrintCheckDialog *pcd)
 {
     gchar* memo = NULL;
-    gchar* memo_temp;
-    int cnt;
     const gchar* split_memo;
-    int nSplits;
     Transaction *trans;
-    Split *split;
     GList *node;
     SplitList* s_list;
 
     trans = xaccSplitGetParent(pcd->split);
-    nSplits = xaccTransCountSplits(trans);
     s_list = xaccTransGetSplitList(trans);
     if ( !s_list ) return NULL;
 
     memo = g_strconcat("", NULL);
     node = s_list;
-    cnt = 1;
-    while ( cnt < nSplits )
+    while ( node )
     {
-        cnt++;
-        split = node->data;
-        split_memo = xaccSplitGetMemo(split);
-        memo_temp = memo;
-        memo = g_strconcat(memo_temp, "\n", split_memo, NULL);
-        g_free(memo_temp);
+        Split *split = node->data;
+        /* Include all splits except the main split for the check */
+        if (split != pcd->split)
+        {
+            gchar* memo_temp;
+            split_memo = xaccSplitGetMemo(split);
+            memo_temp = memo;
+            memo = g_strconcat(memo_temp, "\n", split_memo, NULL);
+            g_free(memo_temp);
+        }
         node = node->next;
     }
     return memo;
@@ -455,33 +451,31 @@
 get_check_splits_account(PrintCheckDialog *pcd)
 {
     gchar* account = NULL;
-    gchar* account_temp;
-    int cnt;
-    const gchar* aName = NULL;
-    int nSplits;
-    Account *pAccount;
     Transaction *trans;
-    Split *split;
     GList *node;
     SplitList* s_list;
 
     trans = xaccSplitGetParent(pcd->split);
-    nSplits = xaccTransCountSplits(trans);
     s_list = xaccTransGetSplitList(trans);
     if ( !s_list ) return NULL;
 
     account = g_strconcat("", NULL);
     node = s_list;
-    cnt = 1;
-    while ( cnt < nSplits )
+    while ( node )
     {
-        cnt++;
-        split = node->data;
-        pAccount = xaccSplitGetAccount(split);
-        aName = gnc_get_account_name_for_register(pAccount);
-        account_temp = account;
-        account = g_strconcat(account_temp, "\n", aName, NULL);
-        g_free(account_temp);
+        Split *split = node->data;
+        /* Include all splits except the main split for the check */
+        if (split != pcd->split)
+        {
+            gchar* account_temp;
+            const gchar* aName = NULL;
+            Account *pAccount;
+            pAccount = xaccSplitGetAccount(split);
+            aName = gnc_get_account_name_for_register(pAccount);
+            account_temp = account;
+            account = g_strconcat(account_temp, "\n", aName, NULL);
+            g_free(account_temp);
+        }
         node = node->next;
     }
     return account;

Modified: gnucash/trunk/src/gnome/dialog-print-check2.c
===================================================================
--- gnucash/trunk/src/gnome/dialog-print-check2.c	2013-12-07 07:33:24 UTC (rev 23496)
+++ gnucash/trunk/src/gnome/dialog-print-check2.c	2013-12-07 07:33:33 UTC (rev 23497)
@@ -381,31 +381,29 @@
 get_check_splits_amount2(PrintCheckDialog *pcd)
 {
     gchar* amount = NULL;
-    gchar* amt_temp;
-    int cnt;
-    const gchar* split_amount;
-    int nSplits;
     Transaction *trans;
-    Split *split;
     GList *node;
     SplitList* s_list;
 
     trans = xaccSplitGetParent(pcd->split);
-    nSplits = xaccTransCountSplits(trans);
     s_list = xaccTransGetSplitList(trans);
     if ( !s_list ) return NULL;
 
     amount = g_strconcat("", NULL);
     node = s_list;
-    cnt = 1;
-    while ( cnt < nSplits )
+    while ( node )
     {
-        cnt++;
-        split = node->data;
-        split_amount = xaccPrintAmount(xaccSplitGetAmount(split), gnc_split_amount_print_info(split, TRUE));
-        amt_temp = amount;
-        amount = g_strconcat(amt_temp, "\n", split_amount, NULL);
-        g_free(amt_temp);
+        Split *split = node->data;
+        /* Include all splits except the main split for the check */
+        if (split != pcd->split)
+        {
+            const gchar* split_amount;
+            gchar* amt_temp;
+            split_amount = xaccPrintAmount(xaccSplitGetAmount(split), gnc_split_amount_print_info(split, TRUE));
+            amt_temp = amount;
+            amount = g_strconcat(amt_temp, "\n", split_amount, NULL);
+            g_free(amt_temp);
+        }
         node = node->next;
     }
     return amount;
@@ -418,31 +416,29 @@
 get_check_splits_memo2(PrintCheckDialog *pcd)
 {
     gchar* memo = NULL;
-    gchar* memo_temp;
-    int cnt;
     const gchar* split_memo;
-    int nSplits;
     Transaction *trans;
-    Split *split;
     GList *node;
     SplitList* s_list;
 
     trans = xaccSplitGetParent(pcd->split);
-    nSplits = xaccTransCountSplits(trans);
     s_list = xaccTransGetSplitList(trans);
     if ( !s_list ) return NULL;
 
     memo = g_strconcat("", NULL);
     node = s_list;
-    cnt = 1;
-    while ( cnt < nSplits )
+    while ( node )
     {
-        cnt++;
-        split = node->data;
-        split_memo = xaccSplitGetMemo(split);
-        memo_temp = memo;
-        memo = g_strconcat(memo_temp, "\n", split_memo, NULL);
-        g_free(memo_temp);
+        Split *split = node->data;
+        /* Include all splits except the main split for the check */
+        if (split != pcd->split)
+        {
+            gchar* memo_temp;
+            split_memo = xaccSplitGetMemo(split);
+            memo_temp = memo;
+            memo = g_strconcat(memo_temp, "\n", split_memo, NULL);
+            g_free(memo_temp);
+        }
         node = node->next;
     }
     return memo;
@@ -455,33 +451,31 @@
 get_check_splits_account2(PrintCheckDialog *pcd)
 {
     gchar* account = NULL;
-    gchar* account_temp;
-    int cnt;
-    const gchar* aName = NULL;
-    int nSplits;
-    Account *pAccount;
     Transaction *trans;
-    Split *split;
     GList *node;
     SplitList* s_list;
 
     trans = xaccSplitGetParent(pcd->split);
-    nSplits = xaccTransCountSplits(trans);
     s_list = xaccTransGetSplitList(trans);
     if ( !s_list ) return NULL;
 
     account = g_strconcat("", NULL);
     node = s_list;
-    cnt = 1;
-    while ( cnt < nSplits )
+    while ( node )
     {
-        cnt++;
-        split = node->data;
-        pAccount = xaccSplitGetAccount(split);
-        aName = gnc_get_account_name_for_register(pAccount);
-        account_temp = account;
-        account = g_strconcat(account_temp, "\n", aName, NULL);
-        g_free(account_temp);
+        Split *split = node->data;
+        /* Include all splits except the main split for the check */
+        if (split != pcd->split)
+        {
+            gchar* account_temp;
+            const gchar* aName = NULL;
+            Account *pAccount;
+            pAccount = xaccSplitGetAccount(split);
+            aName = gnc_get_account_name_for_register(pAccount);
+            account_temp = account;
+            account = g_strconcat(account_temp, "\n", aName, NULL);
+            g_free(account_temp);
+        }
         node = node->next;
     }
     return account;

Modified: gnucash/trunk/src/gnome/gnc-plugin-page-register.c
===================================================================
--- gnucash/trunk/src/gnome/gnc-plugin-page-register.c	2013-12-07 07:33:24 UTC (rev 23496)
+++ gnucash/trunk/src/gnome/gnc-plugin-page-register.c	2013-12-07 07:33:33 UTC (rev 23497)
@@ -2696,6 +2696,7 @@
     Transaction   * trans;
     GList         * splits = NULL, *item;
     GNCLedgerDisplayType ledger_type;
+    Account       * account;
 
     ENTER("(action %p, plugin_page %p)", action, plugin_page);
 
@@ -2706,14 +2707,30 @@
     ledger_type = gnc_ledger_display_type(priv->ledger);
     if (ledger_type == LD_SINGLE || ledger_type == LD_SUBACCOUNT)
     {
+        account  = gnc_plugin_page_register_get_account (plugin_page);
         split    = gnc_split_register_get_current_split(reg);
         trans    = xaccSplitGetParent(split);
 
         if (split && trans)
         {
-            splits = g_list_append(splits, split);
-            gnc_ui_print_check_dialog_create(plugin_page, splits);
-            g_list_free(splits);
+            if (xaccSplitGetAccount(split) == account)
+            {
+                splits = g_list_append(splits, split);
+                gnc_ui_print_check_dialog_create(plugin_page, splits);
+                g_list_free(splits);
+            }
+            else
+            {
+                /* This split is not for the account shown in this register.  Get the
+                   split that anchors the transaction to the registor */
+                split = gnc_split_register_get_current_trans_split(reg, NULL);
+                if (split)
+                {
+                    splits = g_list_append(splits, split);
+                    gnc_ui_print_check_dialog_create(plugin_page, splits);
+                    g_list_free(splits);
+                }
+            }           
         }
     }
     else if (ledger_type == LD_GL && reg->type == SEARCH_LEDGER)

Modified: gnucash/trunk/src/gnome/gnc-plugin-page-register2.c
===================================================================
--- gnucash/trunk/src/gnome/gnc-plugin-page-register2.c	2013-12-07 07:33:24 UTC (rev 23496)
+++ gnucash/trunk/src/gnome/gnc-plugin-page-register2.c	2013-12-07 07:33:33 UTC (rev 23497)
@@ -2543,6 +2543,7 @@
     Transaction   * trans;
     GList         * splits = NULL, *item;
     GNCLedgerDisplay2Type ledger_type;
+    Account       * account;
 
     ENTER("(action %p, plugin_page %p)", action, plugin_page);
 
@@ -2555,6 +2556,7 @@
 
     if (ledger_type == LD2_SINGLE || ledger_type == LD2_SUBACCOUNT)
     {
+        account  = gnc_plugin_page_register2_get_account (plugin_page);
         split = gnc_tree_view_split_reg_get_current_split (view);
         trans = xaccSplitGetParent (split);
 
@@ -2587,9 +2589,24 @@
 
         if (split && trans)
         {
-            splits = g_list_append (splits, split);
-            gnc_ui_print_check_dialog_create2 (plugin_page, splits);
-            g_list_free (splits);
+            if (xaccSplitGetAccount(split) == account)
+            {
+                splits = g_list_append(splits, split);
+                gnc_ui_print_check_dialog_create2 (plugin_page, splits);
+                g_list_free(splits);
+            }
+            else
+            {
+                /* This split is not for the account shown in this register.  Get the
+                   split for that account and use it. */
+                split = gnc_tree_model_split_reg_trans_get_split_equal_to_ancestor(trans, account);
+                if (split)
+                {
+                    splits = g_list_append(splits, split);
+                    gnc_ui_print_check_dialog_create2 (plugin_page, splits);
+                    g_list_free(splits);
+                }
+            }           
         }
     }
     else if (ledger_type == LD2_GL && model->type == SEARCH_LEDGER2)



More information about the gnucash-changes mailing list