Fix up state-changing business functions

To ensure that they all have a begin/commit and mark the instance
dirty so that the change is immediately written to the DB.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@23167 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
John Ralls 2013-09-13 23:36:36 +00:00
parent 818c00630d
commit 38f1cc6479
7 changed files with 48 additions and 5 deletions

View File

@ -404,6 +404,7 @@ void gncBillTermSetParent (GncBillTerm *term, GncBillTerm *parent)
{ {
gncBillTermMakeInvisible (term); gncBillTermMakeInvisible (term);
} }
mark_term (term);
gncBillTermCommitEdit (term); gncBillTermCommitEdit (term);
} }
@ -412,6 +413,7 @@ void gncBillTermSetChild (GncBillTerm *term, GncBillTerm *child)
if (!term) return; if (!term) return;
gncBillTermBeginEdit (term); gncBillTermBeginEdit (term);
term->child = child; term->child = child;
mark_term (term);
gncBillTermCommitEdit (term); gncBillTermCommitEdit (term);
} }
@ -421,6 +423,7 @@ void gncBillTermIncRef (GncBillTerm *term)
if (term->parent || term->invisible) return; /* children dont need refcounts */ if (term->parent || term->invisible) return; /* children dont need refcounts */
gncBillTermBeginEdit (term); gncBillTermBeginEdit (term);
term->refcount++; term->refcount++;
mark_term (term);
gncBillTermCommitEdit (term); gncBillTermCommitEdit (term);
} }
@ -428,16 +431,20 @@ void gncBillTermDecRef (GncBillTerm *term)
{ {
if (!term) return; if (!term) return;
if (term->parent || term->invisible) return; /* children dont need refcounts */ if (term->parent || term->invisible) return; /* children dont need refcounts */
g_return_if_fail (term->refcount >= 1);
gncBillTermBeginEdit (term); gncBillTermBeginEdit (term);
term->refcount--; term->refcount--;
g_return_if_fail (term->refcount >= 0); mark_term (term);
gncBillTermCommitEdit (term); gncBillTermCommitEdit (term);
} }
void gncBillTermSetRefcount (GncBillTerm *term, gint64 refcount) void gncBillTermSetRefcount (GncBillTerm *term, gint64 refcount)
{ {
if (!term) return; if (!term) return;
gncBillTermBeginEdit (term);
term->refcount = refcount; term->refcount = refcount;
mark_term (term);
gncBillTermCommitEdit (term);
} }
void gncBillTermMakeInvisible (GncBillTerm *term) void gncBillTermMakeInvisible (GncBillTerm *term)
@ -446,6 +453,7 @@ void gncBillTermMakeInvisible (GncBillTerm *term)
gncBillTermBeginEdit (term); gncBillTermBeginEdit (term);
term->invisible = TRUE; term->invisible = TRUE;
remObj (term); remObj (term);
mark_term (term);
gncBillTermCommitEdit (term); gncBillTermCommitEdit (term);
} }
@ -578,6 +586,7 @@ static GncBillTerm *gncBillTermCopy (const GncBillTerm *term)
t->discount = term->discount; t->discount = term->discount;
t->cutoff = term->cutoff; t->cutoff = term->cutoff;
mark_term (t);
gncBillTermCommitEdit(t); gncBillTermCommitEdit(t);
return t; return t;

View File

@ -550,6 +550,7 @@ qofEmployeeSetAddr (GncEmployee *employee, QofInstance *addr_ent)
} }
gncEmployeeBeginEdit(employee); gncEmployeeBeginEdit(employee);
employee->addr = addr; employee->addr = addr;
mark_employee (employee);
gncEmployeeCommitEdit(employee); gncEmployeeCommitEdit(employee);
} }

View File

@ -844,6 +844,7 @@ void gncEntryCopy (const GncEntry *src, GncEntry *dest, gboolean add_entry)
} }
dest->values_dirty = TRUE; dest->values_dirty = TRUE;
mark_entry (dest);
gncEntryCommitEdit (dest); gncEntryCommitEdit (dest);
} }
@ -1330,6 +1331,7 @@ gncEntryRecomputeValues (GncEntry *entry)
/* Determine the commodity denominator */ /* Determine the commodity denominator */
denom = get_entry_commodity_denom (entry); denom = get_entry_commodity_denom (entry);
gncEntryBeginEdit (entry);
/* Compute the invoice values */ /* Compute the invoice values */
gncEntryComputeValue (entry->quantity, entry->i_price, gncEntryComputeValue (entry->quantity, entry->i_price,
(entry->i_taxable ? entry->i_tax_table : NULL), (entry->i_taxable ? entry->i_tax_table : NULL),
@ -1362,6 +1364,8 @@ gncEntryRecomputeValues (GncEntry *entry)
entry->b_tax_value_rounded = gnc_numeric_convert (entry->b_tax_value, denom, entry->b_tax_value_rounded = gnc_numeric_convert (entry->b_tax_value, denom,
GNC_HOW_RND_ROUND_HALF_UP); GNC_HOW_RND_ROUND_HALF_UP);
entry->values_dirty = FALSE; entry->values_dirty = FALSE;
mark_entry (entry);
gncEntryCommitEdit (entry);
} }
/* The "Int" functions below are for internal use only. /* The "Int" functions below are for internal use only.

View File

@ -380,7 +380,7 @@ GncInvoice *gncInvoiceCopy (const GncInvoice *from)
// Posted-date and the posted Txn is intentionally not copied; the // Posted-date and the posted Txn is intentionally not copied; the
// copy isn't "posted" but needs to be posted by the user. // copy isn't "posted" but needs to be posted by the user.
mark_invoice (invoice);
gncInvoiceCommitEdit(invoice); gncInvoiceCommitEdit(invoice);
return invoice; return invoice;
@ -621,27 +621,33 @@ void gncInvoiceAddEntry (GncInvoice *invoice, GncEntry *entry)
if (old == invoice) return; /* I already own this one */ if (old == invoice) return; /* I already own this one */
if (old) gncInvoiceRemoveEntry (old, entry); if (old) gncInvoiceRemoveEntry (old, entry);
gncInvoiceBeginEdit (invoice);
gncEntrySetInvoice (entry, invoice); gncEntrySetInvoice (entry, invoice);
invoice->entries = g_list_insert_sorted (invoice->entries, entry, invoice->entries = g_list_insert_sorted (invoice->entries, entry,
(GCompareFunc)gncEntryCompare); (GCompareFunc)gncEntryCompare);
mark_invoice (invoice); mark_invoice (invoice);
gncInvoiceCommitEdit (invoice);
} }
void gncInvoiceRemoveEntry (GncInvoice *invoice, GncEntry *entry) void gncInvoiceRemoveEntry (GncInvoice *invoice, GncEntry *entry)
{ {
if (!invoice || !entry) return; if (!invoice || !entry) return;
gncInvoiceBeginEdit (invoice);
gncEntrySetInvoice (entry, NULL); gncEntrySetInvoice (entry, NULL);
invoice->entries = g_list_remove (invoice->entries, entry); invoice->entries = g_list_remove (invoice->entries, entry);
mark_invoice (invoice); mark_invoice (invoice);
gncInvoiceCommitEdit (invoice);
} }
void gncInvoiceAddPrice (GncInvoice *invoice, GNCPrice *price) void gncInvoiceAddPrice (GncInvoice *invoice, GNCPrice *price)
{ {
if (!invoice || !price) return; if (!invoice || !price) return;
gncInvoiceBeginEdit (invoice);
invoice->prices = g_list_prepend(invoice->prices, price); invoice->prices = g_list_prepend(invoice->prices, price);
mark_invoice (invoice); mark_invoice (invoice);
gncInvoiceCommitEdit (invoice);
} }
void gncBillAddEntry (GncInvoice *bill, GncEntry *entry) void gncBillAddEntry (GncInvoice *bill, GncEntry *entry)
@ -656,19 +662,23 @@ void gncBillAddEntry (GncInvoice *bill, GncEntry *entry)
if (old == bill) return; /* I already own this one */ if (old == bill) return; /* I already own this one */
if (old) gncBillRemoveEntry (old, entry); if (old) gncBillRemoveEntry (old, entry);
gncInvoiceBeginEdit (bill);
gncEntrySetBill (entry, bill); gncEntrySetBill (entry, bill);
bill->entries = g_list_insert_sorted (bill->entries, entry, bill->entries = g_list_insert_sorted (bill->entries, entry,
(GCompareFunc)gncEntryCompare); (GCompareFunc)gncEntryCompare);
mark_invoice (bill); mark_invoice (bill);
gncInvoiceCommitEdit (bill);
} }
void gncBillRemoveEntry (GncInvoice *bill, GncEntry *entry) void gncBillRemoveEntry (GncInvoice *bill, GncEntry *entry)
{ {
if (!bill || !entry) return; if (!bill || !entry) return;
gncInvoiceBeginEdit (bill);
gncEntrySetBill (entry, NULL); gncEntrySetBill (entry, NULL);
bill->entries = g_list_remove (bill->entries, entry); bill->entries = g_list_remove (bill->entries, entry);
mark_invoice (bill); mark_invoice (bill);
gncInvoiceCommitEdit (bill);
} }
void gncInvoiceSortEntries (GncInvoice *invoice) void gncInvoiceSortEntries (GncInvoice *invoice)
@ -676,7 +686,9 @@ void gncInvoiceSortEntries (GncInvoice *invoice)
if (!invoice) return; if (!invoice) return;
invoice->entries = g_list_sort(invoice->entries, invoice->entries = g_list_sort(invoice->entries,
(GCompareFunc)gncEntryCompare); (GCompareFunc)gncEntryCompare);
gncInvoiceBeginEdit (invoice);
mark_invoice(invoice); mark_invoice(invoice);
gncInvoiceCommitEdit (invoice);
} }
/* ================================================================== */ /* ================================================================== */
@ -1488,6 +1500,10 @@ Transaction * gncInvoicePostToAccount (GncInvoice *invoice, Account *acc,
gncAccountValueDestroy (splitinfo); gncAccountValueDestroy (splitinfo);
gnc_lot_commit_edit (lot); gnc_lot_commit_edit (lot);
/* Not strictly necessary, since it was done by the Set calls
* above, but good insurance. */
DEBUG("Committing Invoice %s", invoice->id);
mark_invoice (invoice);
gncInvoiceCommitEdit (invoice); gncInvoiceCommitEdit (invoice);
/* If requested, attempt to automatically apply open payments /* If requested, attempt to automatically apply open payments

View File

@ -338,10 +338,11 @@ qofJobSetOwner (GncJob *job, QofInstance *ent)
{ {
return; return;
} }
qof_begin_edit(&job->inst);
gncJobBeginEdit (job);
qofOwnerSetEntity(&job->owner, ent); qofOwnerSetEntity(&job->owner, ent);
mark_job (job); mark_job (job);
qof_commit_edit(&job->inst); gncJobCommitEdit (job);
} }
void gncJobBeginEdit (GncJob *job) void gncJobBeginEdit (GncJob *job)

View File

@ -399,21 +399,25 @@ void gncOrderAddEntry (GncOrder *order, GncEntry *entry)
if (old == order) return; /* I already own it */ if (old == order) return; /* I already own it */
if (old) gncOrderRemoveEntry (old, entry); if (old) gncOrderRemoveEntry (old, entry);
gncOrderBeginEdit (order);
order->entries = g_list_insert_sorted (order->entries, entry, order->entries = g_list_insert_sorted (order->entries, entry,
(GCompareFunc)gncEntryCompare); (GCompareFunc)gncEntryCompare);
/* This will send out an event -- make sure we're attached */ /* This will send out an event -- make sure we're attached */
gncEntrySetOrder (entry, order); gncEntrySetOrder (entry, order);
mark_order (order); mark_order (order);
gncOrderCommitEdit (order);
} }
void gncOrderRemoveEntry (GncOrder *order, GncEntry *entry) void gncOrderRemoveEntry (GncOrder *order, GncEntry *entry)
{ {
if (!order || !entry) return; if (!order || !entry) return;
gncOrderBeginEdit (order);
gncEntrySetOrder (entry, NULL); gncEntrySetOrder (entry, NULL);
order->entries = g_list_remove (order->entries, entry); order->entries = g_list_remove (order->entries, entry);
mark_order (order); mark_order (order);
gncOrderCommitEdit (order);
} }
/* Get Functions */ /* Get Functions */

View File

@ -499,6 +499,7 @@ void gncTaxTableSetParent (GncTaxTable *table, GncTaxTable *parent)
gncTaxTableAddChild(parent, table); gncTaxTableAddChild(parent, table);
table->refcount = 0; table->refcount = 0;
gncTaxTableMakeInvisible (table); gncTaxTableMakeInvisible (table);
mark_table (table);
gncTaxTableCommitEdit (table); gncTaxTableCommitEdit (table);
} }
@ -507,6 +508,7 @@ void gncTaxTableSetChild (GncTaxTable *table, GncTaxTable *child)
if (!table) return; if (!table) return;
gncTaxTableBeginEdit (table); gncTaxTableBeginEdit (table);
table->child = child; table->child = child;
mark_table (table);
gncTaxTableCommitEdit (table); gncTaxTableCommitEdit (table);
} }
@ -516,6 +518,7 @@ void gncTaxTableIncRef (GncTaxTable *table)
if (table->parent || table->invisible) return; /* children dont need refcounts */ if (table->parent || table->invisible) return; /* children dont need refcounts */
gncTaxTableBeginEdit (table); gncTaxTableBeginEdit (table);
table->refcount++; table->refcount++;
mark_table (table);
gncTaxTableCommitEdit (table); gncTaxTableCommitEdit (table);
} }
@ -523,16 +526,21 @@ void gncTaxTableDecRef (GncTaxTable *table)
{ {
if (!table) return; if (!table) return;
if (table->parent || table->invisible) return; /* children dont need refcounts */ if (table->parent || table->invisible) return; /* children dont need refcounts */
g_return_if_fail (table->refcount > 0);
gncTaxTableBeginEdit (table); gncTaxTableBeginEdit (table);
table->refcount--; table->refcount--;
g_return_if_fail (table->refcount >= 0); mark_table (table);
gncTaxTableCommitEdit (table); gncTaxTableCommitEdit (table);
} }
void gncTaxTableSetRefcount (GncTaxTable *table, gint64 refcount) void gncTaxTableSetRefcount (GncTaxTable *table, gint64 refcount)
{ {
if (!table) return; if (!table) return;
g_return_if_fail (refcount >= 0);
gncTaxTableBeginEdit (table);
table->refcount = refcount; table->refcount = refcount;
mark_table (table);
gncTaxTableCommitEdit (table);
} }
void gncTaxTableMakeInvisible (GncTaxTable *table) void gncTaxTableMakeInvisible (GncTaxTable *table)