mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
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:
parent
67edb46720
commit
e4c67b8bea
@ -64,13 +64,6 @@
|
|||||||
*/
|
*/
|
||||||
int force_double_entry = 0;
|
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 */
|
/* arbitrary price per share increment FIXME */
|
||||||
#define PRICE_DENOM 1000000
|
#define PRICE_DENOM 1000000
|
||||||
|
|
||||||
@ -968,8 +961,8 @@ xaccSplitsComputeValue (GList *splits, Split * skip_me,
|
|||||||
value = gnc_numeric_add_fixed(value, s->damount);
|
value = gnc_numeric_add_fixed(value, s->damount);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PERR ("inconsistent currencies\n");
|
PERR ("inconsistent currencies\n"
|
||||||
printf("base = '%s', curr='%s', sec='%s'\n",
|
"\tbase = '%s', curr='%s', sec='%s'\n",
|
||||||
gnc_commodity_get_printname(base_currency),
|
gnc_commodity_get_printname(base_currency),
|
||||||
gnc_commodity_get_printname(currency),
|
gnc_commodity_get_printname(currency),
|
||||||
gnc_commodity_get_printname(security));
|
gnc_commodity_get_printname(security));
|
||||||
@ -1171,9 +1164,9 @@ xaccTransSetCurrency (Transaction *trans, const gnc_commodity *curr)
|
|||||||
trans->common_currency = curr;
|
trans->common_currency = curr;
|
||||||
|
|
||||||
/* The following code will be obsolete when we finally eliminate
|
/* The following code will be obsolete when we finally eliminate
|
||||||
* the storage of the currency with the account. But in the meanwhile.
|
* the storage of the reporting currency with the account. But in
|
||||||
* we will try to keep it in sync, so that both the old and new ways
|
* the meanwhile, we will try to keep it in sync, so that both the
|
||||||
* work.
|
* old and new ways work.
|
||||||
*
|
*
|
||||||
* This is a cheesy and potentially error-prone algorithm;
|
* This is a cheesy and potentially error-prone algorithm;
|
||||||
* but lets give it a spin and try our luck ...
|
* but lets give it a spin and try our luck ...
|
||||||
@ -1255,49 +1248,44 @@ xaccTransCommitEdit (Transaction *trans)
|
|||||||
check_open (trans);
|
check_open (trans);
|
||||||
|
|
||||||
/* At this point, we check to see if we have a valid transaction.
|
/* 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
|
* There are two possiblities:
|
||||||
* has no splits in it, in which case we delete the transaction and
|
* 1) Its more or less OK, and needs a little cleanup
|
||||||
* return.
|
* 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);
|
split = trans->splits->data;
|
||||||
/* Make a log in the journal before destruction. */
|
|
||||||
xaccTransWriteLog (trans, 'D');
|
/* Try to get the sorting order lined up according to
|
||||||
xaccRemoveEntity(&trans->guid);
|
* when the user typed things in. */
|
||||||
xaccFreeTransaction (trans);
|
if (0 == trans->date_entered.tv_sec) {
|
||||||
return;
|
struct timeval tv;
|
||||||
}
|
gettimeofday (&tv, NULL);
|
||||||
|
trans->date_entered.tv_sec = tv.tv_sec;
|
||||||
split = trans->splits->data;
|
trans->date_entered.tv_nsec = 1000 * tv.tv_usec;
|
||||||
|
}
|
||||||
/* try to get the sorting order lined up according to
|
|
||||||
* when the user typed things in. */
|
/* Alternately the transaction may have only one split in
|
||||||
if (0 == trans->date_entered.tv_sec) {
|
* it, in which case that's OK if and only if the split has no
|
||||||
struct timeval tv;
|
* value (i.e. is only recording a price). Otherwise, a single
|
||||||
gettimeofday (&tv, NULL);
|
* split with a value can't possibly balance, thus violating the
|
||||||
trans->date_entered.tv_sec = tv.tv_sec;
|
* rules of double-entry, and that's way bogus. So create
|
||||||
trans->date_entered.tv_nsec = 1000 * tv.tv_usec;
|
* a matching opposite and place it either here (if force==1),
|
||||||
}
|
* or in some dummy account (if force==2).
|
||||||
|
*/
|
||||||
/* Alternately the transaction may have only one split in
|
if ((1 == force_double_entry) &&
|
||||||
* it, in which case that's OK if and only if the split has no
|
(NULL == g_list_nth(trans->splits, 1)) &&
|
||||||
* value (i.e. is only recording a price). Otherwise, a single
|
(!gnc_numeric_zero_p(split->damount))) {
|
||||||
* split with a value can't possibly balance, thus violating the
|
Split * s = xaccMallocSplit();
|
||||||
* rules of double-entry, and that's way bogus. So create
|
xaccTransAppendSplit (trans, s);
|
||||||
* a matching opposite and place it either here (if force==1),
|
xaccAccountInsertSplit (split->acc, s);
|
||||||
* or in some dummy account (if force==2).
|
xaccSplitSetMemo (s, split->memo);
|
||||||
*/
|
xaccSplitSetAction (s, split->action);
|
||||||
if ((1 == force_double_entry) &&
|
xaccSplitSetShareAmount(s, gnc_numeric_neg(split->damount));
|
||||||
(NULL == g_list_nth(trans->splits, 1)) &&
|
xaccSplitSetValue(s, gnc_numeric_neg(split->value));
|
||||||
(!gnc_numeric_zero_p(split->damount))) {
|
}
|
||||||
Split * s = xaccMallocSplit();
|
|
||||||
xaccTransAppendSplit (trans, s);
|
|
||||||
xaccAccountInsertSplit (split->acc, s);
|
|
||||||
xaccSplitSetMemo (s, split->memo);
|
|
||||||
xaccSplitSetAction (s, split->action);
|
|
||||||
xaccSplitSetShareAmount(s, gnc_numeric_neg(split->damount));
|
|
||||||
xaccSplitSetValue(s, gnc_numeric_neg(split->value));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------- */
|
/* ------------------------------------------------- */
|
||||||
@ -1319,11 +1307,26 @@ xaccTransCommitEdit (Transaction *trans)
|
|||||||
* at this point, and let the user know that we failed.
|
* at this point, and let the user know that we failed.
|
||||||
*/
|
*/
|
||||||
/* XXX hack alert -- finish this */
|
/* 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 "
|
PERR("Backend asked engine to rollback, but we don't "
|
||||||
"handle this case yet. Return code=%d", rc);
|
"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
|
/* Make sure all associated splits are in proper order
|
||||||
* in their accounts. */
|
* in their accounts. */
|
||||||
|
@ -54,6 +54,13 @@
|
|||||||
#include "Transaction.h" /* for typedefs */
|
#include "Transaction.h" /* for typedefs */
|
||||||
#include "GNCId.h"
|
#include "GNCId.h"
|
||||||
|
|
||||||
|
/* bit-field flags for controlling transaction commits */
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
BEGIN_EDIT = 1 << 0,
|
||||||
|
BEING_DESTROYED = 1 << 1,
|
||||||
|
} TransFlags;
|
||||||
|
|
||||||
|
|
||||||
/** STRUCTS *********************************************************/
|
/** STRUCTS *********************************************************/
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user