gnucash maint: [business]Add diagnostic messages to GncEntry and GncInvoice.

John Ralls jralls at code.gnucash.org
Sat Mar 5 21:18:34 EST 2022


Updated	 via  https://github.com/Gnucash/gnucash/commit/ce2b89fd (commit)
	from  https://github.com/Gnucash/gnucash/commit/916caa25 (commit)



commit ce2b89fd8cae4c5c78ba6925e78d18fca6a3df6a
Author: John Ralls <jralls at ceridwen.us>
Date:   Sat Mar 5 18:17:58 2022 -0800

    [business]Add diagnostic messages to GncEntry and GncInvoice.

diff --git a/gnucash/import-export/ofx/gnc-ofx-import.c b/gnucash/import-export/ofx/gnc-ofx-import.c
index d6527561c..c1f0bd205 100644
--- a/gnucash/import-export/ofx/gnc-ofx-import.c
+++ b/gnucash/import-export/ofx/gnc-ofx-import.c
@@ -625,7 +625,10 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void *user_data)
             }
             else if (data.reference_number_valid)
             {
-                gnc_set_num_action(transaction, split, data.reference_number, NULL);
+                const char *num_value =
+                    strcasecmp (data.reference_number, "null") == 0 ? "" :
+                    data.check_number;
+                gnc_set_num_action(transaction, split, num_value, NULL);
             }
             /* Also put the ofx transaction's memo in the
              * split's memo field */
diff --git a/libgnucash/engine/gncEntry.c b/libgnucash/engine/gncEntry.c
index b96754463..ca1b72545 100644
--- a/libgnucash/engine/gncEntry.c
+++ b/libgnucash/engine/gncEntry.c
@@ -29,6 +29,7 @@
 
 #include <glib.h>
 #include <qofinstance-p.h>
+#include <inttypes.h>
 
 #include "gnc-commodity.h"
 
@@ -120,7 +121,7 @@ gncEntryDiscountHowToString (GncDiscountHow how)
     case (GNC_DISC_POSTTAX):
         return "POSTTAX";
     default:
-        g_warning ("asked to translate unknown discount-how %d.\n", how);
+        PWARN ("asked to translate unknown discount-how %d.\n", how);
         break;
     }
     return NULL;
@@ -145,7 +146,7 @@ gboolean gncEntryDiscountStringToHow (const char *str, GncDiscountHow *how)
         *how = GNC_DISC_POSTTAX;
         return TRUE;
     }
-    g_warning ("asked to translate unknown discount-how string %s.\n",
+    PWARN ("asked to translate unknown discount-how string %s.\n",
                str ? str : "(null)");
 
     return FALSE;
@@ -162,7 +163,7 @@ const char * gncEntryPaymentTypeToString (GncEntryPaymentType type)
     case (GNC_PAYMENT_CARD):
         return "CARD";
     default:
-        g_warning ("asked to translate unknown payment type %d.\n", type);
+        PWARN ("asked to translate unknown payment type %d.\n", type);
         break;
     }
     return NULL ;
@@ -182,7 +183,7 @@ gboolean gncEntryPaymentStringToType (const char *str, GncEntryPaymentType *type
         *type = GNC_PAYMENT_CARD;
         return TRUE;
     }
-    g_warning ("asked to translate unknown discount-how string %s.\n",
+    PWARN ("asked to translate unknown discount-how string %s.\n",
                str ? str : "(null)");
 
     return FALSE;
@@ -591,29 +592,46 @@ void gncEntrySetInvPrice (GncEntry *entry, gnc_numeric price)
 void gncEntrySetInvTaxable (GncEntry *entry, gboolean taxable)
 {
     if (!entry) return;
-    if (entry->i_taxable == taxable) return;
+
+    ENTER ("%d", taxable);
+    if (entry->i_taxable == taxable) {
+         LEAVE ("Value already set");
+         return;
+    }
     gncEntryBeginEdit (entry);
     entry->i_taxable = taxable;
     entry->values_dirty = TRUE;
     mark_entry (entry);
     gncEntryCommitEdit (entry);
+    LEAVE ("");
 }
 
 void gncEntrySetInvTaxIncluded (GncEntry *entry, gboolean taxincluded)
 {
     if (!entry) return;
-    if (entry->i_taxincluded == taxincluded) return;
+
+    ENTER ("%d", taxincluded);
+    if (entry->i_taxincluded == taxincluded) {
+         LEAVE ("Value already set");
+         return;
+    }
     gncEntryBeginEdit (entry);
     entry->i_taxincluded = taxincluded;
     entry->values_dirty = TRUE;
     mark_entry (entry);
     gncEntryCommitEdit (entry);
+    LEAVE ("");
 }
 
 void gncEntrySetInvTaxTable (GncEntry *entry, GncTaxTable *table)
 {
     if (!entry) return;
-    if (entry->i_tax_table == table) return;
+
+    ENTER ("%s", gncTaxTableGetName (table));
+    if (entry->i_tax_table == table) {
+         LEAVE ("Value already set");
+         return;
+    }
     gncEntryBeginEdit (entry);
     if (entry->i_tax_table)
         gncTaxTableDecRef (entry->i_tax_table);
@@ -623,6 +641,7 @@ void gncEntrySetInvTaxTable (GncEntry *entry, GncTaxTable *table)
     entry->values_dirty = TRUE;
     mark_entry (entry);
     gncEntryCommitEdit (entry);
+    LEAVE ("");
 }
 
 void gncEntrySetInvDiscount (GncEntry *entry, gnc_numeric discount)
@@ -715,29 +734,46 @@ void gncEntrySetBillPrice (GncEntry *entry, gnc_numeric price)
 void gncEntrySetBillTaxable (GncEntry *entry, gboolean taxable)
 {
     if (!entry) return;
-    if (entry->b_taxable == taxable) return;
+
+    ENTER ("%d", taxable);
+    if (entry->b_taxable == taxable) {
+         LEAVE ("Value already set");
+         return;
+    }
     gncEntryBeginEdit (entry);
     entry->b_taxable = taxable;
     entry->values_dirty = TRUE;
     mark_entry (entry);
     gncEntryCommitEdit (entry);
+    LEAVE ("");
 }
 
 void gncEntrySetBillTaxIncluded (GncEntry *entry, gboolean taxincluded)
 {
     if (!entry) return;
-    if (entry->b_taxincluded == taxincluded) return;
+
+    ENTER ("%d", taxincluded);
+    if (entry->b_taxincluded == taxincluded) {
+         LEAVE ("Value already set");
+         return;
+    }
     gncEntryBeginEdit (entry);
     entry->b_taxincluded = taxincluded;
     entry->values_dirty = TRUE;
     mark_entry (entry);
     gncEntryCommitEdit (entry);
+    LEAVE ("");
 }
 
 void gncEntrySetBillTaxTable (GncEntry *entry, GncTaxTable *table)
 {
     if (!entry) return;
-    if (entry->b_tax_table == table) return;
+
+    ENTER ("%s", gncTaxTableGetName (table));
+    if (entry->b_tax_table == table) {
+         LEAVE ("Value already set");
+         return;
+    }
     gncEntryBeginEdit (entry);
     if (entry->b_tax_table)
         gncTaxTableDecRef (entry->b_tax_table);
@@ -747,6 +783,7 @@ void gncEntrySetBillTaxTable (GncEntry *entry, GncTaxTable *table)
     entry->values_dirty = TRUE;
     mark_entry (entry);
     gncEntryCommitEdit (entry);
+    LEAVE ("");
 }
 
 void gncEntrySetBillable (GncEntry *entry, gboolean billable)
@@ -1106,10 +1143,12 @@ static void gncEntryComputeValueInt (gnc_numeric qty, gnc_numeric price,
     GList     * entries = gncTaxTableGetEntries (tax_table);
     GList     * node;
 
+    ENTER ("");
     /* Step 1: compute the aggregate price */
 
     aggregate = gnc_numeric_mul (qty, price, GNC_DENOM_AUTO, GNC_HOW_DENOM_REDUCE | GNC_HOW_RND_ROUND);
 
+    PINFO ("Aggregate value %" PRId64 "/%" PRId64, aggregate.num, aggregate.denom);
     /* Step 2: compute the pre-tax aggregate */
 
     /* First, compute the aggregate tpercent and tvalue numbers */
@@ -1129,14 +1168,14 @@ static void gncEntryComputeValueInt (gnc_numeric qty, gnc_numeric price,
                                         GNC_HOW_DENOM_LCD);
             break;
         default:
-            g_warning ("Unknown tax type: %d", gncTaxTableEntryGetType (entry));
+            PWARN ("Unknown tax type: %d", gncTaxTableEntryGetType (entry));
             break;
         }
     }
     /* now we need to convert from 5% -> .05 */
     tpercent = gnc_numeric_div (tpercent, percent, GNC_DENOM_AUTO,
                                 GNC_HOW_DENOM_EXACT | GNC_HOW_RND_NEVER);
-
+    PINFO("Tax rate %" PRId64 "/%" PRId64, tpercent.num, tpercent.denom);
     /* Next, actually compute the pre-tax aggregate value based on the
      * taxincluded flag.
      */
@@ -1153,13 +1192,16 @@ static void gncEntryComputeValueInt (gnc_numeric qty, gnc_numeric price,
                                           gnc_numeric_create (1, 1),
                                           GNC_DENOM_AUTO, GNC_HOW_DENOM_LCD),
                                   GNC_DENOM_AUTO, GNC_HOW_DENOM_REDUCE | GNC_HOW_RND_ROUND);
+        PINFO ("pretax %" PRId64 "/%" PRId64, pretax.num, pretax.denom);
 	if (!gnc_numeric_zero_p(qty))
 	{
 	  i_net_price = gnc_numeric_div (pretax, qty, GNC_DENOM_AUTO, GNC_HOW_DENOM_REDUCE | GNC_HOW_RND_ROUND);
 	}
+        PINFO("i_net_price %" PRId64 "/%" PRId64, i_net_price.num, i_net_price.denom);
     }
     else
     {
+        PINFO ("Tax not included or no tax table, pretax is aggregate");
         pretax = aggregate;
     }
 
@@ -1224,7 +1266,7 @@ static void gncEntryComputeValueInt (gnc_numeric qty, gnc_numeric price,
         break;
 
     default:
-        g_warning ("unknown DiscountHow value: %d", discount_how);
+        PWARN ("unknown DiscountHow value: %d", discount_how);
         break;
     }
 
@@ -1247,6 +1289,7 @@ static void gncEntryComputeValueInt (gnc_numeric qty, gnc_numeric price,
     {
         GList *	taxes = NULL;
 
+        PINFO("Computing tax value list");
         for (node = entries; node; node = node->next)
         {
             GncTaxTableEntry *entry = node->data;
@@ -1276,6 +1319,7 @@ static void gncEntryComputeValueInt (gnc_numeric qty, gnc_numeric price,
     if (net_price != NULL)
       *net_price = i_net_price;
 
+    LEAVE ("");
     return;
 }
 
@@ -1317,12 +1361,14 @@ gncEntryRecomputeValues (GncEntry *entry)
     int denom;
     GList *tv_iter;
 
+    ENTER ("");
     /* See if either tax table changed since we last computed values */
     if (entry->i_tax_table)
     {
         time64 modtime = gncTaxTableLastModifiedSecs (entry->i_tax_table);
         if (entry->i_taxtable_modtime != modtime)
         {
+            PINFO ("Invoice tax table changed");
             entry->values_dirty = TRUE;
             entry->i_taxtable_modtime = modtime;
         }
@@ -1332,13 +1378,16 @@ gncEntryRecomputeValues (GncEntry *entry)
         time64 modtime = gncTaxTableLastModifiedSecs (entry->b_tax_table);
         if (entry->b_taxtable_modtime != modtime)
         {
+            PINFO ("Bill tax table changed");
             entry->values_dirty = TRUE;
             entry->b_taxtable_modtime = modtime;
         }
     }
 
-    if (!entry->values_dirty)
+    if (!entry->values_dirty) {
+        LEAVE ("No changes");
         return;
+    }
 
     /* Clear the last-computed tax values */
     if (entry->i_tax_values)
@@ -1397,6 +1446,7 @@ gncEntryRecomputeValues (GncEntry *entry)
                                                       denom, GNC_HOW_DENOM_EXACT | GNC_HOW_RND_ROUND_HALF_UP);
     }
     entry->values_dirty = FALSE;
+    LEAVE ("");
 }
 
 /* The "Int" functions below are for internal use only.
diff --git a/libgnucash/engine/gncInvoice.c b/libgnucash/engine/gncInvoice.c
index f3a5c5db1..745012bd1 100644
--- a/libgnucash/engine/gncInvoice.c
+++ b/libgnucash/engine/gncInvoice.c
@@ -30,6 +30,7 @@
 #include <config.h>
 
 #include <stdint.h>
+#include <inttypes.h>
 #include <glib.h>
 #include <glib/gi18n.h>
 #include <qofinstance-p.h>
@@ -943,6 +944,7 @@ static gnc_numeric gncInvoiceGetNetAndTaxesInternal (GncInvoice *invoice, gboole
 
     g_return_val_if_fail (invoice, net_total);
 
+    ENTER ("");
     /* Is the current document an invoice/credit note related to a customer or a vendor/employee ?
      * The GncEntry code needs to know to return the proper entry amounts
      */
@@ -966,7 +968,7 @@ static gnc_numeric gncInvoiceGetNetAndTaxesInternal (GncInvoice *invoice, gboole
             if (gnc_numeric_check (value) == GNC_ERROR_OK)
                 net_total = gnc_numeric_add (net_total, value, GNC_DENOM_AUTO, GNC_HOW_DENOM_LCD);
             else
-                g_warning ("bad value in our entry");
+                PWARN ("bad value in our entry");
         }
 
         if (taxes)
@@ -991,6 +993,7 @@ static gnc_numeric gncInvoiceGetNetAndTaxesInternal (GncInvoice *invoice, gboole
         *taxes = tv_list;
     }
 
+    LEAVE ("%" PRId64 "/%" PRId64, net_total.num, net_total.denom);
     return net_total;
 }
 
@@ -1004,6 +1007,7 @@ static gnc_numeric gncInvoiceGetTotalInternal (GncInvoice *invoice, gboolean use
 
     if (!invoice) return gnc_numeric_zero ();
 
+    ENTER ("");
     total = gncInvoiceGetNetAndTaxesInternal (invoice, use_value, use_tax? &taxes : NULL, use_payment_type, type);
 
     if (use_tax)
@@ -1015,6 +1019,7 @@ static gnc_numeric gncInvoiceGetTotalInternal (GncInvoice *invoice, gboolean use
                                  GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT | GNC_HOW_RND_ROUND_HALF_UP);
         gncAccountValueDestroy (taxes);
     }
+    LEAVE ("%" PRId64 "/%" PRId64, total.num, total.denom);
     return total;
 }
 
@@ -1070,6 +1075,7 @@ GList * gncInvoiceGetTypeListForOwnerType (GncOwnerType type)
         type_list = g_list_append (type_list, GINT_TO_POINTER(GNC_INVOICE_EMPL_CREDIT_NOTE));
         return type_list;
     default:
+        PWARN("Bad owner type, no invoices.");
         return NULL;
     }
 
@@ -1379,6 +1385,7 @@ GHashTable *gncInvoiceGetForeignCurrencies (const GncInvoice *invoice)
     gboolean is_cn = gncInvoiceGetIsCreditNote (invoice);
     GHashTable *amt_hash = g_hash_table_new_full (g_direct_hash, g_direct_equal,
                                                   NULL, g_free);
+    ENTER ("");
 
     for (entries_iter = invoice->entries; entries_iter != NULL; entries_iter = g_list_next(entries_iter))
     {
@@ -1429,6 +1436,8 @@ GHashTable *gncInvoiceGetForeignCurrencies (const GncInvoice *invoice)
         }
         gncAccountValueDestroy (tt_amts);
     }
+
+    LEAVE ("");
     return amt_hash;
 }
 
@@ -1442,6 +1451,7 @@ static gboolean gncInvoicePostAddSplit (QofBook *book,
 {
     Split *split;
 
+    ENTER ("");
     split = xaccMallocSplit (book);
     /* set action and memo? */
 
@@ -1484,6 +1494,8 @@ static gboolean gncInvoicePostAddSplit (QofBook *book,
               We can't really do anything sensible about it, and this is
                         a user-interface free zone so we can't try asking the user
               again either, have to return NULL*/
+            PERR("Multiple commodities with no price.");
+            LEAVE ("FALSE");
             return FALSE;
         }
         else
@@ -1496,6 +1508,7 @@ static gboolean gncInvoicePostAddSplit (QofBook *book,
         }
     }
 
+    LEAVE ("TRUE");
     return TRUE;
 }
 
@@ -1522,6 +1535,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
     if (!invoice || !acc) return NULL;
     if (gncInvoiceIsPosted (invoice)) return NULL;
 
+    ENTER ("");
     gncInvoiceBeginEdit (invoice);
     book = qof_instance_get_book (invoice);
 
@@ -1624,6 +1638,8 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
         value = gncEntryGetBalValue (entry, TRUE, is_cust_doc);
         tax   = gncEntryGetBalTaxValue (entry, TRUE, is_cust_doc);
 
+        DEBUG ("Tax %" PRId64 "/%" PRId64 " on entry value %" PRId64 "/%" PRId64,
+               tax.num, tax.denom, value.num, value.denom);
         /* add the value for the account split */
         this_acc = (is_cust_doc ? gncEntryGetInvAccount (entry) :
                     gncEntryGetBillAccount (entry));
@@ -1642,6 +1658,8 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
                       We can't really do anything sensible about it, and this is
                       a user-interface free zone so we can't try asking the user
                       again either, have to return NULL*/
+                    PERR("Failed to add split %s", gncEntryGetDescription (entry));
+                    LEAVE ("NULL");
                     return NULL;
                 }
 
@@ -1676,12 +1694,12 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
 
             }
             else
-                g_warning ("bad value in our entry");
+                PWARN ("bad value in our entry");
         }
 
         /* check the taxes */
         if (gnc_numeric_check (tax) != GNC_ERROR_OK)
-            g_warning ("bad tax in our entry");
+            PWARN ("bad tax in our entry");
 
     } /* for */
 
@@ -1691,6 +1709,8 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
     gncAccountValueDestroy (taxes);
 
     /* Iterate through the splitinfo list and generate the splits */
+    if (splitinfo)
+        PINFO ("Processing Split List");
     for (iter = splitinfo; iter; iter = iter->next)
     {
         GncAccountValue *acc_val = iter->data;
@@ -1704,6 +1724,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
               We can't really do anything sensible about it, and this is
               a user-interface free zone so we can't try asking the user
               again either, have to return NULL*/
+            PERR("Failed to add split %s, aborting accumulated splits.", memo);
             return NULL;
         }
     }
@@ -1720,6 +1741,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
         gnc_numeric to_charge_bal_amount = (is_cn ? gnc_numeric_neg (invoice->to_charge_amount)
                                             : invoice->to_charge_amount);
 
+        PINFO ("Process to_card payment split");
         /* Set memo. */
         xaccSplitSetMemo (split, _("Extra to Charge Card"));
         /* Set action based on book option */
@@ -1740,6 +1762,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
     {
         Split *split = xaccMallocSplit (book);
 
+        PINFO ("Process to_card balancing split");
         /* Set memo */
         xaccSplitSetMemo (split, memo);
         /* Set action based on book option */
@@ -1778,6 +1801,7 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
     if (autopay)
         gncInvoiceAutoApplyPayments (invoice);
 
+    LEAVE ("");
     return txn;
 }
 
@@ -1797,6 +1821,7 @@ gncInvoiceUnpost (GncInvoice *invoice, gboolean reset_tax_tables)
     lot = gncInvoiceGetPostedLot (invoice);
     g_return_val_if_fail (lot, FALSE);
 
+    ENTER ("");
     /* Destroy the Posted Transaction */
     xaccTransClearReadOnly (txn);
     xaccTransBeginEdit (txn);
@@ -1822,6 +1847,8 @@ gncInvoiceUnpost (GncInvoice *invoice, gboolean reset_tax_tables)
     // Note: make a copy of the lot list here, when splits are deleted from the lot,
     //       the original list may be destroyed by the lot code.
     lot_split_list = g_list_copy (gnc_lot_get_split_list (lot));
+    if (lot_split_list)
+        PINFO ("Recreating link transactions for remaining lots");
     for (lot_split_iter = lot_split_list; lot_split_iter; lot_split_iter = lot_split_iter->next)
     {
         Split *split = lot_split_iter->data;
@@ -1912,6 +1939,8 @@ gncInvoiceUnpost (GncInvoice *invoice, gboolean reset_tax_tables)
     mark_invoice (invoice);
     gncInvoiceCommitEdit (invoice);
 
+    LEAVE ("TRUE");
+
     return TRUE;
 }
 



Summary of changes:
 gnucash/import-export/ofx/gnc-ofx-import.c |  5 +-
 libgnucash/engine/gncEntry.c               | 78 ++++++++++++++++++++++++------
 libgnucash/engine/gncInvoice.c             | 35 ++++++++++++--
 3 files changed, 100 insertions(+), 18 deletions(-)



More information about the gnucash-changes mailing list