Clear up the billterm data lossage (due to a broken enum definition).

* src/business/business-core/file/gnc-bill-term-xml-v2.c:
	* src/business/business-core/file/gnc-bill-term-xml-v2.h:
	  Add a new API to "find-or-create" a billterm so all the
	  code is collated in one location.
	  Add more debugging during the scrub phases.
	* src/business/business-core/file/gnc-invoice-xml-v2.c:
	* src/business/business-core/file/gnc-vendor-xml-v2.c:
	* src/business/business-core/file/gnc-customer-xml-v2.c:
	  Use the new bill-term find-or-create API
	* src/business/business-core/gncBillTerm.c:
	  add some additional debugging
	* src/business/business-core/gncBillTerm.h:
	  The Billterm Type ENUM must start at 1, not zero.  The data file
	  now appears to properly save itself without destroying data.
	  Fixes rest of #328790.



git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13049 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Derek Atkins 2006-01-30 05:57:08 +00:00
parent 7940c68a7a
commit 8a0f2cf7e3
8 changed files with 64 additions and 29 deletions

View File

@ -1,3 +1,21 @@
2006-01-29 Derek Atkins <derek@ihtfp.com>
* src/business/business-core/file/gnc-bill-term-xml-v2.c:
* src/business/business-core/file/gnc-bill-term-xml-v2.h:
Add a new API to "find-or-create" a billterm so all the
code is collated in one location.
Add more debugging during the scrub phases.
* src/business/business-core/file/gnc-invoice-xml-v2.c:
* src/business/business-core/file/gnc-vendor-xml-v2.c:
* src/business/business-core/file/gnc-customer-xml-v2.c:
Use the new bill-term find-or-create API
* src/business/business-core/gncBillTerm.c:
add some additional debugging
* src/business/business-core/gncBillTerm.h:
The Billterm Type ENUM must start at 1, not zero. The data file
now appears to properly save itself without destroying data.
Fixes rest of #328790.
2006-01-29 David Hampton <hampton@employees.org> 2006-01-29 David Hampton <hampton@employees.org>
* src/gtk-compat.h: * src/gtk-compat.h:

View File

@ -629,6 +629,10 @@ billterm_scrub_cust (QofEntity * cust_p, gpointer ht_p)
count = GPOINTER_TO_INT(g_hash_table_lookup(ht, term)); count = GPOINTER_TO_INT(g_hash_table_lookup(ht, term));
count++; count++;
g_hash_table_insert(ht, term, GINT_TO_POINTER(count)); g_hash_table_insert(ht, term, GINT_TO_POINTER(count));
if (billterm_is_grandchild(term))
PWARN("customer %s has grandchild billterm %s\n",
guid_to_string(qof_instance_get_guid(QOF_INSTANCE(cust))),
guid_to_string(qof_instance_get_guid(QOF_INSTANCE(term))));
} }
} }
@ -645,6 +649,10 @@ billterm_scrub_vendor (QofEntity * vendor_p, gpointer ht_p)
count = GPOINTER_TO_INT(g_hash_table_lookup(ht, term)); count = GPOINTER_TO_INT(g_hash_table_lookup(ht, term));
count++; count++;
g_hash_table_insert(ht, term, GINT_TO_POINTER(count)); g_hash_table_insert(ht, term, GINT_TO_POINTER(count));
if (billterm_is_grandchild(term))
PWARN("vendor %s has grandchild billterm %s\n",
guid_to_string(qof_instance_get_guid(QOF_INSTANCE(vendor))),
guid_to_string(qof_instance_get_guid(QOF_INSTANCE(term))));
} }
} }
@ -670,6 +678,7 @@ billterm_scrub (QofBook *book)
GncBillTerm *parent, *term; GncBillTerm *parent, *term;
GHashTable *ht = g_hash_table_new(g_direct_hash, g_direct_equal); GHashTable *ht = g_hash_table_new(g_direct_hash, g_direct_equal);
PDEBUG("scrubbing billterms...");
qof_object_foreach (GNC_ID_INVOICE, book, billterm_scrub_invoices, ht); qof_object_foreach (GNC_ID_INVOICE, book, billterm_scrub_invoices, ht);
qof_object_foreach (GNC_ID_CUSTOMER, book, billterm_scrub_cust, ht); qof_object_foreach (GNC_ID_CUSTOMER, book, billterm_scrub_cust, ht);
qof_object_foreach (GNC_ID_VENDOR, book, billterm_scrub_vendor, ht); qof_object_foreach (GNC_ID_VENDOR, book, billterm_scrub_vendor, ht);
@ -679,7 +688,7 @@ billterm_scrub (QofBook *book)
for (node = list; node; node = node->next) { for (node = list; node; node = node->next) {
term = node->data; term = node->data;
PINFO ("deleting grandchild billterm: %s\n", PWARN ("deleting grandchild billterm: %s\n",
guid_to_string(qof_instance_get_guid(QOF_INSTANCE(term)))); guid_to_string(qof_instance_get_guid(QOF_INSTANCE(term))));
/* Make sure the parent has no children */ /* Make sure the parent has no children */
@ -725,3 +734,24 @@ gnc_billterm_xml_initialize (void)
GNC_FILE_BACKEND, GNC_FILE_BACKEND,
&be_data); &be_data);
} }
GncBillTerm *
gnc_billterm_xml_find_or_create(QofBook *book, GUID *guid)
{
GncBillTerm *term;
g_return_val_if_fail(book, NULL);
g_return_val_if_fail(guid, NULL);
term = gncBillTermLookup(book, guid);
PDEBUG("looking for billterm %s, found %p", guid_to_string(guid), term);
if (!term) {
term = gncBillTermCreate(book);
gncBillTermBeginEdit(term);
gncBillTermSetGUID(term, guid);
gncBillTermCommitEdit(term);
PDEBUG("Created term: %p", term);
} else
gncBillTermDecRef(term);
return term;
}

View File

@ -24,6 +24,8 @@
#ifndef GNC_BILLTERM_XML_V2_H #ifndef GNC_BILLTERM_XML_V2_H
#define GNC_BILLTERM_XML_V2_H #define GNC_BILLTERM_XML_V2_H
#include "gncBillTerm.h"
void gnc_billterm_xml_initialize (void); void gnc_billterm_xml_initialize (void);
GncBillTerm *gnc_billterm_xml_find_or_create(QofBook *book, GUID *guid);
#endif /* GNC_BILLTERM_XML_V2_H */ #endif /* GNC_BILLTERM_XML_V2_H */

View File

@ -46,6 +46,7 @@
#include "gncTaxTableP.h" #include "gncTaxTableP.h"
#include "gnc-customer-xml-v2.h" #include "gnc-customer-xml-v2.h"
#include "gnc-address-xml-v2.h" #include "gnc-address-xml-v2.h"
#include "gnc-bill-term-xml-v2.h"
#include "xml-helpers.h" #include "xml-helpers.h"
@ -230,15 +231,8 @@ customer_terms_handler (xmlNodePtr node, gpointer cust_pdata)
guid = dom_tree_to_guid(node); guid = dom_tree_to_guid(node);
g_return_val_if_fail (guid, FALSE); g_return_val_if_fail (guid, FALSE);
term = gncBillTermLookup (pdata->book, guid); term = gnc_billterm_xml_find_or_create(pdata->book, guid);
if (!term) { g_assert(term);
term = gncBillTermCreate (pdata->book);
gncBillTermBeginEdit (term);
gncBillTermSetGUID (term, guid);
gncBillTermCommitEdit (term);
} else
gncBillTermDecRef (term);
g_free (guid); g_free (guid);
gncCustomerSetTerms (pdata->customer, term); gncCustomerSetTerms (pdata->customer, term);

View File

@ -45,6 +45,7 @@
#include "gncInvoiceP.h" #include "gncInvoiceP.h"
#include "gnc-invoice-xml-v2.h" #include "gnc-invoice-xml-v2.h"
#include "gnc-owner-xml-v2.h" #include "gnc-owner-xml-v2.h"
#include "gnc-bill-term-xml-v2.h"
#define _GNC_MOD_NAME GNC_ID_INVOICE #define _GNC_MOD_NAME GNC_ID_INVOICE
@ -290,15 +291,8 @@ invoice_terms_handler (xmlNodePtr node, gpointer invoice_pdata)
guid = dom_tree_to_guid(node); guid = dom_tree_to_guid(node);
g_return_val_if_fail (guid, FALSE); g_return_val_if_fail (guid, FALSE);
term = gncBillTermLookup (pdata->book, guid); term = gnc_billterm_xml_find_or_create(pdata->book, guid);
if (!term) { g_assert(term);
term = gncBillTermCreate (pdata->book);
gncBillTermBeginEdit (term);
gncBillTermSetGUID (term, guid);
gncBillTermCommitEdit (term);
} else
gncBillTermDecRef (term);
g_free (guid); g_free (guid);
gncInvoiceSetTerms (pdata->invoice, term); gncInvoiceSetTerms (pdata->invoice, term);

View File

@ -47,6 +47,7 @@
#include "gnc-vendor-xml-v2.h" #include "gnc-vendor-xml-v2.h"
#include "gnc-address-xml-v2.h" #include "gnc-address-xml-v2.h"
#include "xml-helpers.h" #include "xml-helpers.h"
#include "gnc-bill-term-xml-v2.h"
#define _GNC_MOD_NAME GNC_ID_VENDOR #define _GNC_MOD_NAME GNC_ID_VENDOR
@ -212,15 +213,8 @@ vendor_terms_handler (xmlNodePtr node, gpointer vendor_pdata)
guid = dom_tree_to_guid(node); guid = dom_tree_to_guid(node);
g_return_val_if_fail (guid, FALSE); g_return_val_if_fail (guid, FALSE);
term = gncBillTermLookup (pdata->book, guid); term = gnc_billterm_xml_find_or_create(pdata->book, guid);
if (!term) { g_assert(term);
term = gncBillTermCreate (pdata->book);
gncBillTermBeginEdit (term);
gncBillTermSetGUID (term, guid);
gncBillTermCommitEdit (term);
} else
gncBillTermDecRef (term);
g_free (guid); g_free (guid);
gncVendorSetTerms (pdata->vendor, term); gncVendorSetTerms (pdata->vendor, term);

View File

@ -148,6 +148,8 @@ GncBillTerm * gncBillTermCreate (QofBook *book)
void gncBillTermDestroy (GncBillTerm *term) void gncBillTermDestroy (GncBillTerm *term)
{ {
if (!term) return; if (!term) return;
PDEBUG("destroying bill term %s (%p)",
guid_to_string(qof_instance_get_guid(&term->inst)), term);
term->inst.do_free = TRUE; term->inst.do_free = TRUE;
qof_collection_mark_dirty (term->inst.entity.collection); qof_collection_mark_dirty (term->inst.entity.collection);
gncBillTermCommitEdit (term); gncBillTermCommitEdit (term);

View File

@ -57,9 +57,10 @@ typedef struct _gncBillTerm GncBillTerm;
* How to interpret the amount. * How to interpret the amount.
* You can interpret it as a VALUE or a PERCENT. * You can interpret it as a VALUE or a PERCENT.
* ??? huh? * ??? huh?
* NOTE: This enum /depends/ on starting at value 1
*/ */
#define ENUM_TERMS_TYPE(_) \ #define ENUM_TERMS_TYPE(_) \
_(GNC_TERM_TYPE_DAYS,) \ _(GNC_TERM_TYPE_DAYS,=1) \
_(GNC_TERM_TYPE_PROXIMO,) _(GNC_TERM_TYPE_PROXIMO,)
DEFINE_ENUM(GncBillTermType, ENUM_TERMS_TYPE) DEFINE_ENUM(GncBillTermType, ENUM_TERMS_TYPE)