r21404 - gnucash/trunk/src - Prepare invoice search to handle both invoices and credit notes

Geert Janssens gjanssens at code.gnucash.org
Sun Oct 9 17:06:02 EDT 2011


Author: gjanssens
Date: 2011-10-09 17:06:02 -0400 (Sun, 09 Oct 2011)
New Revision: 21404
Trac: http://svn.gnucash.org/trac/changeset/21404

Modified:
   gnucash/trunk/src/business/business-gnome/dialog-invoice.c
   gnucash/trunk/src/engine/gncInvoice.c
   gnucash/trunk/src/engine/gncInvoice.h
Log:
Prepare invoice search to handle both invoices and credit notes

Modified: gnucash/trunk/src/business/business-gnome/dialog-invoice.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-invoice.c	2011-10-09 21:05:52 UTC (rev 21403)
+++ gnucash/trunk/src/business/business-gnome/dialog-invoice.c	2011-10-09 21:06:02 UTC (rev 21404)
@@ -2703,32 +2703,35 @@
                                       (g_slist_prepend (NULL, OWNER_PARENTG),
                                        INVOICE_OWNER),
                                       gncOwnerGetGUID (owner), QOF_QUERY_OR);
-
             qof_query_merge_in_place (q, q2, QOF_QUERY_AND);
             qof_query_destroy (q2);
+
+            /* Use this base query as pre-fill query.
+             * This will pre-fill the search dialog with the query results
+             */
             q2 = qof_query_copy (q);
+
         }
         else
         {
-            QofQueryPredData *inv_type_pred;
-            GSList *param_list = NULL;
-            inv_type_pred = qof_query_int32_predicate(QOF_COMPARE_EQUAL,
-                            gncInvoiceGetTypeListForOwnerType(owner_type));
-            param_list = g_slist_prepend (param_list, INVOICE_TYPE);
-            qof_query_add_term (q, param_list, inv_type_pred, QOF_QUERY_AND);
-        }
-    }
+            QofQuery *q3 = qof_query_create ();
+            QofQueryPredData *inv_type_pred = NULL;
+            GList *type_list = NULL, *node = NULL;
 
-#if 0
-    if (start)
-    {
-        if (q2 == NULL)
-            q2 = qof_query_copy (q);
+            type_list = gncInvoiceGetTypeListForOwnerType(owner_type);
+            for (node = type_list; node; node=node->next)
+            {
+                inv_type_pred = qof_query_int32_predicate(QOF_COMPARE_EQUAL,
+                                GPOINTER_TO_INT(node->data));
+                qof_query_add_term (q3, g_slist_prepend (NULL, INVOICE_TYPE), inv_type_pred, QOF_QUERY_OR);
+            }
+            qof_query_merge_in_place (q, q3, QOF_QUERY_AND);
+            qof_query_destroy (q3);
 
-        qof_query_add_guid_match (q2, g_slist_prepend (NULL, QOF_PARAM_GUID),
-                                  gncInvoiceGetGUID (start), QOF_QUERY_AND);
+            /* Don't set a pre-fill query in this case, the result set would be too long */
+            q2 = NULL;
+        }
     }
-#endif
 
     /* Launch select dialog and return the result */
     sw = g_new0 (struct _invoice_select_window, 1);

Modified: gnucash/trunk/src/engine/gncInvoice.c
===================================================================
--- gnucash/trunk/src/engine/gncInvoice.c	2011-10-09 21:05:52 UTC (rev 21403)
+++ gnucash/trunk/src/engine/gncInvoice.c	2011-10-09 21:06:02 UTC (rev 21404)
@@ -851,19 +851,25 @@
     return gncInvoiceGetTotalInternal(invoice, TRUE, TRUE, TRUE, type);
 }
 
-// FIXME this should return a list of valid invoice types for a given owner type
-GncInvoiceType gncInvoiceGetTypeListForOwnerType (GncOwnerType type)
+GList * gncInvoiceGetTypeListForOwnerType (GncOwnerType type)
 {
+    GList *type_list = NULL;
     switch (type)
     {
     case GNC_OWNER_CUSTOMER:
-        return GNC_INVOICE_CUST_INVOICE;
+        type_list = g_list_append (type_list, GINT_TO_POINTER(GNC_INVOICE_CUST_INVOICE));
+        type_list = g_list_append (type_list, GINT_TO_POINTER(GNC_INVOICE_CUST_CREDIT_NOTE));
+        return type_list;
     case GNC_OWNER_VENDOR:
-        return GNC_INVOICE_VEND_INVOICE;
+        type_list = g_list_append (type_list, GINT_TO_POINTER(GNC_INVOICE_VEND_INVOICE));
+        type_list = g_list_append (type_list, GINT_TO_POINTER(GNC_INVOICE_VEND_CREDIT_NOTE));
+        return type_list;
     case GNC_OWNER_EMPLOYEE:
-        return GNC_INVOICE_EMPL_INVOICE;
+        type_list = g_list_append (type_list, GINT_TO_POINTER(GNC_INVOICE_EMPL_INVOICE));
+        type_list = g_list_append (type_list, GINT_TO_POINTER(GNC_INVOICE_EMPL_CREDIT_NOTE));
+        return type_list;
     default:
-        return GNC_INVOICE_UNDEFINED;
+        return NULL;
     }
 
 }

Modified: gnucash/trunk/src/engine/gncInvoice.h
===================================================================
--- gnucash/trunk/src/engine/gncInvoice.h	2011-10-09 21:05:52 UTC (rev 21403)
+++ gnucash/trunk/src/engine/gncInvoice.h	2011-10-09 21:06:02 UTC (rev 21404)
@@ -137,7 +137,7 @@
 const char * gncInvoiceGetBillingID (const GncInvoice *invoice);
 const char * gncInvoiceGetNotes (const GncInvoice *invoice);
 GncOwnerType gncInvoiceGetOwnerType (GncInvoice *invoice);
-GncInvoiceType gncInvoiceGetTypeListForOwnerType (GncOwnerType type);
+GList * gncInvoiceGetTypeListForOwnerType (GncOwnerType type);
 GncInvoiceType gncInvoiceGetType (GncInvoice *invoice);
 const char * gncInvoiceGetTypeString (GncInvoice *invoice);
 gnc_commodity * gncInvoiceGetCurrency (const GncInvoice *invoice);



More information about the gnucash-changes mailing list