mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Bug 723644.
Make sure that gnc_search_invoice_on_id() returns the correct type of object.
This commit is contained in:
parent
5706c0083c
commit
40c236b9e0
@ -23,7 +23,16 @@
|
|||||||
|
|
||||||
#include "gncIDSearch.h"
|
#include "gncIDSearch.h"
|
||||||
|
|
||||||
static void * search(QofBook * book, const gchar *id, void * object, QofIdType type);
|
typedef enum
|
||||||
|
{ UNDEFINED,
|
||||||
|
CUSTOMER,
|
||||||
|
VENDOR,
|
||||||
|
INVOICE,
|
||||||
|
BILL
|
||||||
|
}GncSearchType;
|
||||||
|
|
||||||
|
static void * search(QofBook * book, const gchar *id, void * object, GncSearchType type);
|
||||||
|
static QofLogModule log_module = G_LOG_DOMAIN;
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* Search the book for a Customer/Invoice/Bill with the same ID.
|
* Search the book for a Customer/Invoice/Bill with the same ID.
|
||||||
* If it exists return a valid object, if not then returns NULL.
|
* If it exists return a valid object, if not then returns NULL.
|
||||||
@ -31,11 +40,13 @@ static void * search(QofBook * book, const gchar *id, void * object, QofIdType t
|
|||||||
@param gchar ID of the Customer
|
@param gchar ID of the Customer
|
||||||
@return GncCustomer * Pointer to the customer or NULL of there is no customer
|
@return GncCustomer * Pointer to the customer or NULL of there is no customer
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
|
|
||||||
|
|
||||||
GncCustomer *
|
GncCustomer *
|
||||||
gnc_search_customer_on_id (QofBook * book, const gchar *id)
|
gnc_search_customer_on_id (QofBook * book, const gchar *id)
|
||||||
{
|
{
|
||||||
GncCustomer *customer = NULL;
|
GncCustomer *customer = NULL;
|
||||||
QofIdType type = GNC_CUSTOMER_MODULE_NAME;
|
GncSearchType type = CUSTOMER;
|
||||||
customer = (GncCustomer*)search(book, id, customer, type);
|
customer = (GncCustomer*)search(book, id, customer, type);
|
||||||
return customer;
|
return customer;
|
||||||
}
|
}
|
||||||
@ -44,7 +55,7 @@ GncInvoice *
|
|||||||
gnc_search_invoice_on_id (QofBook * book, const gchar *id)
|
gnc_search_invoice_on_id (QofBook * book, const gchar *id)
|
||||||
{
|
{
|
||||||
GncInvoice *invoice = NULL;
|
GncInvoice *invoice = NULL;
|
||||||
QofIdType type = GNC_INVOICE_MODULE_NAME;
|
GncSearchType type = INVOICE;
|
||||||
invoice = (GncInvoice*)search(book, id, invoice, type);
|
invoice = (GncInvoice*)search(book, id, invoice, type);
|
||||||
return invoice;
|
return invoice;
|
||||||
}
|
}
|
||||||
@ -54,7 +65,7 @@ GncInvoice *
|
|||||||
gnc_search_bill_on_id (QofBook * book, const gchar *id)
|
gnc_search_bill_on_id (QofBook * book, const gchar *id)
|
||||||
{
|
{
|
||||||
GncInvoice *bill = NULL;
|
GncInvoice *bill = NULL;
|
||||||
QofIdType type = GNC_INVOICE_MODULE_NAME;
|
GncSearchType type = BILL;
|
||||||
bill = (GncInvoice*)search(book, id, bill, type);
|
bill = (GncInvoice*)search(book, id, bill, type);
|
||||||
return bill;
|
return bill;
|
||||||
}
|
}
|
||||||
@ -63,7 +74,7 @@ GncVendor *
|
|||||||
gnc_search_vendor_on_id (QofBook * book, const gchar *id)
|
gnc_search_vendor_on_id (QofBook * book, const gchar *id)
|
||||||
{
|
{
|
||||||
GncVendor *vendor = NULL;
|
GncVendor *vendor = NULL;
|
||||||
QofIdType type = GNC_VENDOR_MODULE_NAME;
|
GncSearchType type = VENDOR;
|
||||||
vendor = (GncVendor*)search(book, id, vendor, type);
|
vendor = (GncVendor*)search(book, id, vendor, type);
|
||||||
return vendor;
|
return vendor;
|
||||||
}
|
}
|
||||||
@ -73,33 +84,37 @@ gnc_search_vendor_on_id (QofBook * book, const gchar *id)
|
|||||||
* Generic search called after setting up stuff
|
* Generic search called after setting up stuff
|
||||||
* DO NOT call directly but type tests should fail anyway
|
* DO NOT call directly but type tests should fail anyway
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
static void * search(QofBook * book, const gchar *id, void * object, QofIdType type)
|
static void * search(QofBook * book, const gchar *id, void * object, GncSearchType type)
|
||||||
{
|
{
|
||||||
void *c;
|
void *c;
|
||||||
GList *result;
|
GList *result;
|
||||||
QofQuery *q;
|
QofQuery *q;
|
||||||
gint len;
|
gint len;
|
||||||
QofQueryPredData* string_pred_data;
|
QofQueryPredData* string_pred_data;
|
||||||
|
|
||||||
|
PINFO("Type = %d", type);
|
||||||
g_return_val_if_fail (type, NULL);
|
g_return_val_if_fail (type, NULL);
|
||||||
g_return_val_if_fail (id, NULL);
|
g_return_val_if_fail (id, NULL);
|
||||||
g_return_val_if_fail (book, NULL);
|
g_return_val_if_fail (book, NULL);
|
||||||
|
|
||||||
// Build the query
|
// Build the query
|
||||||
q = qof_query_create_for (type);
|
q = qof_query_create ();
|
||||||
qof_query_set_book (q, book);
|
qof_query_set_book (q, book);
|
||||||
// Search only the id field
|
// Search only the id field
|
||||||
string_pred_data = qof_query_string_predicate (QOF_COMPARE_EQUAL, id, QOF_STRING_MATCH_NORMAL, FALSE);
|
string_pred_data = qof_query_string_predicate (QOF_COMPARE_EQUAL, id, QOF_STRING_MATCH_NORMAL, FALSE);
|
||||||
|
if (type == CUSTOMER)
|
||||||
if (strcmp(type, GNC_CUSTOMER_MODULE_NAME))
|
|
||||||
{
|
{
|
||||||
|
qof_query_search_for(q,GNC_CUSTOMER_MODULE_NAME);
|
||||||
qof_query_add_term (q, qof_query_build_param_list("CUSTOMER_ID"), string_pred_data, QOF_QUERY_AND);
|
qof_query_add_term (q, qof_query_build_param_list("CUSTOMER_ID"), string_pred_data, QOF_QUERY_AND);
|
||||||
}
|
}
|
||||||
else if (strcmp(type, GNC_INVOICE_MODULE_NAME))
|
else if (type == INVOICE || type == BILL)
|
||||||
{
|
{
|
||||||
|
qof_query_search_for(q,GNC_INVOICE_MODULE_NAME);
|
||||||
qof_query_add_term (q, qof_query_build_param_list("INVOICE_ID"), string_pred_data, QOF_QUERY_AND);
|
qof_query_add_term (q, qof_query_build_param_list("INVOICE_ID"), string_pred_data, QOF_QUERY_AND);
|
||||||
}
|
}
|
||||||
else if (strcmp(type, GNC_VENDOR_MODULE_NAME))
|
else if (type == VENDOR)
|
||||||
{
|
{
|
||||||
|
qof_query_search_for(q,GNC_VENDOR_MODULE_NAME);
|
||||||
qof_query_add_term (q, qof_query_build_param_list("VENDOR_ID"), string_pred_data, QOF_QUERY_AND);
|
qof_query_add_term (q, qof_query_build_param_list("VENDOR_ID"), string_pred_data, QOF_QUERY_AND);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,18 +131,26 @@ static void * search(QofBook * book, const gchar *id, void * object, QofIdType t
|
|||||||
while (result)
|
while (result)
|
||||||
{
|
{
|
||||||
c = result->data;
|
c = result->data;
|
||||||
if (strcmp(type, GNC_CUSTOMER_MODULE_NAME) && strcmp(id, gncCustomerGetID(c)) == 0)
|
|
||||||
|
if (type == CUSTOMER && strcmp(id, gncCustomerGetID(c)) == 0)
|
||||||
{
|
{
|
||||||
// correct id found
|
// correct id found
|
||||||
object = c;
|
object = c;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (strcmp(type, GNC_INVOICE_MODULE_NAME) && strcmp(id, gncInvoiceGetID(c)) == 0)
|
else if (type == INVOICE && strcmp(id, gncInvoiceGetID(c)) == 0
|
||||||
|
&& gncInvoiceGetType(c) == GNC_INVOICE_CUST_INVOICE)
|
||||||
{
|
{
|
||||||
object = c;
|
object = c;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (strcmp(type, GNC_VENDOR_MODULE_NAME) && strcmp(id, gncVendorGetID(c)) == 0)
|
else if (type == BILL && strcmp(id, gncInvoiceGetID(c)) == 0
|
||||||
|
&& gncInvoiceGetType(c) == GNC_INVOICE_VEND_INVOICE)
|
||||||
|
{
|
||||||
|
object = c;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (type == VENDOR && strcmp(id, gncVendorGetID(c)) == 0)
|
||||||
{
|
{
|
||||||
object = c;
|
object = c;
|
||||||
break;
|
break;
|
||||||
|
@ -354,7 +354,7 @@ void gnc_bi_import_gui_open_mode_cb (GtkWidget *widget, gpointer data)
|
|||||||
|
|
||||||
|
|
||||||
/*****************************************************************
|
/*****************************************************************
|
||||||
* Set whether we are importing a bi, invoice, Customer or Vendor
|
* Set whether we are importing a bill, invoice, Customer or Vendor
|
||||||
* ****************************************************************/
|
* ****************************************************************/
|
||||||
void gnc_import_gui_type_cb (GtkWidget *widget, gpointer data)
|
void gnc_import_gui_type_cb (GtkWidget *widget, gpointer data)
|
||||||
{
|
{
|
||||||
|
@ -78,6 +78,7 @@
|
|||||||
g_free (temp); \
|
g_free (temp); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static QofLogModule log_module = G_LOG_DOMAIN; //G_LOG_BUSINESS;
|
||||||
|
|
||||||
bi_import_result
|
bi_import_result
|
||||||
gnc_bi_import_read_file (const gchar * filename, const gchar * parser_regexp,
|
gnc_bi_import_read_file (const gchar * filename, const gchar * parser_regexp,
|
||||||
@ -564,9 +565,12 @@ gnc_bi_import_create_bis (GtkListStore * store, QofBook * book,
|
|||||||
invoice = gnc_search_bill_on_id (book, id);
|
invoice = gnc_search_bill_on_id (book, id);
|
||||||
else if (g_ascii_strcasecmp (type, "INVOICE") == 0)
|
else if (g_ascii_strcasecmp (type, "INVOICE") == 0)
|
||||||
invoice = gnc_search_invoice_on_id (book, id);
|
invoice = gnc_search_invoice_on_id (book, id);
|
||||||
|
PINFO( "Existing %s ID: %s\n", type, gncInvoiceGetID(invoice));
|
||||||
|
|
||||||
if (!invoice)
|
// If the search is empty then there is no existing invoice so make a new one
|
||||||
|
if (invoice == NULL)
|
||||||
{
|
{
|
||||||
|
PINFO( "Creating a new : %s\n", type );
|
||||||
// new invoice
|
// new invoice
|
||||||
invoice = gncInvoiceCreate (book);
|
invoice = gncInvoiceCreate (book);
|
||||||
/* Protect against thrashing the DB and trying to write the invoice
|
/* Protect against thrashing the DB and trying to write the invoice
|
||||||
@ -686,6 +690,7 @@ gnc_bi_import_create_bis (GtkListStore * store, QofBook * book,
|
|||||||
gncEntrySetQuantity (entry, n);
|
gncEntrySetQuantity (entry, n);
|
||||||
acc = gnc_account_lookup_for_register (gnc_get_current_root_account (),
|
acc = gnc_account_lookup_for_register (gnc_get_current_root_account (),
|
||||||
account);
|
account);
|
||||||
|
|
||||||
if (g_ascii_strcasecmp (type, "BILL") == 0)
|
if (g_ascii_strcasecmp (type, "BILL") == 0)
|
||||||
{
|
{
|
||||||
gncEntrySetBillAccount (entry, acc);
|
gncEntrySetBillAccount (entry, acc);
|
||||||
|
Loading…
Reference in New Issue
Block a user