r22062 - gnucash/branches/2.4/src - Fix skipping of alternate rows when there is a customer id mis-match and fix
Mike Evans
mikee at code.gnucash.org
Fri Feb 24 07:46:54 EST 2012
Author: mikee
Date: 2012-02-24 07:46:54 -0500 (Fri, 24 Feb 2012)
New Revision: 22062
Trac: http://svn.gnucash.org/trac/changeset/22062
Modified:
gnucash/branches/2.4/src/engine/gncIDSearch.c
gnucash/branches/2.4/src/plugins/bi_import/bi_import.c
gnucash/branches/2.4/src/plugins/bi_import/bi_import.h
gnucash/branches/2.4/src/plugins/bi_import/gui.c
Log:
Fix skipping of alternate rows when there is a customer id mis-match and fix
gtk_entry_set_text errors.
Fix already exists in trunk.
Modified: gnucash/branches/2.4/src/engine/gncIDSearch.c
===================================================================
--- gnucash/branches/2.4/src/engine/gncIDSearch.c 2012-02-24 12:26:18 UTC (rev 22061)
+++ gnucash/branches/2.4/src/engine/gncIDSearch.c 2012-02-24 12:46:54 UTC (rev 22062)
@@ -83,7 +83,7 @@
g_return_val_if_fail (type, NULL);
g_return_val_if_fail (id, NULL);
g_return_val_if_fail (book, NULL);
-
+
// Build the query
q = qof_query_create_for (type);
qof_query_set_book (q, book);
@@ -105,7 +105,8 @@
GncVendor *c = NULL;
qof_query_add_term (q, qof_query_build_param_list("VENDOR_ID"), string_pred_data, QOF_QUERY_AND);
}
-
+
+
// Run the query
result = qof_query_run (q);
@@ -114,15 +115,26 @@
if (result && (len > 0))
{
result = g_list_first (result);
+
while (result)
{
c = result->data;
- if (strcmp(id, gncCustomerGetID(c)) == 0)
+ if (strcmp(type, GNC_CUSTOMER_MODULE_NAME) && strcmp(id, gncCustomerGetID(c)) == 0)
{
// correct id found
object = c;
break;
}
+ else if (strcmp(type, GNC_INVOICE_MODULE_NAME) && strcmp(id, gncInvoiceGetID(c)) == 0)
+ {
+ object = c;
+ break;
+ }
+ else if (strcmp(type, GNC_VENDOR_MODULE_NAME) && strcmp(id, gncVendorGetID(c)) == 0)
+ {
+ object = c;
+ break;
+ }
result = g_list_next (result);
}
}
Modified: gnucash/branches/2.4/src/plugins/bi_import/bi_import.c
===================================================================
--- gnucash/branches/2.4/src/plugins/bi_import/bi_import.c 2012-02-24 12:26:18 UTC (rev 22061)
+++ gnucash/branches/2.4/src/plugins/bi_import/bi_import.c 2012-02-24 12:46:54 UTC (rev 22062)
@@ -230,13 +230,14 @@
//! * if price is unset, delete row
void
gnc_bi_import_fix_bis (GtkListStore * store, guint * fixed, guint * deleted,
- GString * info)
+ GString * info, gchar *type)
{
GtkTreeIter iter;
gboolean valid, row_deleted, row_fixed;
gchar *id, *date_opened, *date_posted, *owner_id, *date, *quantity, *price;
GString *prev_id, *prev_date_opened, *prev_date_posted, *prev_owner_id, *prev_date; // needed to fix multi line invoices
guint dummy;
+ gint row = 1;
// allow the call to this function with only GtkListeStore* specified
if (!fixed)
@@ -276,8 +277,8 @@
gtk_list_store_remove (store, &iter);
row_deleted = TRUE;
g_string_append_printf (info,
- _("ROW DELETED, PRICE_NOT_SET: id=%s\n"),
- id);
+ _("ROW %d DELETED, PRICE_NOT_SET: id=%s\n"),
+ row, id);
}
else if (strlen (quantity) == 0)
{
@@ -285,8 +286,8 @@
// no fix possible -> delete row
gtk_list_store_remove (store, &iter);
row_deleted = TRUE;
- g_string_append_printf (info, _("ROW DELETED, QTY_NOT_SET: id=%s\n"),
- id);
+ g_string_append_printf (info, _("ROW %d DELETED, QTY_NOT_SET: id=%s\n"),
+ row, id);
}
else
{
@@ -299,7 +300,7 @@
gtk_list_store_remove (store, &iter);
row_deleted = TRUE;
g_string_append_printf (info,
- _("ROW DELETED, ID_NOT_SET\n"));
+ _("ROW %d DELETED, ID_NOT_SET\n"),row);
}
else
{
@@ -394,8 +395,8 @@
gtk_list_store_remove (store, &iter);
row_deleted = TRUE;
g_string_append_printf (info,
- _("ROW DELETED, VENDOR_NOT_SET: id=%s\n"),
- id);
+ _("ROW %d DELETED, VENDOR_NOT_SET: id=%s\n"),
+ row, id);
}
else
{
@@ -409,17 +410,34 @@
// remember owner_id
g_string_assign (prev_owner_id, owner_id);
}
- // now check, if customer exists
- if (!gnc_search_vendor_on_id
- (gnc_get_current_book (), prev_owner_id->str))
+ if (g_ascii_strcasecmp (type, "BILL") == 0)
{
- // customer not found => delete row
- gtk_list_store_remove (store, &iter);
- row_deleted = TRUE;
- g_string_append_printf (info,
- _("ROW DELETED, VENDOR_DOES_NOT_EXIST: id=%s\n"),
- id);
+ // BILL: check, if vendor exists
+ if (!gnc_search_vendor_on_id
+ (gnc_get_current_book (), prev_owner_id->str))
+ {
+ // vendor not found => delete row
+ valid = gtk_list_store_remove (store, &iter);
+ row_deleted = TRUE;
+ g_string_append_printf (info,
+ _("ROW %d DELETED, VENDOR_DOES_NOT_EXIST: id=%s\n"),
+ row, id);
+ }
}
+ else if (g_ascii_strcasecmp (type, "INVOICE") == 0)
+ {
+ // INVOICE: check, if customer exists
+ if (!gnc_search_customer_on_id
+ (gnc_get_current_book (), prev_owner_id->str))
+ {
+ // customer not found => delete row
+ valid = gtk_list_store_remove (store, &iter);
+ row_deleted = TRUE;
+ g_string_append_printf (info,
+ _("ROW %d DELETED, CUSTOMER_DOES_NOT_EXIST: id=%s\n"),
+ row, id);
+ }
+ }
// owner_id is valid
}
@@ -443,7 +461,11 @@
}
else if (row_fixed)
(*fixed)++;
+
+ if (!row_deleted)
valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter);
+
+ row++;
}
// deallocate strings
@@ -574,8 +596,10 @@
timespecFromTime_t (&now_timespec, now);
gncInvoiceSetDateOpened (invoice, now_timespec);
}
- gncInvoiceSetBillingID (invoice, biing_id);
- gncInvoiceSetNotes (invoice, notes);
+ //if ((biing_id))
+ gncInvoiceSetBillingID (invoice, biing_id ? biing_id : "");
+ //if ((notes))
+ gncInvoiceSetNotes (invoice, notes ? notes : "");
gncInvoiceSetActive (invoice, TRUE);
//if (g_ascii_strcasecmp(type,"INVOICE"))gncInvoiceSetBillTo( invoice, billto );
(*n_invoices_created)++;
Modified: gnucash/branches/2.4/src/plugins/bi_import/bi_import.h
===================================================================
--- gnucash/branches/2.4/src/plugins/bi_import/bi_import.h 2012-02-24 12:26:18 UTC (rev 22061)
+++ gnucash/branches/2.4/src/plugins/bi_import/bi_import.h 2012-02-24 12:46:54 UTC (rev 22062)
@@ -65,7 +65,7 @@
gnc_bi_import_read_file (const gchar *filename, const gchar *parser_regexp, GtkListStore *store, guint max_rows, bi_import_stats *stats);
void
-gnc_bi_import_fix_bis (GtkListStore *store, guint *fixed, guint *deleted, GString *info);
+gnc_bi_import_fix_bis (GtkListStore *store, guint *fixed, guint *deleted, GString *info, gchar *type);
void
gnc_bi_import_create_bis (GtkListStore *store, QofBook *book, guint *n_invoices_created, guint *n_invoices_updated, gchar *type);
Modified: gnucash/branches/2.4/src/plugins/bi_import/gui.c
===================================================================
--- gnucash/branches/2.4/src/plugins/bi_import/gui.c 2012-02-24 12:26:18 UTC (rev 22061)
+++ gnucash/branches/2.4/src/plugins/bi_import/gui.c 2012-02-24 12:46:54 UTC (rev 22062)
@@ -200,7 +200,7 @@
res = gnc_bi_import_read_file (filename, gui->regexp->str, gui->store, 0, &stats);
if (res == RESULT_OK)
{
- gnc_bi_import_fix_bis (gui->store, &n_fixed, &n_deleted, info);
+ gnc_bi_import_fix_bis (gui->store, &n_fixed, &n_deleted, info, gui->type);
if (info->len > 0)
gnc_info_dialog (gui->dialog, "%s", info->str);
g_string_free( info, TRUE );
@@ -269,7 +269,7 @@
filename = gnc_plugin_bi_import_getFilename();
if (filename)
{
- //printf("Setting filename"); // debug
+ //printf("Setting filename %s\n",filename); // debug
gtk_entry_set_text( GTK_ENTRY(gui->entryFilename), filename );
//printf("Set filename"); // debug
g_free( filename );
More information about the gnucash-changes
mailing list