r19998 - gnucash/trunk/src/business/business-ledger - Fully implement auto-completion in the invoice entries on the description field, separately for bills or invoices.

Christian Stimming cstim at code.gnucash.org
Thu Dec 30 06:02:13 EST 2010


Author: cstim
Date: 2010-12-30 06:02:13 -0500 (Thu, 30 Dec 2010)
New Revision: 19998
Trac: http://svn.gnucash.org/trac/changeset/19998

Modified:
   gnucash/trunk/src/business/business-ledger/gncEntryLedgerControl.c
   gnucash/trunk/src/business/business-ledger/gncEntryLedgerLoad.c
Log:
Fully implement auto-completion in the invoice entries on the description field, separately for bills or invoices.

The quickfill is obtained from the global cache of the GncEntry's
descriptions, one for invoices, one for the rest.
The auto-completion is a simple query to get the newest entry with the
same description, but limited to invoices or bills, respectively.

Modified: gnucash/trunk/src/business/business-ledger/gncEntryLedgerControl.c
===================================================================
--- gnucash/trunk/src/business/business-ledger/gncEntryLedgerControl.c	2010-12-30 11:00:27 UTC (rev 19997)
+++ gnucash/trunk/src/business/business-ledger/gncEntryLedgerControl.c	2010-12-30 11:02:13 UTC (rev 19998)
@@ -245,12 +245,13 @@
  * description string equal to the given "desc" argument. The query
  * will find the single GncEntry with the latest (=newest)
  * DATE_ENTERED. */
-static QofQuery *new_query_for_entry_desc(GncEntryLedger *reg, const char* desc)
+static QofQuery *new_query_for_entry_desc(GncEntryLedger *reg, const char* desc, gboolean use_invoice)
 {
     QofQuery *query = NULL;
     QofQueryPredData *predData = NULL;
     GSList *param_list = NULL;
     GSList *primary_sort_params = NULL;
+    const char* should_be_null = (use_invoice ? ENTRY_BILL : ENTRY_INVOICE);
 
     g_assert(reg);
     g_assert(desc);
@@ -271,6 +272,12 @@
     /* Register this in the query */
     qof_query_add_term (query, param_list, predData, QOF_QUERY_FIRST_TERM);
 
+    /* For invoice entries, Entry->Bill must be NULL, and vice versa */
+    qof_query_add_guid_match (query,
+                              qof_query_build_param_list (should_be_null,
+                                                          QOF_PARAM_GUID, NULL),
+                              NULL, QOF_QUERY_AND);
+
     /* Set the sort order: By DATE_ENTERED, increasing, and returning
      * only one single resulting item. */
     primary_sort_params = qof_query_build_param_list(ENTRY_DATE_ENTERED, NULL);
@@ -288,9 +295,23 @@
 find_entry_in_book_by_desc(GncEntryLedger *reg, const char* desc)
 {
     GncEntry *result = NULL;
-    QofQuery *query = new_query_for_entry_desc(reg, desc);
-    GList *entries = qof_query_run(query);
+    gboolean use_invoice;
+    QofQuery *query;
+    GList *entries = NULL;
 
+    switch (reg->type)
+    {
+    case GNCENTRY_INVOICE_ENTRY:
+    case GNCENTRY_INVOICE_VIEWER:
+        use_invoice = TRUE;
+        break;
+    default:
+        use_invoice = FALSE;
+    };
+
+    query = new_query_for_entry_desc(reg, desc, use_invoice);
+    entries = qof_query_run(query);
+
     /* Do we have a non-empty result? */
     if (entries)
     {
@@ -303,6 +324,7 @@
     return result;
 }
 
+#if 0
 /** Finds the GncEntry with the matching description string as given
  * in "desc", but searches this only in the given entry ledger
  * (i.e. the currently opened ledger window). */
@@ -342,6 +364,7 @@
 
     return NULL;
 }
+#endif
 
 static void set_value_combo_cell(BasicCell *cell, const char *new_value)
 {
@@ -468,12 +491,11 @@
      * the entries from the current invoice/bill, but it would be
      * better to draw this from a larger set of entries. */
     auto_entry =
-#if 0
-        /* Activate this for book-wide auto-completion of the invoice entries */
+        /* Use this for book-wide auto-completion of the invoice entries */
         find_entry_in_book_by_desc(ledger, desc);
-#else
-    gnc_find_entry_in_reg_by_desc(ledger, desc);
-#endif
+/* #else */
+/*     gnc_find_entry_in_reg_by_desc(ledger, desc); */
+/* #endif */
 
     if (auto_entry == NULL)
         return FALSE;

Modified: gnucash/trunk/src/business/business-ledger/gncEntryLedgerLoad.c
===================================================================
--- gnucash/trunk/src/business/business-ledger/gncEntryLedgerLoad.c	2010-12-30 11:00:27 UTC (rev 19997)
+++ gnucash/trunk/src/business/business-ledger/gncEntryLedgerLoad.c	2010-12-30 11:02:13 UTC (rev 19998)
@@ -40,6 +40,8 @@
 #include "gncEntry.h"
 #include "gncEntryLedger.h"
 #include "gncEntryLedgerP.h"
+#include "quickfillcell.h"
+#include "gnome-utils/gnc-entry-quickfill.h"
 
 
 /* XXX: This should go elsewhere */
@@ -269,11 +271,36 @@
     gnc_table_show_range (ledger->table, start_loc, end_loc);
 }
 
+#define DESC_QF_KEY_INVOICES "ENTRY_DESC_CELL_QF_INVOICES"
+#define DESC_QF_KEY_BILLS "ENTRY_DESC_CELL_QF_BILLS"
+
+static void
+load_description_cell (GncEntryLedger *ledger)
+{
+    QuickFill *shared_quickfill;
+    QuickFillCell *cell;
+
+    switch (ledger->type)
+    {
+    case GNCENTRY_INVOICE_ENTRY:
+    case GNCENTRY_INVOICE_VIEWER:
+        shared_quickfill = gnc_get_shared_entry_desc_quickfill(ledger->book, DESC_QF_KEY_INVOICES, TRUE);
+        break;
+    default:
+        shared_quickfill = gnc_get_shared_entry_desc_quickfill(ledger->book, DESC_QF_KEY_BILLS, FALSE);
+    };
+
+    cell = (QuickFillCell *)
+           gnc_table_layout_get_cell (ledger->table->layout, ENTRY_DESC_CELL);
+    gnc_quickfill_cell_use_quickfill_cache (cell, shared_quickfill);
+}
+
 void gnc_entry_ledger_load_xfer_cells (GncEntryLedger *ledger)
 {
     load_xfer_type_cells (ledger);
     load_taxtable_type_cells (ledger);
     load_payment_type_cells (ledger);
+    load_description_cell (ledger);
 }
 
 /* XXX (FIXME): This should be in a config file! */



More information about the gnucash-changes mailing list