From fa2338deb154a3914fae0f0a24c527e3724386ca Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Sun, 9 Oct 2011 21:06:02 +0000 Subject: [PATCH] Prepare invoice search to handle both invoices and credit notes git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@21404 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/business/business-gnome/dialog-invoice.c | 39 +++++++++++--------- src/engine/gncInvoice.c | 18 ++++++--- src/engine/gncInvoice.h | 2 +- 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/src/business/business-gnome/dialog-invoice.c b/src/business/business-gnome/dialog-invoice.c index 382a7b89a5..3a5dc92b83 100644 --- a/src/business/business-gnome/dialog-invoice.c +++ b/src/business/business-gnome/dialog-invoice.c @@ -2703,33 +2703,36 @@ gnc_invoice_search (GncInvoice *start, GncOwner *owner, QofBook *book) (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; + + 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); + + /* Don't set a pre-fill query in this case, the result set would be too long */ + q2 = NULL; } } -#if 0 - if (start) - { - if (q2 == NULL) - q2 = qof_query_copy (q); - - qof_query_add_guid_match (q2, g_slist_prepend (NULL, QOF_PARAM_GUID), - gncInvoiceGetGUID (start), QOF_QUERY_AND); - } -#endif - /* Launch select dialog and return the result */ sw = g_new0 (struct _invoice_select_window, 1); diff --git a/src/engine/gncInvoice.c b/src/engine/gncInvoice.c index 5992a7b94f..c21578373b 100644 --- a/src/engine/gncInvoice.c +++ b/src/engine/gncInvoice.c @@ -851,19 +851,25 @@ gnc_numeric gncInvoiceGetTotalOf (GncInvoice *invoice, GncEntryPaymentType type) 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; } } diff --git a/src/engine/gncInvoice.h b/src/engine/gncInvoice.h index de41c56b57..1c336ed2be 100644 --- a/src/engine/gncInvoice.h +++ b/src/engine/gncInvoice.h @@ -137,7 +137,7 @@ GncBillTerm * gncInvoiceGetTerms (const GncInvoice *invoice); 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);