bug fix: call the backend *before* the transaction is deleted.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3550 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 2001-01-29 07:15:20 +00:00
parent 67edb46720
commit e4c67b8bea
2 changed files with 63 additions and 53 deletions

View File

@ -64,13 +64,6 @@
*/
int force_double_entry = 0;
/* bit-field flags for controlling transaction commits */
typedef enum
{
BEGIN_EDIT = 1 << 0,
BEING_DESTROYED = 1 << 1,
} TransFlags;
/* arbitrary price per share increment FIXME */
#define PRICE_DENOM 1000000
@ -968,8 +961,8 @@ xaccSplitsComputeValue (GList *splits, Split * skip_me,
value = gnc_numeric_add_fixed(value, s->damount);
}
else {
PERR ("inconsistent currencies\n");
printf("base = '%s', curr='%s', sec='%s'\n",
PERR ("inconsistent currencies\n"
"\tbase = '%s', curr='%s', sec='%s'\n",
gnc_commodity_get_printname(base_currency),
gnc_commodity_get_printname(currency),
gnc_commodity_get_printname(security));
@ -1171,9 +1164,9 @@ xaccTransSetCurrency (Transaction *trans, const gnc_commodity *curr)
trans->common_currency = curr;
/* The following code will be obsolete when we finally eliminate
* the storage of the currency with the account. But in the meanwhile.
* we will try to keep it in sync, so that both the old and new ways
* work.
* the storage of the reporting currency with the account. But in
* the meanwhile, we will try to keep it in sync, so that both the
* old and new ways work.
*
* This is a cheesy and potentially error-prone algorithm;
* but lets give it a spin and try our luck ...
@ -1255,23 +1248,17 @@ xaccTransCommitEdit (Transaction *trans)
check_open (trans);
/* At this point, we check to see if we have a valid transaction.
* As a result of editing, we could end up with a transaction that
* has no splits in it, in which case we delete the transaction and
* return.
* There are two possiblities:
* 1) Its more or less OK, and needs a little cleanup
* 2) It has zero splits, i.e. is meant to be destroyed.
* We handle 1) immediately, and we call the backend before
* we go through with 2).
*/
if (!trans->splits || (trans->open & BEING_DESTROYED))
if (trans->splits && !(trans->open & BEING_DESTROYED))
{
PINFO ("delete trans at addr=%p", trans);
/* Make a log in the journal before destruction. */
xaccTransWriteLog (trans, 'D');
xaccRemoveEntity(&trans->guid);
xaccFreeTransaction (trans);
return;
}
split = trans->splits->data;
/* try to get the sorting order lined up according to
/* Try to get the sorting order lined up according to
* when the user typed things in. */
if (0 == trans->date_entered.tv_sec) {
struct timeval tv;
@ -1299,6 +1286,7 @@ xaccTransCommitEdit (Transaction *trans)
xaccSplitSetShareAmount(s, gnc_numeric_neg(split->damount));
xaccSplitSetValue(s, gnc_numeric_neg(split->value));
}
}
/* ------------------------------------------------- */
/* OK, at this point, we are done making sure that
@ -1319,11 +1307,26 @@ xaccTransCommitEdit (Transaction *trans)
* at this point, and let the user know that we failed.
*/
/* XXX hack alert -- finish this */
PWARN("Another user has modified the transaction\n"
"Please refresh your browser and try again.\n"
"(This dialog should be a gui dialog and \n"
"should check for errors)\n");
PERR("Backend asked engine to rollback, but we don't "
"handle this case yet. Return code=%d", rc);
}
}
/* ------------------------------------------------- */
if (!trans->splits || (trans->open & BEING_DESTROYED))
{
PINFO ("delete trans at addr=%p", trans);
/* Make a log in the journal before destruction. */
xaccTransWriteLog (trans, 'D');
xaccRemoveEntity(&trans->guid);
xaccFreeTransaction (trans);
return;
}
/* ------------------------------------------------- */
/* Make sure all associated splits are in proper order
* in their accounts. */

View File

@ -54,6 +54,13 @@
#include "Transaction.h" /* for typedefs */
#include "GNCId.h"
/* bit-field flags for controlling transaction commits */
typedef enum
{
BEGIN_EDIT = 1 << 0,
BEING_DESTROYED = 1 << 1,
} TransFlags;
/** STRUCTS *********************************************************/
/*