From a436587841e3dc924e91cc731b03db4786bfd105 Mon Sep 17 00:00:00 2001 From: Derek Atkins Date: Tue, 17 Jun 2003 21:38:41 +0000 Subject: [PATCH] * src/business/business-core/gncBillTerm.c: fix gncBillTermCopy() so it PROPERLY copies the bill term. Oops! * src/business/business-core/file/gnc-tax-table-xml-v2.c: when rebuilding the refcount, make sure we fix the grandparent problems first so we refcount the correct object. * src/business/business-core/file/gnc-bill-term-xml-v2.c: when rebuilding the refcount, make sure we fix the grandparent problems first so we refcount the correct object. Also cope with the broken gncBillTermCopy() and hope that the existing parent is correct. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@8638 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 11 ++++++ .../business-core/file/gnc-bill-term-xml-v2.c | 38 +++++++++++++++---- .../business-core/file/gnc-tax-table-xml-v2.c | 18 ++++++--- src/business/business-core/gncBillTerm.c | 11 ++++++ 4 files changed, 65 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0c7432fe6a..33e8215fb3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,17 @@ It does not need to be part of the enum (it's not even used anywhere) * src/engine/QueryCore.h: gint32 prints as a "%d", not a "%ld". + * src/business/business-core/gncBillTerm.c: fix gncBillTermCopy() + so it PROPERLY copies the bill term. Oops! + * src/business/business-core/file/gnc-tax-table-xml-v2.c: + when rebuilding the refcount, make sure we fix the grandparent + problems first so we refcount the correct object. + * src/business/business-core/file/gnc-bill-term-xml-v2.c: + when rebuilding the refcount, make sure we fix the grandparent + problems first so we refcount the correct object. Also cope + with the broken gncBillTermCopy() and hope that the existing + parent is correct. + 2003-06-16 David Hampton * src/gnome/window-register.c: Register with the component manager diff --git a/src/business/business-core/file/gnc-bill-term-xml-v2.c b/src/business/business-core/file/gnc-bill-term-xml-v2.c index 19fc2d8b70..56ae961e65 100644 --- a/src/business/business-core/file/gnc-bill-term-xml-v2.c +++ b/src/business/business-core/file/gnc-bill-term-xml-v2.c @@ -429,9 +429,9 @@ dom_tree_to_billterm (xmlNodePtr node, GNCBook *book) successful = dom_tree_generic_parse (node, billterm_handlers_v2, &billterm_pdata); - if (successful) + if (successful) { gncBillTermCommitEdit (billterm_pdata.term); - else { + } else { PERR ("failed to parse billing term tree"); gncBillTermDestroy (billterm_pdata.term); billterm_pdata.term = NULL; @@ -565,8 +565,29 @@ billterm_scrub_cb (gpointer term_p, gpointer list_p) GncBillTerm *term = term_p; GList **list = list_p; - if (billterm_is_grandchild(term) || gncBillTermGetType(term) == 0) + if (billterm_is_grandchild(term)) { *list = g_list_prepend(*list, term); + + } else if (!gncBillTermGetType(term)) { + GncBillTerm *t = gncBillTermGetParent(term); + if (t) { + /* Fix up the broken "copy" function */ + PWARN("Fixing broken child billterm: %s", + guid_to_string(gncBillTermGetGUID(term))); + + gncBillTermBeginEdit(term); + gncBillTermSetType(term, gncBillTermGetType(t)); + gncBillTermSetDueDays (term, gncBillTermGetDueDays(t)); + gncBillTermSetDiscountDays (term, gncBillTermGetDiscountDays(t)); + gncBillTermSetDiscount (term, gncBillTermGetDiscount(t)); + gncBillTermSetCutoff (term, gncBillTermGetCutoff(t)); + gncBillTermCommitEdit(term); + + } else { + /* No parent? Must be a standalone */ + *list = g_list_prepend(*list, term); + } + } } /* for each invoice, check the bill terms. If the bill terms are @@ -582,16 +603,19 @@ billterm_scrub_invoices (gpointer invoice_p, gpointer ht_p) term = gncInvoiceGetTerms(invoice); if (term) { - count = GPOINTER_TO_INT(g_hash_table_lookup(ht, term)); - count++; - g_hash_table_insert(ht, term, GINT_TO_POINTER(count)); if (billterm_is_grandchild(term)) { - PINFO("Fixing i-billterm on invoice %s\n", + PWARN("Fixing i-billterm on invoice %s\n", guid_to_string(gncInvoiceGetGUID(invoice))); new_bt = billterm_find_senior(term); gncInvoiceBeginEdit(invoice); gncInvoiceSetTerms(invoice, new_bt); gncInvoiceCommitEdit(invoice); + term = new_bt; + } + if (term) { + count = GPOINTER_TO_INT(g_hash_table_lookup(ht, term)); + count++; + g_hash_table_insert(ht, term, GINT_TO_POINTER(count)); } } } diff --git a/src/business/business-core/file/gnc-tax-table-xml-v2.c b/src/business/business-core/file/gnc-tax-table-xml-v2.c index 984d37d61d..d4f5e8a8ba 100644 --- a/src/business/business-core/file/gnc-tax-table-xml-v2.c +++ b/src/business/business-core/file/gnc-tax-table-xml-v2.c @@ -536,9 +536,6 @@ taxtable_scrub_entries (gpointer entry_p, gpointer ht_p) table = gncEntryGetInvTaxTable(entry); if (table) { - count = GPOINTER_TO_INT(g_hash_table_lookup(ht, table)); - count++; - g_hash_table_insert(ht, table, GINT_TO_POINTER(count)); if (taxtable_is_grandchild(table)) { PINFO("Fixing i-taxtable on entry %s\n", guid_to_string(gncEntryGetGUID(entry))); @@ -546,14 +543,17 @@ taxtable_scrub_entries (gpointer entry_p, gpointer ht_p) gncEntryBeginEdit(entry); gncEntrySetInvTaxTable(entry, new_tt); gncEntryCommitEdit(entry); + table = new_tt; + } + if (table) { + count = GPOINTER_TO_INT(g_hash_table_lookup(ht, table)); + count++; + g_hash_table_insert(ht, table, GINT_TO_POINTER(count)); } } table = gncEntryGetBillTaxTable(entry); if (table) { - count = GPOINTER_TO_INT(g_hash_table_lookup(ht, table)); - count++; - g_hash_table_insert(ht, table, GINT_TO_POINTER(count)); if (taxtable_is_grandchild(table)) { PINFO("Fixing b-taxtable on entry %s\n", guid_to_string(gncEntryGetGUID(entry))); @@ -561,6 +561,12 @@ taxtable_scrub_entries (gpointer entry_p, gpointer ht_p) gncEntryBeginEdit(entry); gncEntrySetBillTaxTable(entry, new_tt); gncEntryCommitEdit(entry); + table = new_tt; + } + if (table) { + count = GPOINTER_TO_INT(g_hash_table_lookup(ht, table)); + count++; + g_hash_table_insert(ht, table, GINT_TO_POINTER(count)); } } } diff --git a/src/business/business-core/gncBillTerm.c b/src/business/business-core/gncBillTerm.c index 7c11a367f0..a9c77c7828 100644 --- a/src/business/business-core/gncBillTerm.c +++ b/src/business/business-core/gncBillTerm.c @@ -409,9 +409,20 @@ static GncBillTerm *gncBillTermCopy (GncBillTerm *term) if (!term) return NULL; t = gncBillTermCreate (term->book); + + gncBillTermBeginEdit(t); + gncBillTermSetName (t, term->name); gncBillTermSetDescription (t, term->desc); + t->type = term->type; + t->due_days = term->due_days; + t->disc_days = term->disc_days; + t->discount = term->discount; + t->cutoff = term->cutoff; + + gncBillTermCommitEdit(t); + return t; }