Index: python-bindings/utils.c
===================================================================
--- src/optional/python-bindings/utils.c	(revision 0)
+++ src/optional/python-bindings/utils.c	(revision 0)
@@ -0,0 +1,179 @@
+/**      utils.c
+*
+*      This program is free software; you can redistribute it and/or modify
+*      it under the terms of the GNU General Public License as published by
+*      the Free Software Foundation; either version 2 of the License, or
+*      (at your option) any later version.
+*
+*      This program is distributed in the hope that it will be useful,
+*      but WITHOUT ANY WARRANTY; without even the implied warranty of
+*      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*      GNU General Public License for more details.
+*
+*      You should have received a copy of the GNU General Public License
+*      along with this program; if not, write to the Free Software
+*      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+*      MA 02110-1301, USA.
+*
+* Developed (aka copied?) from code written by Sebastian Held <sebastian.held@gmx.de>
+* as part of his GnuCash invoice importer module
+* Mike Evans <mikee@saxicola.co.uk>
+*
+**********************************************************************/
+
+#include "utils.h"
+
+
+/***********************************************************************
+ * Search the book for a Customer with the same ID.  If it exists return a
+ * Customer object, if nit then return NULL.
+ @param gchar ID of the Customer
+ @param QofBook	The book
+ @return GncCustomer * Pointer to the customer or NULL of there is no customer
+ *
+ **********************************************************************/
+GncCustomer *
+search_customer_on_id (const gchar *id, QofBook * book)
+{
+	QueryNew *q;
+	GNCIdType type = GNC_CUSTOMER_MODULE_NAME;
+	GList *result; // do not free this!
+	QueryPredData_t string_pred_data;
+	GncCustomer *customer = NULL;
+	gint len;
+
+	g_return_val_if_fail (id, NULL);
+	g_return_val_if_fail (book, NULL);
+
+	// Build the query
+	q = gncQueryCreateFor (type);
+	gncQuerySetBook (q, book);
+
+	// Search only the customer id field
+	string_pred_data = gncQueryStringPredicate (COMPARE_EQUAL, id, STRING_MATCH_NORMAL, FALSE);
+	gncQueryAddTerm (q, gncQueryBuildParamList(CUSTOMER_ID), string_pred_data, QUERY_AND);
+
+	// Run the query
+	result = gncQueryRun (q);
+
+	// now compare _exactly_
+	len = g_list_length (result);
+	if (result && (len>0)) {
+		result = g_list_first (result);
+		while (result) {
+			GncCustomer *c = result->data;
+			if (strcmp(id,gncCustomerGetID(c)) == 0) {
+				// correct id found
+				customer = c;
+				break;
+			}
+			result = g_list_next (result);
+		}
+	}
+
+	gncQueryDestroy (q);
+	return customer;
+}
+
+/***********************************************************************
+ * Search the book for an Invoice with the same ID.  If it exists return an
+ * Invoice object, if not then return NULL.
+ @param gchar ID of the invoice
+ @param QofBook	The book
+ @return GncCustomer * Pointer to the Invoice or NULL of there is no customer
+ *
+ **********************************************************************/
+GncInvoice *
+search_invoice_on_id(const gchar *id, QofBook *book)
+{
+	QueryNew *q;
+	GNCIdType type = GNC_INVOICE_MODULE_NAME;
+	GList *result; // do not free this!
+	QueryPredData_t string_pred_data;
+	GncInvoice *invoice = NULL;
+	gint len;
+
+	g_return_val_if_fail (id, NULL);
+	g_return_val_if_fail (book, NULL);
+
+	// Build the query
+	q = gncQueryCreateFor (type);
+	gncQuerySetBook (q, book);
+
+	// Search only the invoice id field
+	string_pred_data = gncQueryStringPredicate (COMPARE_EQUAL, id, STRING_MATCH_NORMAL, FALSE);
+	gncQueryAddTerm (q, gncQueryBuildParamList(INVOICE_ID), string_pred_data, QUERY_AND);
+
+	// Run the query
+	result = gncQueryRun (q);
+
+	// now compare _exactly_
+	len = g_list_length (result);
+	if (result && (len>0)) {
+		result = g_list_first (result);
+		while (result) {
+			GncInvoice *c = result->data;
+			if (strcmp(id,gncInvoiceGetID(c)) == 0) {
+				// correct id found
+				invoice = c;
+				break;
+			}
+			result = g_list_next (result);
+		}
+	}
+
+	gncQueryDestroy (q);
+	return invoice;
+}
+
+
+/***********************************************************************
+ * Search the book for a Bill with the same ID.  If it exists return an
+ * Invoice object, if not then return NULL.
+ @param gchar ID of the invoice
+ @param QofBook	The book
+ @return GncCustomer * Pointer to the Invoice or NULL of there is no customer
+ *
+ **********************************************************************/
+GncInvoice *
+search_bill_on_id(const gchar *id, QofBook *book)
+{
+	QueryNew *q;
+	GNCIdType type = GNC_INVOICE_MODULE_NAME;
+	GList *result; // do not free this!
+	QueryPredData_t string_pred_data;
+	GncInvoice *bill = NULL;
+	gint len;
+
+	g_return_val_if_fail (id, NULL);
+	g_return_val_if_fail (book, NULL);
+
+	// Build the query
+	q = gncQueryCreateFor (type);
+	gncQuerySetBook (q, book);
+
+	// Search only the invoice id field
+	string_pred_data = gncQueryStringPredicate (COMPARE_EQUAL, id, STRING_MATCH_NORMAL, FALSE);
+	gncQueryAddTerm (q, gncQueryBuildParamList(INVOICE_ID), string_pred_data, QUERY_AND);
+
+	// Run the query
+	result = gncQueryRun (q);
+
+	// now compare _exactly_
+	len = g_list_length (result);
+	if (result && (len>0)) {
+		result = g_list_first (result);
+		while (result) {
+			GncInvoice *c = result->data;
+			if (strcmp(id,gncInvoiceGetID(c)) == 0) {
+				// correct id found
+				bill = c;
+				break;
+			}
+			result = g_list_next (result);
+		}
+	}
+
+	gncQueryDestroy (q);
+	return bill;
+}
Index: python-bindings/utils.h
===================================================================
--- src/optional/python-bindings/utils.h	(revision 0)
+++ src/optional/python-bindings/utils.h	(revision 0)
@@ -0,0 +1,58 @@
+/**      utils.h
+*
+*      This program is free software; you can redistribute it and/or modify
+*      it under the terms of the GNU General Public License as published by
+*      the Free Software Foundation; either version 2 of the License, or
+*      (at your option) any later version.
+*
+*      This program is distributed in the hope that it will be useful,
+*      but WITHOUT ANY WARRANTY; without even the implied warranty of
+*      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*      GNU General Public License for more details.
+*
+*      You should have received a copy of the GNU General Public License
+*      along with this program; if not, write to the Free Software
+*      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+*      MA 02110-1301, USA.
+*
+* Developed from code written by Sebastian Held <sebastian.held@gmx.de>
+* as part of his invoice importer module
+* Mike Evans <mikee@saxicola.co.uk>
+*
+**********************************************************************/
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <glib/gi18n.h>
+#include <regex.h>
+#include <glib.h>
+#include <glib/gstdio.h>
+
+#include "gnc-ui.h"
+#include "gnc-ui-util.h"
+#include "gnome-utils/gnc-gui-query.h"
+#include "gncAddress.h"
+#include "gncCustomerP.h"
+#include "gncCustomer.h"
+#include "gncInvoice.h"
+#include "gnc-exp-parser.h"
+
+// query
+#include "QueryCore.h"
+#include "QueryNew.h"
+#include "GNCId.h"
+
+
+
+#ifndef GNC_PLUGIN_invoice_import_invoice_import_H
+#define GNC_PLUGIN_invoice_import_invoice_import_H
+
+GncCustomer * search_customer_on_id  (const gchar *id, QofBook *book);
+GncInvoice  * search_invoice_on_id   (const gchar *id, QofBook *book);
+GncInvoice  * search_bill_on_id   (const gchar *id, QofBook *book);
+
+#endif
+
Index: python-bindings/gnucash_core.i
===================================================================
--- src/optional/python-bindings/gnucash_core.i	(revision 19377)
+++ src/optional/python-bindings/gnucash_core.i	(working copy)
@@ -51,11 +51,14 @@
 #include "gncVendor.h"
 #include "gncAddress.h"
 #include "gncBillTerm.h"
+
 #include "gncOwner.h"
 #include "gncInvoice.h"
 #include "gncJob.h"
 #include "gncEntry.h"
 #include "gncTaxTable.h"
+#include "utils.h"
+
 %}

 %include <timespec.i>
@@ -174,15 +177,18 @@
 %include <gncJob.h>
 %include <gncEntry.h>
 %include <gncTaxTable.h>
+%include "utils.h"

+
 %init %{
-
 qof_log_init();
 qof_init();
 gnc_module_system_init();
 char * no_args[1] = { NULL };
 gnc_engine_init_static(0, no_args);

+
 gnc_module_init_backend_xml();
 gnc_module_init_backend_dbi();
 %}
+
Index: python-bindings/Makefile.am
===================================================================
--- src/optional/python-bindings/Makefile.am	(revision 19377)
+++ src/optional/python-bindings/Makefile.am	(working copy)
@@ -12,15 +12,22 @@
 pkgpyexec_LTLIBRARIES = _gnucash_core_c.la

 _gnucash_core_c_la_SOURCES = \
-  gnucash_core.c
+  gnucash_core.c utils.c

 _gnucash_core_c_la_CPPFLAGS = \
   $(PYTHON_CPPFLAGS) \
   $(GLIB_CFLAGS) \
+  $(GNOME_CFLAGS) \
   -I${top_srcdir}/src/libqof/qof \
   -I$(top_srcdir)/src  \
   -I$(top_srcdir)/src/engine \
-  -I$(top_srcdir)/src/business/business-core
+  -I$(top_srcdir)/src/business/business-core \
+  -I${top_srcdir}/src/gnome-utils \
+  -I${top_srcdir}/src/app-utils \
+  -I${top_srcdir}/src/gnc-module \
+  -I${top_srcdir}/src/gnome \
+	-I${top_srcdir}/src/core-utils \
+  -I${top_srcdir}/src/gnc-module

 # Suppress all warnings for now, but we really only need to -Wno-implicit
 AM_CFLAGS = -w
@@ -29,20 +36,22 @@

 _gnucash_core_c_la_LIBADD = \
   ${GLIB_LIBS} \
+  ${GNOME_LIBS} \
+  ${GLADE_LIBS} \
   ${top_builddir}/src/libqof/qof/libgnc-qof.la \
   ${top_builddir}/src/gnc-module/libgnc-module.la \
   ${top_builddir}/src/engine/libgncmod-engine.la \
   ${top_builddir}/src/backend/xml/libgncmod-backend-xml.la \
   ${top_builddir}/src/backend/dbi/libgncmod-backend-dbi.la
 if BUILDING_FROM_SVN
-gnucash_core.c: $(SWIG_FILES) ${top_srcdir}/src/base-typemaps.i $(top_builddir)/config.h
+gnucash_core.c: $(SWIG_FILES) ${top_srcdir}/src/base-typemaps.i utils.c $(top_builddir)/config.h
 	swig -python -Wall -Werror \
         -I$(top_srcdir)/src -I$(top_srcdir)/src/engine \
 		-I$(top_srcdir)/src/business/business-core \
         -I${top_srcdir}/src/libqof/qof \
 		-o $@ $<

-gnucash_core_c.py: gnucash_core.c $(SWIG_FILES)
+gnucash_core_c.py: gnucash_core.c utils.c $(SWIG_FILES)
 endif

 EXTRA_DIST = \
@@ -50,7 +59,7 @@
   example_scripts/simple_book.py \
   example_scripts/simple_session.py \
   example_scripts/simple_test.py \
-  example_scripts/simple_business_create.py \
+  xample_scripts/simple_business_create.py \
   example_scripts/simple_invoice_insert.py \
   example_scripts/simple_sqlite_create.py \
   example_scripts/change_tax_code.py \
@@ -59,3 +68,4 @@
   glib.i

 MAINTAINERCLEANFILES = gnucash-core.c
+
